Orxonox  0.0.5 Codename: Arcturus
tribool.h
Go to the documentation of this file.
1 // Three-state boolean logic library
2 
3 // Copyright Douglas Gregor 2002-2004. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
8 // Modifications by Orxonox to shape the third state into 'dontcare' instead
9 // of 'indeterminate'. The difference is that 'dontcare' is actually a value
10 // so that (dontcare == dontcare).
11 // Also removed all logic operators except for == and !=
12 // Added C++11 constexpr
13 
14 
15 // For more information, see http://www.boost.org
16 #ifndef ORXONOX_TRIBOOL_H
17 #define ORXONOX_TRIBOOL_H
18 
19 namespace orxonox {
20 
26 
31 
38 class tribool
39 {
40 public:
46  constexpr tribool() : value(false_value) {}
47 
54  constexpr tribool(bool value) : value(value? true_value : false_value) {}
55 
61  constexpr tribool(dontcare_keyword_t) : value(dontcare_value) {}
62 
69  constexpr bool operator==(tribool y) const
70  {
71  return (this->value == y.value);
72  }
73 
77  constexpr bool operator==(bool y) const { return (*this) == tribool(y); }
78 
82  constexpr bool operator==(dontcare_keyword_t) const
83  { return tribool(dontcare) == (*this); }
84 
91  constexpr bool operator!=(tribool y) const
92  {
93  return !((*this) == y);
94  }
95 
99  constexpr bool operator!=(bool y) const { return (*this) != tribool(y); }
100 
104  constexpr bool operator!=(dontcare_keyword_t) const
105  { return (*this) != tribool(dontcare); }
106 
111  enum value_t { false_value, true_value, dontcare_value } value;
112 };
113 
117 constexpr bool operator==(bool x, tribool y) { return tribool(x) == y; }
118 
123 { return tribool(dontcare) == x; }
124 
128 constexpr bool operator!=(bool x, tribool y) { return tribool(x) != y; }
129 
134 { return tribool(dontcare) != x; }
135 
136 } // end namespace orxonox
137 
138 #endif // ORXONOX_TRIBOOL_H
139 
constexpr bool operator!=(bool x, tribool y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:128
constexpr tribool(bool value)
Construct a new 3-state boolean value with the given boolean value, which may be true or false...
Definition: tribool.h:54
constexpr dontcare_keyword_t dontcare
Keyword for the dontcare tribool value.
Definition: tribool.h:30
constexpr bool operator==(bool y) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:77
constexpr bool operator!=(tribool y) const
Compare tribools for inequality.
Definition: tribool.h:91
constexpr bool operator==(dontcare_keyword_t) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:82
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
A 3-state boolean type.
Definition: tribool.h:38
enum orxonox::tribool::value_t value
constexpr bool operator==(bool x, tribool y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:117
INTERNAL ONLY The type of the 'dontcare' keyword.
Definition: tribool.h:25
value_t
The actual stored value in this 3-state boolean, which may be false, true, or dontcare.
Definition: tribool.h:111
constexpr bool operator!=(bool y) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:99
constexpr tribool()
Construct a new 3-state boolean value with the value 'false'.
Definition: tribool.h:46
constexpr tribool(dontcare_keyword_t)
Construct a new 3-state boolean value with an dontcare value.
Definition: tribool.h:61
constexpr bool operator==(tribool y) const
Compare tribools for equality.
Definition: tribool.h:69
constexpr bool operator!=(dontcare_keyword_t) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tribool.h:104