Changeset 11096
- Timestamp:
- Jan 25, 2016, 9:33:11 PM (9 years ago)
- Location:
- code/trunk/src/libraries/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/util/OrxEnum.h
r7401 r11096 61 61 { 62 62 public: 63 OrxEnum() { } 64 OrxEnum(int type) { type_ = type; } 65 OrxEnum(const T& instance) { type_ = instance.type_; } 63 constexpr OrxEnum() : type_() {} 64 constexpr OrxEnum(int type) : type_(type) {} 65 constexpr OrxEnum(const T& instance) : type_(instance.type_) {} 66 constexpr OrxEnum(const OrxEnum& instance) = delete; 66 67 67 operator int(){ return type_; }68 T& operator =(int type) { type_ = type; return *this; }69 bool operator <(const T& right) const { return (type_ < right.type_); }70 bool operator >(const T& right) const { return (type_ > right.type_); }68 constexpr operator int() const { return type_; } 69 T& operator =(int type) { type_ = type; return *this; } 70 constexpr bool operator <(const T& right) const { return (type_ < right.type_); } 71 constexpr bool operator >(const T& right) const { return (type_ > right.type_); } 71 72 72 73 private: 73 OrxEnum(const OrxEnum& instance);74 74 int type_; 75 75 }; … … 77 77 78 78 /// See orxonox::OrxEnum for more info 79 #define OrxEnumConstructors(enumName) \80 enumName() { } \81 enumName(int type) : OrxEnum<enumName>(type) { } \82 enumName(const enumName& inst) : OrxEnum<enumName>(inst) { } \79 #define OrxEnumConstructors(enumName) \ 80 constexpr enumName() { } \ 81 constexpr enumName(int type) : OrxEnum<enumName>(type) { } \ 82 constexpr enumName(const enumName& inst) : OrxEnum<enumName>(inst) { } \ 83 83 void dummyFunction() 84 84 -
code/trunk/src/libraries/util/mbool.h
r8400 r11096 60 60 public: 61 61 /// Constructor: Creates the mbool and initializes the boolean value (default to false). 62 inline mbool(bool value = false)63 { this->value_.memory_ = 0; this->value_.bool_ = value;}62 constexpr mbool(bool value = false) : value_{ static_cast<unsigned char>(value ? 1 : 0) } 63 {} 64 64 /// Copy-constructor, copies state and memory. 65 inline mbool(const mbool& value)66 { this->value_.memory_ = value.value_.memory_;}65 constexpr mbool(const mbool& value) : value_{ value.value_.memory_ } 66 {} 67 67 /// Destructor does nothing but not defining it might create a symbol (class is header only) 68 inline ~mbool() 69 { } 68 inline ~mbool() = default; 70 69 71 70 /// Assigns a boolean value (and increases the memory value if the value is different to the old value). … … 84 83 85 84 /// Implicitly converts the mbool to a bool. 86 inlineoperator bool() const85 constexpr operator bool() const 87 86 { return this->value_.bool_; } 88 87 89 88 /// Compares the mbool to a bool, returns true if the bool has the same value as the state of the mbool. 90 inlinebool operator==(bool other) const89 constexpr bool operator==(bool other) const 91 90 { return this->value_.bool_ == other; } 92 91 /// Compares the mbool to a bool, returns true if the bool has a different value than the state of the mbool. 93 inlinebool operator!=(bool other) const92 constexpr bool operator!=(bool other) const 94 93 { return this->value_.bool_ != other; } 95 94 96 95 /// Compares two mbools, returns true if their memory matches. 97 inlinebool operator==(const mbool& other) const96 constexpr bool operator==(const mbool& other) const 98 97 { return this->value_.memory_ == other.value_.memory_; } 99 98 /// Compares two mbools, returns true if they have a different memory value. 100 inlinebool operator!=(const mbool& other) const99 constexpr bool operator!=(const mbool& other) const 101 100 { return this->value_.memory_ != other.value_.memory_; } 102 101 103 102 /// Returns the inverted state of the bool (doesn't change the internal state). 104 inlinebool operator!() const103 constexpr bool operator!() const 105 104 { return (!this->value_.bool_); } 106 105 … … 111 110 union 112 111 { 112 unsigned char memory_; ///< The memory of the mbool, counts the state-changes (and the first bit represents also the boolean value) 113 113 bool bool_ : 1; ///< The boolean state of the mbool, is located on the first bit of the memory variable 114 unsigned char memory_; ///< The memory of the mbool, counts the state-changes (and the first bit represents also the boolean value)115 114 } value_; ///< A union containing the state and the memory of the mbool 116 115 }; -
code/trunk/src/libraries/util/tribool.h
r8729 r11096 10 10 // so that (dontcare == dontcare). 11 11 // Also removed all logic operators except for == and != 12 // Added C++11 constexpr 12 13 13 14 … … 22 23 * The type of the 'dontcare' keyword. 23 24 */ 24 struct dontcare_keyword_t { 25 struct dontcare_keyword_t {}; 25 26 26 27 /** 27 28 * \brief Keyword for the dontcare tribool value 28 29 */ 29 const dontcare_keyword_t dontcare = dontcare_keyword_t();30 constexpr dontcare_keyword_t dontcare = dontcare_keyword_t(); 30 31 31 32 /** … … 43 44 * \throws nothrow 44 45 */ 45 tribool() : value(false_value) {}46 constexpr tribool() : value(false_value) {} 46 47 47 48 /** … … 51 52 * \throws nothrow 52 53 */ 53 tribool(bool value) : value(value? true_value : false_value) {}54 constexpr tribool(bool value) : value(value? true_value : false_value) {} 54 55 55 56 /** … … 58 59 * \throws nothrow 59 60 */ 60 tribool(dontcare_keyword_t) : value(dontcare_value) {}61 constexpr tribool(dontcare_keyword_t) : value(dontcare_value) {} 61 62 62 63 /** … … 66 67 * \throws nothrow 67 68 */ 68 inline bool operator==(tribool y)69 constexpr bool operator==(tribool y) const 69 70 { 70 71 return (this->value == y.value); … … 74 75 * \overload 75 76 */ 76 inline bool operator==(bool y){ return (*this) == tribool(y); }77 constexpr bool operator==(bool y) const { return (*this) == tribool(y); } 77 78 78 79 /** 79 80 * \overload 80 81 */ 81 inline bool operator==(dontcare_keyword_t)82 constexpr bool operator==(dontcare_keyword_t) const 82 83 { return tribool(dontcare) == (*this); } 83 84 … … 88 89 * \throws nothrow 89 90 */ 90 inline bool operator!=(tribool y)91 constexpr bool operator!=(tribool y) const 91 92 { 92 93 return !((*this) == y); … … 96 97 * \overload 97 98 */ 98 inline bool operator!=(bool y){ return (*this) != tribool(y); }99 constexpr bool operator!=(bool y) const { return (*this) != tribool(y); } 99 100 100 101 /** 101 102 * \overload 102 103 */ 103 inline bool operator!=(dontcare_keyword_t)104 constexpr bool operator!=(dontcare_keyword_t) const 104 105 { return (*this) != tribool(dontcare); } 105 106 … … 114 115 * \overload 115 116 */ 116 inlinebool operator==(bool x, tribool y) { return tribool(x) == y; }117 constexpr bool operator==(bool x, tribool y) { return tribool(x) == y; } 117 118 118 119 /** 119 120 * \overload 120 121 */ 121 inlinebool operator==(dontcare_keyword_t, tribool x)122 constexpr bool operator==(dontcare_keyword_t, tribool x) 122 123 { return tribool(dontcare) == x; } 123 124 … … 125 126 * \overload 126 127 */ 127 inlinebool operator!=(bool x, tribool y) { return tribool(x) != y; }128 constexpr bool operator!=(bool x, tribool y) { return tribool(x) != y; } 128 129 129 130 /** 130 131 * \overload 131 132 */ 132 inlinebool operator!=(dontcare_keyword_t, tribool x)133 constexpr bool operator!=(dontcare_keyword_t, tribool x) 133 134 { return tribool(dontcare) != x; } 134 135
Note: See TracChangeset
for help on using the changeset viewer.