Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/levelMichael/src/libraries/util/tribool.h @ 9928

Last change on this file since 9928 was 8729, checked in by rgrieder, 13 years ago

Merged unity_build branch back to trunk.

Features:

  • Implemented fully automatic build units to speed up compilation if requested
  • Added DOUT macro for quick debug output
  • Activated text colouring in the POSIX IOConsole
  • DeclareToluaInterface is not necessary anymore

Improvements:

  • Output levels now change appropriately when switch back and forth from dev mode
  • Log level for the file output is now also correct during startup
  • Removed some header file dependencies in core and tools to speed up compilation

no more file for command line options

  • Improved util::tribool by adapting some concepts from boost::tribool

Regressions:

  • It is not possible anymore to specify command line arguments in an extra file because we've got config values for that purpose.
  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
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
13
14// For more information, see http://www.boost.org
15#ifndef ORXONOX_TRIBOOL_H
16#define ORXONOX_TRIBOOL_H
17
18namespace orxonox {
19
20/**
21 * INTERNAL ONLY
22 * The type of the 'dontcare' keyword.
23 */
24struct dontcare_keyword_t { };
25
26/**
27 * \brief Keyword for the dontcare tribool value
28 */
29const dontcare_keyword_t dontcare = dontcare_keyword_t();
30
31/**
32 * \brief A 3-state boolean type.
33 *
34 * 3-state boolean values are either true, false, or
35 * dontcare.
36 */
37class tribool
38{
39public:
40  /**
41   * Construct a new 3-state boolean value with the value 'false'.
42   *
43   * \throws nothrow
44   */
45  tribool() : value(false_value) {}
46
47  /**
48   * Construct a new 3-state boolean value with the given boolean
49   * value, which may be \c true or \c false.
50   *
51   * \throws nothrow
52   */
53  tribool(bool value) : value(value? true_value : false_value) {}
54
55  /**
56   * Construct a new 3-state boolean value with an dontcare value.
57   *
58   * \throws nothrow
59   */
60  tribool(dontcare_keyword_t) : value(dontcare_value) {}
61
62  /**
63   * \brief Compare tribools for equality
64   *
65   * \returns the result of comparing two tribool values.
66   * \throws nothrow
67   */
68  inline bool operator==(tribool y)
69  {
70    return (this->value == y.value);
71  }
72
73  /**
74   * \overload
75   */
76  inline bool operator==(bool y) { return (*this) == tribool(y); }
77
78  /**
79   * \overload
80   */
81  inline bool operator==(dontcare_keyword_t)
82  { return tribool(dontcare) == (*this); }
83
84  /**
85   * \brief Compare tribools for inequality
86   *
87   * \returns the result of comparing two tribool values for inequality.
88   * \throws nothrow
89   */
90  inline bool operator!=(tribool y)
91  {
92    return !((*this) == y);
93  }
94
95  /**
96   * \overload
97   */
98  inline bool operator!=(bool y) { return (*this) != tribool(y); }
99
100  /**
101   * \overload
102   */
103  inline bool operator!=(dontcare_keyword_t)
104  { return (*this) != tribool(dontcare); }
105
106  /**
107   * The actual stored value in this 3-state boolean, which may be false, true,
108   * or dontcare.
109   */
110  enum value_t { false_value, true_value, dontcare_value } value;
111};
112
113/**
114 * \overload
115 */
116inline bool operator==(bool x, tribool y) { return tribool(x) == y; }
117
118/**
119 * \overload
120 */
121inline bool operator==(dontcare_keyword_t, tribool x)
122{ return tribool(dontcare) == x; }
123
124/**
125 * \overload
126 */
127inline bool operator!=(bool x, tribool y) { return tribool(x) != y; }
128
129/**
130 * \overload
131 */
132inline bool operator!=(dontcare_keyword_t, tribool x)
133{ return tribool(dontcare) != x; }
134
135} // end namespace orxonox
136
137#endif // ORXONOX_TRIBOOL_H
138
Note: See TracBrowser for help on using the repository browser.