Embedded Template Library  1.0
type_def.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2016 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_TYPE_DEF_INCLUDED
32 #define ETL_TYPE_DEF_INCLUDED
33 
34 #include "platform.h"
35 
36 namespace etl
37 {
38  #define ETL_TYPEDEF(T, name) class name##_tag; typedef etl::type_def<name##_tag, T> name
39 
40  //*************************************************************************
51  //*************************************************************************
52  template <typename TIdType, typename TValue>
53  class type_def
54  {
55  public:
56 
57  typedef TValue value_type;
58  typedef TIdType id_type;
59 
60  //*********************************************************************
61  type_def()
62  : value(TValue())
63  {
64  }
65 
66  //*********************************************************************
67  type_def(TValue value_)
68  : value(value_)
69  {
70  }
71 
72  //*********************************************************************
73  type_def(const type_def& other)
74  : value(other.value)
75  {
76  }
77 
78  //*********************************************************************
79  operator TValue() const
80  {
81  return value;
82  }
83 
84  //*********************************************************************
85  type_def& operator ++()
86  {
87  ++value;
88  return *this;
89  }
90 
91  //*********************************************************************
92  type_def operator ++(int)
93  {
94  type_def temp(*this);
95  type_def::operator ++();
96  return temp;
97  }
98 
99  //*********************************************************************
100  type_def& operator --()
101  {
102  --value;
103  return *this;
104  }
105 
106  //*********************************************************************
107  type_def operator --(int)
108  {
109  type_def temp(*this);
110  type_def::operator --();
111  return temp;
112  }
113 
114  //*********************************************************************
115  type_def& operator +=(TValue rhs)
116  {
117  value += rhs;
118  return *this;
119  }
120 
121  //*********************************************************************
122  type_def& operator +=(const type_def& rhs)
123  {
124  value += rhs.value;
125  return *this;
126  }
127 
128  //*********************************************************************
129  type_def& operator -=(TValue rhs)
130  {
131  value -= rhs;
132  return *this;
133  }
134 
135  //*********************************************************************
136  type_def& operator -=(const type_def& rhs)
137  {
138  value -= rhs.value;
139  return *this;
140  }
141 
142  //*********************************************************************
143  type_def& operator *=(TValue rhs)
144  {
145  value *= rhs;
146  return *this;
147  }
148 
149  //*********************************************************************
150  type_def& operator *=(const type_def& rhs)
151  {
152  value *= rhs.value;
153  return *this;
154  }
155 
156  //*********************************************************************
157  type_def& operator /=(TValue rhs)
158  {
159  value /= rhs;
160  return *this;
161  }
162 
163  //*********************************************************************
164  type_def& operator /=(const type_def& rhs)
165  {
166  value /= rhs.value;
167  return *this;
168  }
169 
170  //*********************************************************************
171  type_def& operator %=(TValue rhs)
172  {
173  value %= rhs;
174  return *this;
175  }
176 
177  //*********************************************************************
178  type_def& operator %=(const type_def& rhs)
179  {
180  value %= rhs.value;
181  return *this;
182  }
183 
184  //*********************************************************************
185  type_def& operator &=(TValue rhs)
186  {
187  value &= rhs;
188  return *this;
189  }
190 
191  //*********************************************************************
192  type_def& operator &=(const type_def& rhs)
193  {
194  value &= rhs.value;
195  return *this;
196  }
197 
198  //*********************************************************************
199  type_def& operator |=(TValue rhs)
200  {
201  value |= rhs;
202  return *this;
203  }
204 
205  //*********************************************************************
206  type_def& operator |=(const type_def& rhs)
207  {
208  value |= rhs.value;
209  return *this;
210  }
211 
212  //*********************************************************************
213  type_def& operator ^=(TValue rhs)
214  {
215  value ^= rhs;
216  return *this;
217  }
218 
219  //*********************************************************************
220  type_def& operator ^=(const type_def& rhs)
221  {
222  value ^= rhs.value;
223  return *this;
224  }
225 
226  //*********************************************************************
227  type_def& operator <<=(TValue rhs)
228  {
229  value <<= rhs;
230  return *this;
231  }
232 
233  //*********************************************************************
234  type_def& operator >>=(TValue rhs)
235  {
236  value >>= rhs;
237  return *this;
238  }
239 
240  //*********************************************************************
241  type_def& operator =(TValue rhs)
242  {
243  value = rhs;
244  return *this;
245  }
246 
247  //*********************************************************************
248  type_def& operator =(const type_def& rhs)
249  {
250  value = rhs.value;
251  return *this;
252  }
253 
254  //*********************************************************************
255  TValue& get()
256  {
257  return value;
258  }
259 
260  //*********************************************************************
261  const TValue& get() const
262  {
263  return value;
264  }
265 
266  //*********************************************************************
267  friend bool operator <(const type_def& lhs, const type_def& rhs)
268  {
269  return lhs.value < rhs.value;
270  }
271 
272  //*********************************************************************
273  friend bool operator <=(const type_def& lhs, const type_def& rhs)
274  {
275  return lhs.value <= rhs.value;
276  }
277 
278  //*********************************************************************
279  friend bool operator >(const type_def& lhs, const type_def& rhs)
280  {
281  return lhs.value > rhs.value;
282  }
283 
284  //*********************************************************************
285  friend bool operator >=(const type_def& lhs, const type_def& rhs)
286  {
287  return lhs.value >= rhs.value;
288  }
289 
290  //*********************************************************************
291  friend bool operator ==(const type_def& lhs, const type_def& rhs)
292  {
293  return lhs.value == rhs.value;
294  }
295 
296  //*********************************************************************
297  friend bool operator !=(const type_def& lhs, const type_def& rhs)
298  {
299  return lhs.value != rhs.value;
300  }
301 
302  private:
303 
304  TValue value;
305  };
306 }
307 
308 #endif
Definition: type_def.h:54
Definition: absolute.h:37