Orxonox  0.0.5 Codename: Arcturus
mbool.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Fabian 'x3n' Landau
24  * Co-authors:
25  * ...
26  *
27  */
28 
35 #ifndef _mbool_H__
36 #define _mbool_H__
37 
38 #include "UtilPrereqs.h"
39 
40 namespace orxonox
41 {
58  struct mbool
59  {
60  public:
62  constexpr mbool(bool value = false) : value_{ static_cast<unsigned char>(value ? 1 : 0) }
63  {}
65  constexpr mbool(const mbool& value) : value_{ value.value_.memory_ }
66  {}
68  inline ~mbool() = default;
69 
71  inline mbool& operator=(bool value)
72  { if (value != this->value_.bool_) { ++this->value_.memory_; } return (*this); }
74  inline mbool& operator=(const mbool& value)
75  { this->value_.memory_ = value.value_.memory_; return (*this); }
76 
78  inline mbool& operator++()
79  { ++this->value_.memory_; return (*this); }
81  inline mbool operator++(int)
82  { mbool temp = (*this); ++this->value_.memory_; return temp; }
83 
85  constexpr operator bool() const
86  { return this->value_.bool_; }
87 
89  constexpr bool operator==(bool other) const
90  { return this->value_.bool_ == other; }
92  constexpr bool operator!=(bool other) const
93  { return this->value_.bool_ != other; }
94 
96  constexpr bool operator==(const mbool& other) const
97  { return this->value_.memory_ == other.value_.memory_; }
99  constexpr bool operator!=(const mbool& other) const
100  { return this->value_.memory_ != other.value_.memory_; }
101 
103  constexpr bool operator!() const
104  { return (!this->value_.bool_); }
105 
107  inline unsigned char& getMemory(){ return value_.memory_; }
108 
109  private:
110  union
111  {
112  unsigned char memory_;
113  bool bool_ : 1;
114  } value_;
115  };
116 }
117 
118 #endif /* _mbool_H__ */
constexpr bool operator!=(bool other) const
Compares the mbool to a bool, returns true if the bool has a different value than the state of the mb...
Definition: mbool.h:92
constexpr bool operator!=(const mbool &other) const
Compares two mbools, returns true if they have a different memory value.
Definition: mbool.h:99
~mbool()=default
Destructor does nothing but not defining it might create a symbol (class is header only) ...
mbool & operator=(bool value)
Assigns a boolean value (and increases the memory value if the value is different to the old value)...
Definition: mbool.h:71
mbool operator++(int)
Increases the memory which also inverts it&#39;s state (mbool++).
Definition: mbool.h:81
constexpr mbool(const mbool &value)
Copy-constructor, copies state and memory.
Definition: mbool.h:65
union orxonox::mbool::@37 value_
A union containing the state and the memory of the mbool.
mbool is a small helper class that acts like a bool, but keeps track of the number of its state chang...
Definition: mbool.h:58
mbool & operator++()
Increases the memory which also inverts it&#39;s state (++mbool).
Definition: mbool.h:78
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
constexpr bool operator==(bool other) const
Compares the mbool to a bool, returns true if the bool has the same value as the state of the mbool...
Definition: mbool.h:89
Shared library macros, enums, constants and forward declarations for the util library ...
unsigned char memory_
The memory of the mbool, counts the state-changes (and the first bit represents also the boolean valu...
Definition: mbool.h:112
mbool & operator=(const mbool &value)
Assigns another mbool, copies state and memory.
Definition: mbool.h:74
unsigned char & getMemory()
Returns the memory value.
Definition: mbool.h:107
constexpr mbool(bool value=false)
Constructor: Creates the mbool and initializes the boolean value (default to false).
Definition: mbool.h:62
constexpr bool operator!() const
Returns the inverted state of the bool (doesn&#39;t change the internal state).
Definition: mbool.h:103
bool bool_
The boolean state of the mbool, is located on the first bit of the memory variable.
Definition: mbool.h:113
constexpr bool operator==(const mbool &other) const
Compares two mbools, returns true if their memory matches.
Definition: mbool.h:96