aGrUM  0.14.2
variableNodeMap.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}@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  ***************************************************************************/
26 #ifndef GUM_VARIABLE_NODE_MAP_H
27 #define GUM_VARIABLE_NODE_MAP_H
28 
29 #include <iostream>
30 #include <string>
31 
32 #include <agrum/agrum.h>
33 
34 #include <agrum/core/bijection.h>
37 
38 namespace gum {
39 
48  public:
50 
52 
55 
58  VariableNodeMap(const VariableNodeMap& source);
59 
62 
65 
67 
68  // ===========================================================================
70  // ===========================================================================
72 
74 
75  const DiscreteVariable& get(NodeId id) const;
76 
78 
79  NodeId get(const DiscreteVariable& var) const;
80 
82  bool exists(NodeId id) const;
83 
85  bool exists(const DiscreteVariable& var) const;
86 
88 
93  NodeId insert(NodeId id, const DiscreteVariable& var);
94 
96 
97  void erase(NodeId id);
98 
100 
101  void erase(const DiscreteVariable& var);
102 
104 
106  void changeName(NodeId id, const std::string& new_name);
107 
109  void clear();
110 
112  const std::string toString() const;
113 
120  const std::string& name(NodeId id) const;
121 
128  const std::string& name(const DiscreteVariable& var) const;
129 
131 
132  // ===========================================================================
134  // ===========================================================================
136 
138 
139  const DiscreteVariable& operator[](NodeId id) const;
140 
142 
143  NodeId operator[](const DiscreteVariable& var) const;
144 
146 
147  // ===========================================================================
149  // ===========================================================================
151 
153  NodeId idFromName(const std::string& name) const;
154  const DiscreteVariable& variableFromName(const std::string& name) const;
155 
157 
158  private:
160  void __copy(const VariableNodeMap& source);
161 
164 
167  };
168 
170 
171  std::ostream& operator<<(std::ostream&, const VariableNodeMap&);
172 
173 } /* namespace gum */
174 
175 #ifndef GUM_NO_INLINE
177 #endif /* GUM_NO_INLINE */
178 
179 #endif /* GUM_VARIABLE_NODE_MAP_H*/
Inlined implementation of VariableNodeMap.
void __copy(const VariableNodeMap &source)
effectively do the copy (for copy constructor or operator=)
const std::string & name(NodeId id) const
Returns the name of a variable given its id.
Base class for discrete random variable.
Bijection< NodeId, const DiscreteVariable *> __nodes2vars
Bijection between the node&#39;s NodeIds and the variables.
NodeId insert(NodeId id, const DiscreteVariable &var)
Maps id with var.
VariableNodeMap()
Default constructor.
Container used to map discrete variables with nodes.
bool exists(NodeId id) const
Return true if id matches a node.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void erase(NodeId id)
Removes a var and it&#39;s id of this mapping. The pointer is deleted.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:583
void clear()
removes all the associations
const DiscreteVariable & operator[](NodeId id) const
Returns a discrete variable given it&#39;s node id.
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
NodeId idFromName(const std::string &name) const
void changeName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable
VariableNodeMap & operator=(const VariableNodeMap &source)
Copy operator.
const std::string toString() const
friendly displays the content of the VariableNodeMap
Bijection< std::string, NodeId > __names2nodes
HashTable for easely find an id from a name.
~VariableNodeMap()
Destructor.
const DiscreteVariable & variableFromName(const std::string &name) const
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Set of pairs of elements with fast search for both elements.
some utils for topology : NodeId, Edge, Arc and consorts ...