/usr/include/opengm/utilities/tribool.hxx is in libopengm-dev 2.3.6+20160905-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | #pragma once
#ifndef OPENGM_TRIBOOL_HXX
#define OPENGM_TRIBOOL_HXX
namespace opengm {
/// Variable with three values (true=1, false=0, maybe=-1 )
class Tribool
{
public:
enum State {True=1, False=0, Maybe=-1};
Tribool();
Tribool(const Tribool&);
template<class T>
Tribool(const T);
Tribool(Tribool::State state);
Tribool& operator=(const Tribool&);
template<class T>
Tribool& operator=(T);
Tribool& operator=(Tribool::State state);
bool operator==(const bool a) const;
template<class T>
bool operator==(T a) const;
bool operator!=(const bool a) const;
operator bool() const;
bool operator!() const;
bool maybe() const;
void operator&=(Tribool::State state);
private:
int value_;
friend std::ostream& operator<<(std::ostream& out, const Tribool& t );
};
inline Tribool::Tribool()
: value_(Tribool::Maybe)
{}
inline Tribool::Tribool
(
const Tribool& val
)
: value_(val.value_)
{}
inline Tribool::Tribool
(
Tribool::State state
)
: value_(state)
{}
template<class T>
inline Tribool::Tribool
(
const T val
)
: value_(static_cast<int>(val) == Tribool::Maybe
? Tribool::Maybe
: static_cast<int>(static_cast<bool>(val)))
{}
inline Tribool&
Tribool::operator=
(
const Tribool& rhs
)
{
if(this != &rhs) {
value_ = rhs.value_;
}
return *this;
}
template<class T>
inline Tribool&
Tribool::operator=
(
const T val
)
{
static_cast<int>(val) == Tribool::Maybe
? value_ = Tribool::Maybe
: value_ = static_cast<int>(static_cast<bool>(val));
return *this;
}
inline Tribool&
Tribool::operator=
(
Tribool::State val
)
{
value_ = static_cast<int>(val);
return *this;
}
inline bool
Tribool::operator==
(
const bool a
) const
{
return bool( (value_ == Tribool::True && a == true)
|| (value_ == Tribool::False && a == false));
}
template<class T>
inline bool
Tribool::operator==
(
T a
) const
{
return static_cast<int>(a) == value_;
}
inline bool
Tribool::operator!=
(
const bool a
) const
{
return (value_ != Tribool::True && a == true)
|| (value_ != Tribool::True && a == false);
}
inline Tribool::operator bool() const
{
return value_ == Tribool::True;
}
inline bool
Tribool::operator!() const
{
return value_ == Tribool::False;
}
inline bool
Tribool::maybe() const
{
return value_ == Tribool::Maybe;
}
inline std::ostream&
operator<<
(
std::ostream& out,
const Tribool& t
)
{
out << static_cast<int>(t.value_);
return out;
}
inline void
Tribool::operator&=(Tribool::State state)
{
if(state==Tribool::True && value_!=Tribool::False) value_=Tribool::True;
if(state==Tribool::False) value_=Tribool::False;
}
} // namespace opengm
#endif // #ifndef OPENGM_TRIBOOL_HXX
|