File: xbool.hpp

package info (click to toggle)
netgen 6.2.2601%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,076 kB
  • sloc: cpp: 166,627; tcl: 6,310; python: 2,868; sh: 528; makefile: 90
file content (47 lines) | stat: -rw-r--r-- 1,399 bytes parent folder | download | duplicates (4)
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
#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; }
    bool IsMaybeTrue() const { return state >= 1; } 
    bool IsMaybeFalse() const { return state <= 1; } 
    friend ostream & operator<< (ostream & ost, xbool xb);
  };


  static char output[] = "0?1";
  inline ostream & operator<< (ostream & ost, xbool xb)
  {
    return ost << output[xb.state];
  }
  
} // namespace ngcore

#endif // NETGEN_CORE_XBOOL_HPP