BooleConstant.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_BooleConstant_h_
#define polybori_BooleConstant_h_
// include basic definitions
#include <polybori/pbori_defs.h>
BEGIN_NAMESPACE_PBORI
class BooleConstant:
public CTypes {
typedef BooleConstant self;
public:
typedef const self* const_iterator;
BooleConstant(): m_value(false) {}
BooleConstant(bool value): m_value(value) {}
BooleConstant(short value): m_value(value % 2) {}
BooleConstant(unsigned short value): m_value(value % 2) {}
BooleConstant(int value): m_value(value % 2) {}
BooleConstant(unsigned int value): m_value(value % 2) {}
BooleConstant(long value): m_value(value % 2) {}
BooleConstant(unsigned long value): m_value(value % 2) {}
operator bool() const { return m_value; }
BooleConstant operator!() const { return !m_value; }
deg_type deg() const { return (m_value? 0: -1); }
const_iterator orderedBegin() const { return this; }
const_iterator orderedEnd() const { return this + (m_value? 1: 0); }
const_iterator variableBegin() const { return this; }
const_iterator variableEnd() const { return variableBegin(); }
bool isOne() const { return m_value; }
bool isZero() const { return !m_value; }
bool isConstant() const { return true; }
bool hasConstantPart() const { return isOne(); }
protected:
const bool m_value;
};
inline CTypes::ostream_type&
operator<<(CTypes::ostream_type& os, const BooleConstant& rhs) {
return (os << (int) rhs);
}
inline BooleConstant
operator+(const BooleConstant& lhs, const BooleConstant& rhs) {
return lhs ^ rhs;
}
inline BooleConstant
operator-(const BooleConstant& lhs, const BooleConstant& rhs) {
return lhs + rhs;
}
inline BooleConstant
operator*(const BooleConstant& lhs, const BooleConstant& rhs) {
return lhs && rhs;
}
END_NAMESPACE_PBORI
#endif // polybori_BooleConstant_h_