PolyBoRi
|
00001 // -*- c++ -*- 00002 //***************************************************************************** 00015 //***************************************************************************** 00016 00017 #ifndef polybori_diagram_CApplyNodeFacade_h 00018 #define polybori_diagram_CApplyNodeFacade_h 00019 00020 // include basic definitions 00021 #include <polybori/pbori_defs.h> 00022 #include <stdexcept> 00023 00024 00025 BEGIN_NAMESPACE_PBORI 00026 00040 template <class DiagramType, class NodePtr> 00041 class CApplyNodeFacade { 00042 00044 typedef CApplyNodeFacade self; 00045 public: 00046 00048 00049 typedef DiagramType diagram_type; 00050 typedef NodePtr node_ptr; 00052 00054 00055 00056 bool operator==(const diagram_type& rhs) const { 00057 return rhs.getNode() == *this; 00058 } 00059 00061 bool operator!=(const diagram_type& rhs) const { return !(*this == rhs); } 00063 00064 protected: 00066 void checkSameManager(const diagram_type& other) const { 00067 if PBORI_UNLIKELY(my().getManager() != other.getManager()) { 00068 throw std::runtime_error("Operands come from different manager."); 00069 } 00070 } 00071 00073 00074 00075 template <class MgrType> 00076 diagram_type apply(node_ptr (*func)(MgrType, node_ptr)) const { 00077 return diagram(func(get<MgrType>(), *this)); 00078 } 00079 00081 template <class MgrType> 00082 diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr), 00083 const diagram_type& rhs) const { 00084 checkSameManager(rhs); 00085 return diagram(func(get<MgrType>(), *this, rhs)); 00086 } 00087 00089 template <class MgrType> 00090 diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr, node_ptr), 00091 const diagram_type& first, const diagram_type& second) const { 00092 checkSameManager(first); 00093 checkSameManager(second); 00094 return diagram(func(get<MgrType>(), *this, first, second)); 00095 } 00096 00098 template <class MgrType, class Type> 00099 diagram_type apply(node_ptr(*func)(MgrType, node_ptr, Type), Type value) const { 00100 return diagram(func(get<MgrType>(), *this, value)); 00101 } 00102 00104 template <class MgrType, class ResultType> 00105 ResultType apply(ResultType(*func)(MgrType, node_ptr)) const { 00106 return func(get<MgrType>(), *this); 00107 } 00108 // @} 00109 00111 diagram_type diagram(node_ptr node) const { 00112 return diagram_type(my().ring(), node); 00113 } 00114 00115 private: 00117 const diagram_type& my() const { 00118 return static_cast<const diagram_type&>(*this); 00119 } 00120 00122 template<class MgrType> 00123 MgrType get() const { return my().getManager(); } 00124 00126 operator node_ptr() const { return my().getNode(); } 00127 }; 00128 00129 00130 END_NAMESPACE_PBORI 00131 00132 #endif 00133 00134