PolyBoRi
BooleConstant.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00014 //*****************************************************************************
00015 
00016 #ifndef polybori_BooleConstant_h_
00017 #define polybori_BooleConstant_h_
00018 
00019 // include basic definitions
00020 #include <polybori/pbori_defs.h>
00021 
00022 BEGIN_NAMESPACE_PBORI
00023 
00040 class BooleConstant:
00041   public CTypes {
00042 
00043   typedef BooleConstant self;
00044 
00045 public:
00047   typedef const self* const_iterator;
00048 
00050   BooleConstant(): m_value(false) {}
00051 
00053   BooleConstant(bool value): m_value(value) {}
00054 
00056   BooleConstant(short value): m_value(value % 2) {}
00057 
00059   BooleConstant(unsigned short value): m_value(value % 2) {}
00060 
00062   BooleConstant(int value): m_value(value % 2) {}
00063 
00065   BooleConstant(unsigned int value): m_value(value % 2) {}
00066 
00068   BooleConstant(long value): m_value(value % 2) {}
00069 
00071   BooleConstant(unsigned long value): m_value(value % 2) {}
00072 
00074   operator bool() const { return m_value; }
00075 
00077   BooleConstant operator!() const { return !m_value; }
00078 
00080   deg_type deg() const { return (m_value? 0: -1); }
00081 
00083   const_iterator orderedBegin() const { return this; }
00084 
00086   const_iterator orderedEnd() const { return this + (m_value? 1: 0); }
00087 
00089   const_iterator variableBegin() const { return this; } 
00090 
00092   const_iterator variableEnd() const { return variableBegin(); }
00093 
00095 
00096   bool isOne() const { return m_value; }
00097   bool isZero() const { return !m_value; }
00098   bool isConstant() const { return true; }
00099   bool hasConstantPart() const { return isOne(); }
00101 
00102 protected:
00104   const bool m_value;
00105 };
00106 
00108 inline CTypes::ostream_type& 
00109 operator<<(CTypes::ostream_type& os, const BooleConstant& rhs) {
00110   return (os << (int) rhs);
00111 }
00112 
00113 inline BooleConstant
00114 operator+(const BooleConstant& lhs, const BooleConstant& rhs) {
00115   return lhs ^ rhs;
00116 }
00117 
00118 inline BooleConstant
00119 operator-(const BooleConstant& lhs, const BooleConstant& rhs) {
00120   return lhs + rhs;
00121 }
00122 
00123 inline BooleConstant
00124 operator*(const BooleConstant& lhs, const BooleConstant& rhs) {
00125   return lhs && rhs;
00126 }
00127 
00128 END_NAMESPACE_PBORI
00129 
00130 #endif // polybori_BooleConstant_h_