/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ /** @file * @brief Implementation of intuitive tristate logic * * (c) Copyright 2011 by Intra2net AG * Written by Erich Willems and Thomas Jarosch * * After we had serious trouble with the current boost::logic::tribool implementation * overloading the comparison operators, we rolled our own class. */ #ifndef __TRIBOOL_HPP #define __TRIBOOL_HPP #include namespace I2n { class Tribool { public: enum State { False, True, Undef }; Tribool(); Tribool(const State &v); Tribool(const Tribool& src); // set element Tribool& operator= (const State &v); Tribool& operator= (const Tribool& src); // Element comparison bool operator==(const Tribool& v) const; bool operator!=(const Tribool& v) const; // logic operators Tribool operator !() const; Tribool operator ||(const Tribool& x) const; Tribool operator &&(const Tribool& x) const; // Bistate logic to tristate conversion Tribool(const bool &v); Tribool& operator= (const bool &v); // comparision with bool (bi) bool is_exact(const bool &v) const; private: State Value; }; } namespace std { // allow Tribools to be easily printed to ostreams template inline std::basic_ostream& operator<<(std::basic_ostream& os, const I2n::Tribool& x) { if (x == I2n::Tribool::False) os << '0'; else if (x == I2n::Tribool::True) os << '1'; else os << '?'; return os; } } #endif