Embedded Template Library 1.0
Loading...
Searching...
No Matches
user_type.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) 2017 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_USER_TYPE_INCLUDED
32#define ETL_USER_TYPE_INCLUDED
33
34#include "platform.h"
35
74
75//*****************************************************************************
76// The declaration of the structure.
77//*****************************************************************************
78#define ETL_DECLARE_USER_TYPE(TypeName, ValueType) \
79 struct TypeName \
80 { \
81 /* Non-volatile definitions.*/ \
82 typedef ValueType value_type; \
83 TypeName() {} \
84 TypeName(const TypeName &other) : value(other.value) {} \
85 TypeName& operator=(const TypeName &other) { value = other.value; return *this; } \
86 explicit TypeName(ValueType value_) : value(value_) {} \
87 operator ValueType() const { return value; } \
88 ValueType& get() { return value; } \
89 const ValueType& get() const { return value; } \
90 TypeName& operator ++() { ++value; return *this; } \
91 TypeName operator ++(int) { TypeName temp(*this); TypeName::operator ++(); return temp; } \
92 TypeName& operator --() { --value; return *this; } \
93 TypeName operator --(int) { TypeName temp(*this); TypeName::operator --(); return temp; } \
94 TypeName& operator +=(const ValueType& rhs) { value += rhs; return *this; } \
95 TypeName& operator -=(const ValueType& rhs) { value -= rhs; return *this; } \
96 TypeName& operator *=(const ValueType& rhs) { value *= rhs; return *this; } \
97 TypeName& operator /=(const ValueType& rhs) { value /= rhs; return *this; } \
98 TypeName& operator %=(const ValueType& rhs) { value %= rhs; return *this; } \
99 TypeName& operator &=(const ValueType& rhs) { value &= rhs; return *this; } \
100 TypeName& operator |=(const ValueType& rhs) { value |= rhs; return *this; } \
101 TypeName& operator ^=(const ValueType& rhs) { value ^= rhs; return *this; } \
102 TypeName& operator <<=(ValueType distance) { value <<= distance; return *this; } \
103 TypeName& operator >>=(ValueType distance) { value >>= distance; return *this; } \
104 private: \
105 ValueType value; \
106 public: \
107 enum enum_type \
108 {
109
110//*****************************************************************************
111// The predefined constants.
112//*****************************************************************************
113#define ETL_USER_TYPE(enum_name, value) \
114 enum_name = value,
115
116//*****************************************************************************
117// The final section of the structure.
118//*****************************************************************************
119#define ETL_END_USER_TYPE(TypeName) \
120 }; \
121 TypeName(enum_type value_) : value(static_cast<value_type>(value_)) {} \
122 };
123
124
125#endif