Changeset 11096 for code/trunk/src/libraries/util/mbool.h
- Timestamp:
- Jan 25, 2016, 9:33:11 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 };
Note: See TracChangeset
for help on using the changeset viewer.