aGrUM  0.16.0
ExactTerminalNodePolicy.h
Go to the documentation of this file.
1 
30 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_EXACT_TERMINAL_NODE_POLICY_H
31 #define GUM_MULTI_DIM_FUNCTION_GRAPH_EXACT_TERMINAL_NODE_POLICY_H
32 
33 #include <agrum/core/bijection.h>
36 
37 namespace gum {
38 
39  // clang-format off
48  // clang-format on
49  template < typename GUM_SCALAR >
50  class ExactTerminalNodePolicy : public ITerminalNodePolicy< GUM_SCALAR > {
51  public:
52  // ============================================================================
54  // ============================================================================
56 
58  void addTerminalNode(const NodeId& n, const GUM_SCALAR& v) {
59  __map.insert(n, v);
60  }
61 
63  void eraseTerminalNode(const NodeId& n) { __map.eraseFirst(n); }
64 
67 
69  // ============================================================================
71  // ============================================================================
73 
75  bool existsTerminalNodeWithId(const NodeId& n) const {
76  return __map.existsFirst(n);
77  }
78 
80  bool existsTerminalNodeWithValue(const GUM_SCALAR& v) const {
81  return __map.existsSecond(v);
82  }
83 
85  // ============================================================================
87  // ============================================================================
89 
91  const GUM_SCALAR& terminalNodeValue(const NodeId& n) const {
92  return __map.second(n);
93  }
94 
96  const NodeId& terminalNodeId(const GUM_SCALAR& v) const {
97  return __map.first(v);
98  }
99 
101  // ============================================================================
103  // ============================================================================
105 
107  void beginValues() const { __mappy = __map.beginSafe(); }
108 
110  bool hasValue() const { return __mappy != __map.endSafe(); }
111 
113  void nextValue() const { ++__mappy; }
114 
117  const GUM_SCALAR& value() const { return __mappy.second(); }
118 
121  const NodeId& id() const { return __mappy.first(); }
122 
124 
125  private:
128  };
129 
130 } // End of namespace gum
131 
132 #endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_EXACT_TERMINAL_NODE_POLICY_H */
Interface specifying the methods to be implemented by any TerminalNodePolicy.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void clear()
Removes all the associations from the gum::Bijection.
void nextValue() const
Increments the constant safe iterator.
void beginValues() const
Initializes the constant safe iterator on terminal nodes.
void clearAllTerminalNodes()
Erase all terminal nodes.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
const NodeId & id() const
Returns the id of the current terminal nodes pointed by the constant safe iterator.
void eraseFirst(const T1 &first)
Erases an association containing the given first element.
void eraseTerminalNode(const NodeId &n)
Remove node matching given id.
const NodeId & terminalNodeId(const GUM_SCALAR &v) const
Returns the id of the terminal node that has the given value.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool existsSecond(const T2 &second) const
Returns true if second is the second element in a pair in the gum::Bijection.
bool existsTerminalNodeWithValue(const GUM_SCALAR &v) const
Returns true if a terminal node matching this value exists.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
void addTerminalNode(const NodeId &n, const GUM_SCALAR &v)
Insert a new terminal node with given value.
bool hasValue() const
Indicates if constant safe iterator has reach end of terminal nodes list.
Bijection< NodeId, GUM_SCALAR > __map
iterator_safe beginSafe() const
Returns the safe iterator at the beginning of the gum::Bijection.
const GUM_SCALAR & terminalNodeValue(const NodeId &n) const
Returns the value of the terminal node that has the given id.
BijectionIteratorSafe< NodeId, GUM_SCALAR > __mappy
const T2 & second() const
Returns the second element of the current association.
bool existsTerminalNodeWithId(const NodeId &n) const
Returns true if a terminal node matching this id exists.
const iterator_safe & endSafe() const noexcept
Returns the safe iterator at the end of the gum::Bijection.
Implementation of a Terminal Node Policy that maps nodeid directly to value.
const GUM_SCALAR & value() const
Returns the value of the current terminal nodes pointed by the constant safe iterator.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const T1 & first() const
Returns the first element of the current association.