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