PolyBoRi
CApplyNodeFacade.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
15 //*****************************************************************************
16 
17 #ifndef polybori_diagram_CApplyNodeFacade_h
18 #define polybori_diagram_CApplyNodeFacade_h
19 
20 // include basic definitions
21 #include <polybori/pbori_defs.h>
22 #include <stdexcept>
23 
24 
26 
40 template <class DiagramType, class NodePtr>
42 
44  typedef CApplyNodeFacade self;
45 public:
46 
48 
49  typedef DiagramType diagram_type;
50  typedef NodePtr node_ptr;
52 
54 
55 
56  bool operator==(const diagram_type& rhs) const {
57  return rhs.getNode() == *this;
58  }
59 
61  bool operator!=(const diagram_type& rhs) const { return !(*this == rhs); }
63 
64 protected:
66  void checkSameManager(const diagram_type& other) const {
67  if PBORI_UNLIKELY(my().getManager() != other.getManager()) {
68  throw std::runtime_error("Operands come from different manager.");
69  }
70  }
71 
73 
74 
75  template <class MgrType>
76  diagram_type apply(node_ptr (*func)(MgrType, node_ptr)) const {
77  return diagram(func(get<MgrType>(), *this));
78  }
79 
81  template <class MgrType>
82  diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr),
83  const diagram_type& rhs) const {
84  checkSameManager(rhs);
85  return diagram(func(get<MgrType>(), *this, rhs));
86  }
87 
89  template <class MgrType>
90  diagram_type apply(node_ptr (*func)(MgrType, node_ptr, node_ptr, node_ptr),
91  const diagram_type& first, const diagram_type& second) const {
92  checkSameManager(first);
93  checkSameManager(second);
94  return diagram(func(get<MgrType>(), *this, first, second));
95  }
96 
98  template <class MgrType, class Type>
99  diagram_type apply(node_ptr(*func)(MgrType, node_ptr, Type), Type value) const {
100  return diagram(func(get<MgrType>(), *this, value));
101  }
102 
104  template <class MgrType, class ResultType>
105  ResultType apply(ResultType(*func)(MgrType, node_ptr)) const {
106  return func(get<MgrType>(), *this);
107  }
108  // @}
109 
112  return diagram_type(my().ring(), node);
113  }
114 
115 private:
117  const diagram_type& my() const {
118  return static_cast<const diagram_type&>(*this);
119  }
120 
122  template<class MgrType>
123  MgrType get() const { return my().getManager(); }
124 
126  operator node_ptr() const { return my().getNode(); }
127 };
128 
129 
131 
132 #endif
133 
134