2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 * @brief Implementation of intuitive tristate logic
23 * (c) Copyright 2011 by Intra2net AG
24 * Written by Erich Willems and Thomas Jarosch
27 #include <tribool.hpp>
34 * Default to Undef state
45 * @param v Initial state
47 Tribool::Tribool(const State &v)
53 * @brief Copy constructor
55 * @param src Class to copy the value from
57 Tribool::Tribool(const Tribool &src)
63 * @brief Assignment operator
66 * @return :Tribool& Pointer to this class
68 Tribool& Tribool::operator= (const State &v)
75 * @brief Assignment operator
77 * @param src Class to copy the state from
78 * @return :Tribool& Pointer to this class
80 Tribool& Tribool::operator= (const Tribool& src)
87 * @brief Element comparator
89 * @param x Class to compare against
90 * @return bool True if the are in 100% the same state, false otherwise
91 * Will return true if both elements are "Undef".
93 bool Tribool::operator==(const Tribool& x) const
95 return Value==x.Value;
99 * @brief Element comparator, NOT version
101 * @param x Class to compare against
102 * @return bool True if they are not in the same state, false otherwise
104 bool Tribool::operator!=(const Tribool& x) const
106 return Value!=x.Value;
110 * @brief Logical NOT operator - operating in tristate space
112 * @return :Tribool Tribool state as the result
114 Tribool Tribool::operator !() const
128 * @brief Logical OR - operating in tristate space
130 * @param x Object to compare against
131 * @return :Tribool Tribool state as result
133 Tribool Tribool::operator ||(const Tribool& x) const //lint !e1753
135 if ((True==Value) || (True==x.Value))
138 if ((False==Value) && (False==x.Value))
145 * @brief Logical AND operator - operating in tristate space
147 * @param x Object to compare against
148 * @return :Tribool Tristate state as result
150 Tribool Tribool::operator &&(const Tribool& x) const //lint !e1753
152 if ((True==Value) && (True==x.Value))
155 if ((False==Value) || (False==x.Value))
162 * @brief Constructor with bool conversion
164 * @param v Initial value in bistate space: true or false
166 Tribool::Tribool(const bool &v)
175 * @brief Assignment operator
177 * @param v Value in bistate space: true or false
178 * @return :Tribool& Pointer to this class
180 Tribool& Tribool::operator=(const bool &v)
191 * @brief Element comparision for easier access in bistate space
195 * @param v Boolean value to compare against
196 * @return bool True if it's exact the bool value, false otherwise.
197 * Undef state will return false.
199 bool Tribool::is_exact(const bool &v) const
204 if (v == true && Value == True)
206 else if(v == false && Value == False)