Embedded Template Library 1.0
Loading...
Searching...
No Matches
user_type.h File Reference
#include "platform.h"

Go to the source code of this file.

Macros

#define ETL_DECLARE_USER_TYPE(TypeName, ValueType)
#define ETL_USER_TYPE(enum_name, value)
#define ETL_END_USER_TYPE(TypeName)

Macro Definition Documentation

◆ ETL_DECLARE_USER_TYPE

#define ETL_DECLARE_USER_TYPE ( TypeName,
ValueType )
Value:
struct TypeName \
{ \
/* Non-volatile definitions.*/ \
typedef ValueType value_type; \
TypeName() {} \
TypeName(const TypeName &other) : value(other.value) {} \
TypeName& operator=(const TypeName &other) { value = other.value; return *this; } \
explicit TypeName(ValueType value_) : value(value_) {} \
operator ValueType() const { return value; } \
ValueType& get() { return value; } \
const ValueType& get() const { return value; } \
TypeName& operator ++() { ++value; return *this; } \
TypeName operator ++(int) { TypeName temp(*this); TypeName::operator ++(); return temp; } \
TypeName& operator --() { --value; return *this; } \
TypeName operator --(int) { TypeName temp(*this); TypeName::operator --(); return temp; } \
TypeName& operator +=(const ValueType& rhs) { value += rhs; return *this; } \
TypeName& operator -=(const ValueType& rhs) { value -= rhs; return *this; } \
TypeName& operator *=(const ValueType& rhs) { value *= rhs; return *this; } \
TypeName& operator /=(const ValueType& rhs) { value /= rhs; return *this; } \
TypeName& operator %=(const ValueType& rhs) { value %= rhs; return *this; } \
TypeName& operator &=(const ValueType& rhs) { value &= rhs; return *this; } \
TypeName& operator |=(const ValueType& rhs) { value |= rhs; return *this; } \
TypeName& operator ^=(const ValueType& rhs) { value ^= rhs; return *this; } \
TypeName& operator <<=(ValueType distance) { value <<= distance; return *this; } \
TypeName& operator >>=(ValueType distance) { value >>= distance; return *this; } \
private: \
ValueType value; \
public: \
enum enum_type \
{
T & get(array< T, Size > &a)
Definition array.h:1216
ETL_DECLARE_USER_TYPE(CompassDirection, int)
ETL_USER_TYPE(North, 0)
ETL_USER_TYPE(South, 180)
ETL_USER_TYPE(East, 90)
ETL_USER_TYPE(West, 270)
ETL_END_USER_TYPE(CompassDirection)
#define ETL_DECLARE_USER_TYPE(TypeName, ValueType)
Definition user_type.h:78

Using the enumeration.

CompassDirection direction; // Default construction.
direction = CompassDirection::North; // Assignment from an enumeration constant;
int value = int(direction); // Explicit conversion to 'int'.
int value = direction.get();
int& value = direction.get(); // Bind to internal value.
const int& value = direction.get();
direction = CompassDirection(value); // Explicit conversion from 'int'.
direction = CompassDirection(3); // Explicit conversion from a value.
++direction; // Manipulate the value;
direction -= CompassDirection(20);
direction = value; // Implicit conversion from 'int'. **** Compilation error ****

◆ ETL_END_USER_TYPE

#define ETL_END_USER_TYPE ( TypeName)
Value:
}; \
TypeName(enum_type value_) : value(static_cast<value_type>(value_)) {} \
};

◆ ETL_USER_TYPE

#define ETL_USER_TYPE ( enum_name,
value )
Value:
enum_name = value,