aGrUM  0.16.0
variableNodeMap.cpp
Go to the documentation of this file.
1 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
32 # include <iostream>
33 # include <sstream>
34 
35 # ifdef GUM_NO_INLINE
37 # endif /* GUM_NO_INLINE */
38 
39 namespace gum {
40 
41  // Default constructor.
43 
44  // Copy constructor.
46  GUM_CONS_CPY(VariableNodeMap);
47 
48  __copy(source);
49  }
50 
51  // Destructor
53  GUM_DESTRUCTOR(VariableNodeMap);
54 
55  clear();
56  }
57 
58  // Copy operator.
60  clear();
61  __copy(source);
62 
63  return *this;
64  }
65 
66  void VariableNodeMap::clear() {
67  for (auto iter = __nodes2vars.begin(); iter != __nodes2vars.end(); ++iter)
68  delete iter.second();
69 
70  __nodes2vars.clear();
72  }
73 
75  const std::string VariableNodeMap::toString() const {
76  std::stringstream stream;
77 
78  stream << "list of associations:" << std::endl;
79  stream << __nodes2vars << std::endl << std::endl;
80  stream << "list of variable names:" << std::endl;
81  stream << __names2nodes << std::endl;
82 
83  return stream.str();
84  }
85 
87  void VariableNodeMap::__copy(const VariableNodeMap& source) {
88  for (auto iter = source.__nodes2vars.begin();
89  iter != source.__nodes2vars.end();
90  ++iter)
91  __nodes2vars.insert(iter.first(), iter.second()->clone());
92 
93  // copy factory is used inside insert
94 
95  __names2nodes = source.__names2nodes;
96  }
97 
99  std::ostream& operator<<(std::ostream& stream, const VariableNodeMap& v) {
100  stream << v.toString();
101  return stream;
102  }
103 
104 } /* namespace gum */
105 
106 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
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.
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:605
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.