PolyBoRi
BooleConstant.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
14 //*****************************************************************************
15 
16 #ifndef polybori_BooleConstant_h_
17 #define polybori_BooleConstant_h_
18 
19 // include basic definitions
20 #include <polybori/pbori_defs.h>
21 
23 
41  public CTypes {
42 
43  typedef BooleConstant self;
44 
45 public:
47  typedef const self* const_iterator;
48 
50  BooleConstant(): m_value(false) {}
51 
53  BooleConstant(bool value): m_value(value) {}
54 
56  BooleConstant(short value): m_value(value % 2) {}
57 
59  BooleConstant(unsigned short value): m_value(value % 2) {}
60 
62  BooleConstant(int value): m_value(value % 2) {}
63 
65  BooleConstant(unsigned int value): m_value(value % 2) {}
66 
68  BooleConstant(long value): m_value(value % 2) {}
69 
71  BooleConstant(unsigned long value): m_value(value % 2) {}
72 
74  operator bool() const { return m_value; }
75 
77  BooleConstant operator!() const { return !m_value; }
78 
80  deg_type deg() const { return (m_value? 0: -1); }
81 
83  const_iterator orderedBegin() const { return this; }
84 
86  const_iterator orderedEnd() const { return this + (m_value? 1: 0); }
87 
89  const_iterator variableBegin() const { return this; }
90 
92  const_iterator variableEnd() const { return variableBegin(); }
93 
95 
96  bool isOne() const { return m_value; }
97  bool isZero() const { return !m_value; }
98  bool isConstant() const { return true; }
99  bool hasConstantPart() const { return isOne(); }
101 
102 protected:
104  const bool m_value;
105 };
106 
108 inline CTypes::ostream_type&
110  return (os << (int) rhs);
111 }
112 
113 inline BooleConstant
114 operator+(const BooleConstant& lhs, const BooleConstant& rhs) {
115  return lhs ^ rhs;
116 }
117 
118 inline BooleConstant
119 operator-(const BooleConstant& lhs, const BooleConstant& rhs) {
120  return lhs + rhs;
121 }
122 
123 inline BooleConstant
124 operator*(const BooleConstant& lhs, const BooleConstant& rhs) {
125  return lhs && rhs;
126 }
127 
129 
130 #endif // polybori_BooleConstant_h_