Own implementation of intuitive tristate logic
[libi2ncommon] / src / tribool.hpp
1 /** @file
2  * @brief Implementation of intuitive tristate logic
3  *
4  * (c) Copyright 2011 by Intra2net AG
5  * Written by Erich Willems and Thomas Jarosch
6  * 
7  * After we had serious trouble with the current boost::logic::tribool implementation
8  * overloading the comparison operators, we rolled our own class.
9  *
10  * info@intra2net.com
11  */
12
13 namespace I2n
14 {
15
16 class Tribool
17 {
18 public:
19     enum State { False, True, Undef };
20
21     Tribool();
22     Tribool(const State &v);
23     Tribool(const Tribool& src);
24
25     // set element
26     Tribool&        operator= (const State &v);
27     Tribool&        operator= (const Tribool& src);
28
29     // Element comparison
30     bool operator==(const Tribool& v) const;
31     bool operator!=(const Tribool& v) const;
32
33     // logic operators
34     Tribool operator !() const;
35     Tribool operator ||(const Tribool& x) const;
36     Tribool operator &&(const Tribool& x) const;
37
38     // Bistate logic to tristate conversion
39     Tribool(const bool &v);
40     Tribool&        operator= (const bool &v);
41
42     // comparision with bool (bi)
43     bool    is_exact(const bool &v) const;
44
45 private:
46     State Value;
47 };
48
49 }