netgen/libsrc/core/xbool.hpp

46 lines
1.3 KiB
C++
Raw Normal View History

2019-08-06 17:16:13 +05:00
#ifndef NETGEN_CORE_XBOOL_HPP
#define NETGEN_CORE_XBOOL_HPP
/**************************************************************************/
/* File: xbool.hpp */
/* Author: Joachim Schoeberl */
/* Date: 14. Nov. 07 */
/**************************************************************************/
namespace ngcore
{
// an extended bool with values false/maybe/true
enum TMAYBE { maybe };
class xbool
{
uint8_t state;
public:
xbool (bool b) : state(b ? 2 : 0) { ; }
xbool (TMAYBE x) : state(1) { ; }
xbool () = default;
xbool (const xbool &) = default;
xbool & operator= (bool b) { state = b ? 2 : 0; return *this; }
xbool & operator= (TMAYBE x) { state = 1; return *this; }
bool IsTrue () const { return state == 2; }
bool IsMaybe () const { return state == 1; }
bool IsFalse () const { return state == 0; }
2020-05-22 11:15:40 +05:00
friend ostream & operator<< (ostream & ost, xbool xb);
2019-08-06 17:16:13 +05:00
};
2020-05-22 11:15:40 +05:00
static char output[] = "0?1";
inline ostream & operator<< (ostream & ost, xbool xb)
{
return ost << output[xb.state];
}
2019-08-06 17:16:13 +05:00
} // namespace ngcore
#endif // NETGEN_CORE_XBOOL_HPP