aGrUM  0.14.2
variableNodeMap.cpp
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 DOXYGEN_SHOULD_SKIP_THIS
27 
29 # include <iostream>
30 # include <sstream>
31 
32 # ifdef GUM_NO_INLINE
34 # endif /* GUM_NO_INLINE */
35 
36 namespace gum {
37 
38  // Default constructor.
40 
41  // Copy constructor.
43  GUM_CONS_CPY(VariableNodeMap);
44 
45  __copy(source);
46  }
47 
48  // Destructor
50  GUM_DESTRUCTOR(VariableNodeMap);
51 
52  clear();
53  }
54 
55  // Copy operator.
57  clear();
58  __copy(source);
59 
60  return *this;
61  }
62 
63  void VariableNodeMap::clear() {
64  for (auto iter = __nodes2vars.begin(); iter != __nodes2vars.end(); ++iter)
65  delete iter.second();
66 
67  __nodes2vars.clear();
69  }
70 
72  const std::string VariableNodeMap::toString() const {
73  std::stringstream stream;
74 
75  stream << "list of associations:" << std::endl;
76  stream << __nodes2vars << std::endl << std::endl;
77  stream << "list of variable names:" << std::endl;
78  stream << __names2nodes << std::endl;
79 
80  return stream.str();
81  }
82 
84  void VariableNodeMap::__copy(const VariableNodeMap& source) {
85  for (auto iter = source.__nodes2vars.begin();
86  iter != source.__nodes2vars.end();
87  ++iter)
88  __nodes2vars.insert(iter.first(), iter.second()->clone());
89 
90  // copy factory is used inside insert
91 
92  __names2nodes = source.__names2nodes;
93  }
94 
96  std::ostream& operator<<(std::ostream& stream, const VariableNodeMap& v) {
97  stream << v.toString();
98  return stream;
99  }
100 
101 } /* namespace gum */
102 
103 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
Inlined implementation of VariableNodeMap.
void __copy(const VariableNodeMap &source)
effectively do the copy (for copy constructor or operator=)
void clear()
Removes all the associations from the gum::Bijection.
Bijection< NodeId, const DiscreteVariable *> __nodes2vars
Bijection between the node&#39;s NodeIds and the variables.
VariableNodeMap()
Default constructor.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Header of class VariableNodeMap.
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
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.