replace obsolete call to ftime(3)
[libi2ncommon] / src / tribool.hpp
CommitLineData
0e23f538
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
49f91b40
TJ
20/** @file
21 * @brief Implementation of intuitive tristate logic
22 *
23 * (c) Copyright 2011 by Intra2net AG
24 * Written by Erich Willems and Thomas Jarosch
25 *
26 * After we had serious trouble with the current boost::logic::tribool implementation
27 * overloading the comparison operators, we rolled our own class.
49f91b40
TJ
28 */
29
0f9cf43c
GE
30#ifndef __TRIBOOL_HPP
31#define __TRIBOOL_HPP
32
33#include <iostream>
34
49f91b40
TJ
35namespace I2n
36{
37
38class Tribool
39{
40public:
41 enum State { False, True, Undef };
42
43 Tribool();
44 Tribool(const State &v);
45 Tribool(const Tribool& src);
46
47 // set element
48 Tribool& operator= (const State &v);
49 Tribool& operator= (const Tribool& src);
50
51 // Element comparison
52 bool operator==(const Tribool& v) const;
53 bool operator!=(const Tribool& v) const;
54
55 // logic operators
56 Tribool operator !() const;
57 Tribool operator ||(const Tribool& x) const;
58 Tribool operator &&(const Tribool& x) const;
59
60 // Bistate logic to tristate conversion
61 Tribool(const bool &v);
62 Tribool& operator= (const bool &v);
63
64 // comparision with bool (bi)
65 bool is_exact(const bool &v) const;
66
67private:
68 State Value;
69};
70
71}
0f9cf43c
GE
72
73namespace std
74{
75
76// allow Tribools to be easily printed to ostreams
77template <class charT, class traits>
78inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
79 const I2n::Tribool& x)
80{
81 if (x == I2n::Tribool::False)
82 os << '0';
83 else if (x == I2n::Tribool::True)
84 os << '1';
85 else
86 os << '?';
87
88 return os;
89}
90
91}
92
93#endif