OpenTTD Source  20240917-master-g9ab0a47812
enum_type.hpp File Reference

Go to the source code of this file.

Macros

#define DECLARE_POSTFIX_INCREMENT(enum_type)
 Some enums need to have allowed incrementing (i.e. More...
 
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
 Operators to allow to work with enum as with type safe bit set in C++. More...
 
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
 Operator that allows this enumeration to be added to any other enumeration. More...
 

Detailed Description

Type (helpers) for enums

Definition in file enum_type.hpp.

Macro Definition Documentation

◆ DECLARE_ENUM_AS_ADDABLE

#define DECLARE_ENUM_AS_ADDABLE (   EnumType)
Value:
template <typename OtherEnumType, typename = typename std::enable_if<std::is_enum_v<OtherEnumType>, OtherEnumType>::type> \
constexpr OtherEnumType operator + (OtherEnumType m1, EnumType m2) { \
return static_cast<OtherEnumType>(static_cast<typename std::underlying_type<OtherEnumType>::type>(m1) + static_cast<typename std::underlying_type<EnumType>::type>(m2)); \
}

Operator that allows this enumeration to be added to any other enumeration.

Definition at line 41 of file enum_type.hpp.

◆ DECLARE_ENUM_AS_BIT_SET

#define DECLARE_ENUM_AS_BIT_SET (   enum_type)
Value:
inline constexpr enum_type operator | (enum_type m1, enum_type m2) {return (enum_type)((std::underlying_type<enum_type>::type)m1 | (std::underlying_type<enum_type>::type)m2);} \
inline constexpr enum_type operator & (enum_type m1, enum_type m2) {return (enum_type)((std::underlying_type<enum_type>::type)m1 & (std::underlying_type<enum_type>::type)m2);} \
inline constexpr enum_type operator ^ (enum_type m1, enum_type m2) {return (enum_type)((std::underlying_type<enum_type>::type)m1 ^ (std::underlying_type<enum_type>::type)m2);} \
inline constexpr enum_type& operator |= (enum_type& m1, enum_type m2) {m1 = m1 | m2; return m1;} \
inline constexpr enum_type& operator &= (enum_type& m1, enum_type m2) {m1 = m1 & m2; return m1;} \
inline constexpr enum_type& operator ^= (enum_type& m1, enum_type m2) {m1 = m1 ^ m2; return m1;} \
inline constexpr enum_type operator ~(enum_type m) {return (enum_type)(~(std::underlying_type<enum_type>::type)m);}

Operators to allow to work with enum as with type safe bit set in C++.

Definition at line 31 of file enum_type.hpp.

◆ DECLARE_POSTFIX_INCREMENT

#define DECLARE_POSTFIX_INCREMENT (   enum_type)
Value:
inline constexpr enum_type operator ++(enum_type& e, int) \
{ \
enum_type e_org = e; \
e = (enum_type)((std::underlying_type<enum_type>::type)e + 1); \
return e_org; \
} \
inline constexpr enum_type operator --(enum_type& e, int) \
{ \
enum_type e_org = e; \
e = (enum_type)((std::underlying_type<enum_type>::type)e - 1); \
return e_org; \
}

Some enums need to have allowed incrementing (i.e.

StationClassID)

Definition at line 14 of file enum_type.hpp.