Embedded Template Library
1.0
Loading...
Searching...
No Matches
user_type.h
Go to the documentation of this file.
1
2
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) 2017 John Wellbelove
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_USER_TYPE_INCLUDED
32
#define ETL_USER_TYPE_INCLUDED
33
34
#include "
platform.h
"
35
76
77
//*****************************************************************************
78
// The declaration of the structure.
79
//*****************************************************************************
80
#define ETL_DECLARE_USER_TYPE(TypeName, ValueType) \
81
struct TypeName \
82
{ \
83
/* Non-volatile definitions.*/
\
84
typedef ValueType value_type; \
85
TypeName() {} \
86
TypeName(const TypeName& other) \
87
: value(other.value) \
88
{ \
89
} \
90
TypeName& operator=(const TypeName& other) \
91
{ \
92
value = other.value; \
93
return *this; \
94
} \
95
explicit TypeName(ValueType value_) \
96
: value(value_) \
97
{ \
98
} \
99
operator ValueType() const \
100
{ \
101
return value; \
102
} \
103
ValueType& get() \
104
{ \
105
return value; \
106
} \
107
const ValueType& get() const \
108
{ \
109
return value; \
110
} \
111
TypeName& operator++() \
112
{ \
113
++value; \
114
return *this; \
115
} \
116
TypeName operator++(int) \
117
{ \
118
TypeName temp(*this); \
119
TypeName::operator++(); \
120
return temp; \
121
} \
122
TypeName& operator--() \
123
{ \
124
--value; \
125
return *this; \
126
} \
127
TypeName operator--(int) \
128
{ \
129
TypeName temp(*this); \
130
TypeName::operator--(); \
131
return temp; \
132
} \
133
TypeName& operator+=(const ValueType& rhs) \
134
{ \
135
value += rhs; \
136
return *this; \
137
} \
138
TypeName& operator-=(const ValueType& rhs) \
139
{ \
140
value -= rhs; \
141
return *this; \
142
} \
143
TypeName& operator*=(const ValueType& rhs) \
144
{ \
145
value *= rhs; \
146
return *this; \
147
} \
148
TypeName& operator/=(const ValueType& rhs) \
149
{ \
150
value /= rhs; \
151
return *this; \
152
} \
153
TypeName& operator%=(const ValueType& rhs) \
154
{ \
155
value %= rhs; \
156
return *this; \
157
} \
158
TypeName& operator&=(const ValueType& rhs) \
159
{ \
160
value &= rhs; \
161
return *this; \
162
} \
163
TypeName& operator|=(const ValueType& rhs) \
164
{ \
165
value |= rhs; \
166
return *this; \
167
} \
168
TypeName& operator^=(const ValueType& rhs) \
169
{ \
170
value ^= rhs; \
171
return *this; \
172
} \
173
TypeName& operator<<=(ValueType distance) \
174
{ \
175
value <<= distance; \
176
return *this; \
177
} \
178
TypeName& operator>>=(ValueType distance) \
179
{ \
180
value >>= distance; \
181
return *this; \
182
} \
183
\
184
private: \
185
\
186
ValueType value; \
187
\
188
public: \
189
\
190
enum enum_type \
191
{
192
//*****************************************************************************
193
// The predefined constants.
194
//*****************************************************************************
195
#define ETL_USER_TYPE(enum_name, value) enum_name = value,
196
197
//*****************************************************************************
198
// The final section of the structure.
199
//*****************************************************************************
200
#define ETL_END_USER_TYPE(TypeName) \
201
} \
202
; \
203
TypeName(enum_type value_) \
204
: value(static_cast<value_type>(value_)) \
205
{ \
206
} \
207
} \
208
;
209
210
#endif
platform.h
include
etl
user_type.h
Generated on
for Embedded Template Library by
1.15.0