CApplyNodeFacade.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_diagram_CApplyNodeFacade_h
#define polybori_diagram_CApplyNodeFacade_h
// include basic definitions
#include <polybori/pbori_defs.h>
#include <stdexcept>
BEGIN_NAMESPACE_PBORI
template <class DiagramType, class NodePtr>
class CApplyNodeFacade {
typedef CApplyNodeFacade self;
public:
typedef DiagramType diagram_type;
typedef NodePtr node_ptr;
bool operator==(const diagram_type& rhs) const {
return rhs.getNode() == *this;
}
bool operator!=(const diagram_type& rhs) const { return !(*this == rhs); }
protected:
void checkSameManager(const diagram_type& other) const {
if PBORI_UNLIKELY(my().getManager() != other.getManager()) {
throw std::runtime_error("Operands come from different manager.");
}
}
template <class MgrType>
diagram_type apply(node_ptr (*func)(MgrType, node_ptr)) const {
return diagram(func(get<MgrType>(), *this));
}
template <class MgrType>
diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr),
const diagram_type& rhs) const {
checkSameManager(rhs);
return diagram(func(get<MgrType>(), *this, rhs));
}
template <class MgrType>
diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr, node_ptr),
const diagram_type& first, const diagram_type& second) const {
checkSameManager(first);
checkSameManager(second);
return diagram(func(get<MgrType>(), *this, first, second));
}
template <class MgrType, class Type>
diagram_type apply(node_ptr(*func)(MgrType, node_ptr, Type), Type value) const {
return diagram(func(get<MgrType>(), *this, value));
}
template <class MgrType, class ResultType>
ResultType apply(ResultType(*func)(MgrType, node_ptr)) const {
return func(get<MgrType>(), *this);
}
// @}
diagram_type diagram(node_ptr node) const {
return diagram_type(my().ring(), node);
}
private:
const diagram_type& my() const {
return static_cast<const diagram_type&>(*this);
}
template<class MgrType>
MgrType get() const { return my().getManager(); }
operator node_ptr() const { return my().getNode(); }
};
END_NAMESPACE_PBORI
#endif
polybori::CApplyNodeFacade::checkSameManager
void checkSameManager(const diagram_type &other) const
Test, whether both operands.
Definition: CApplyNodeFacade.h:66
END_NAMESPACE_PBORI
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
polybori::CApplyNodeFacade::apply
diagram_type apply(node_ptr(*func)(MgrType, node_ptr)) const
Unary function.
Definition: CApplyNodeFacade.h:76
BEGIN_NAMESPACE_PBORI
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
polybori::CApplyNodeFacade::diagram_type
DiagramType diagram_type
Definition: CApplyNodeFacade.h:49
polybori::CApplyNodeFacade
This template class defines a facade as a C++ interface for applying C-style functions to C-style str...
Definition: CApplyNodeFacade.h:41
polybori::CApplyNodeFacade::operator!=
bool operator!=(const diagram_type &rhs) const
Nonequality.
Definition: CApplyNodeFacade.h:61
polybori::operator==
BoolePolynomial::bool_type operator==(BoolePolynomial::bool_type lhs, const BoolePolynomial &rhs)
Equality check (with constant lhs)
Definition: BoolePolynomial.h:579
pbori_defs.h
polybori::CApplyNodeFacade::diagram
diagram_type diagram(node_ptr node) const
Get diagram of the same context.
Definition: CApplyNodeFacade.h:111
polybori::CCuddDDFacade::getManager
mgr_type * getManager() const
Get raw decision diagram manager.
Definition: CCuddDDFacade.h:256
polybori::CApplyNodeFacade::apply
diagram_type apply(node_ptr(*func)(MgrType, node_ptr, Type), Type value) const
Binary functions with non-diagram right-hand side.
Definition: CApplyNodeFacade.h:99
polybori::CApplyNodeFacade::apply
diagram_type apply(node_ptr(*func)(MgrType, node_ptr, node_ptr), const diagram_type &rhs) const
Binary function (two diagrams)
Definition: CApplyNodeFacade.h:82
polybori::CApplyNodeFacade::apply
diagram_type apply(node_ptr(*func)(MgrType, node_ptr, node_ptr, node_ptr), const diagram_type &first, const diagram_type &second) const
Ternary function (three diagrams)
Definition: CApplyNodeFacade.h:90
polybori::CApplyNodeFacade::apply
ResultType apply(ResultType(*func)(MgrType, node_ptr)) const
Unary functions with non-diagram result value.
Definition: CApplyNodeFacade.h:105
PBORI_UNLIKELY
#define PBORI_UNLIKELY(expression)
Definition: pbori_defs.h:59
polybori::CCuddDDFacade::getNode
node_ptr getNode() const
Get raw node structure.
Definition: CCuddDDFacade.h:253
polybori::CApplyNodeFacade::node_ptr
NodePtr node_ptr
Definition: CApplyNodeFacade.h:50