aGrUM  0.14.2
ExactTerminalNodePolicy.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_EXACT_TERMINAL_NODE_POLICY_H
28 #define GUM_MULTI_DIM_FUNCTION_GRAPH_EXACT_TERMINAL_NODE_POLICY_H
29 
30 #include <agrum/core/bijection.h>
33 
34 namespace gum {
35 
36  // clang-format off
45  // clang-format on
46  template < typename GUM_SCALAR >
47  class ExactTerminalNodePolicy : public ITerminalNodePolicy< GUM_SCALAR > {
48  public:
49  // ============================================================================
51  // ============================================================================
53 
55  void addTerminalNode(const NodeId& n, const GUM_SCALAR& v) {
56  __map.insert(n, v);
57  }
58 
60  void eraseTerminalNode(const NodeId& n) { __map.eraseFirst(n); }
61 
64 
66  // ============================================================================
68  // ============================================================================
70 
72  bool existsTerminalNodeWithId(const NodeId& n) const {
73  return __map.existsFirst(n);
74  }
75 
77  bool existsTerminalNodeWithValue(const GUM_SCALAR& v) const {
78  return __map.existsSecond(v);
79  }
80 
82  // ============================================================================
84  // ============================================================================
86 
88  const GUM_SCALAR& terminalNodeValue(const NodeId& n) const {
89  return __map.second(n);
90  }
91 
93  const NodeId& terminalNodeId(const GUM_SCALAR& v) const {
94  return __map.first(v);
95  }
96 
98  // ============================================================================
100  // ============================================================================
102 
104  void beginValues() const { __mappy = __map.beginSafe(); }
105 
107  bool hasValue() const { return __mappy != __map.endSafe(); }
108 
110  void nextValue() const { ++__mappy; }
111 
114  const GUM_SCALAR& value() const { return __mappy.second(); }
115 
118  const NodeId& id() const { return __mappy.first(); }
119 
121 
122  private:
125  };
126 
127 } // End of namespace gum
128 
129 #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.
Base node set class for graphs.
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.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Headers of the ITerminalNodePolicy.
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:97
Set of pairs of elements with fast search for both elements.
const T1 & first() const
Returns the first element of the current association.