aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
variableNodeMap.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
49
50# include <iostream>
51# include <sstream>
52
54
55# ifdef GUM_NO_INLINE
57# endif /* GUM_NO_INLINE */
58
59namespace gum {
60
61 // Default constructor.
63 GUM_CONSTRUCTOR(VariableNodeMap);
64 ;
65 }
66
67 // Copy constructor.
69 GUM_CONS_CPY(VariableNodeMap);
70
71 _copy_(source);
72 }
73
74 // Destructor
76 GUM_DESTRUCTOR(VariableNodeMap);
77
78 clear();
79 }
80
81 // Copy operator.
83 clear();
84 _copy_(source);
85
86 return *this;
87 }
88
90 for (auto iter = _nodes2vars_.begin(); iter != _nodes2vars_.end(); ++iter)
91 delete iter.second();
92
93 _nodes2vars_.clear();
94 _names2nodes_.clear();
95 }
96
98 std::string VariableNodeMap::toString() const {
99 std::stringstream stream;
100
101 stream << "list of associations:" << std::endl;
102 stream << _nodes2vars_ << std::endl << std::endl;
103 stream << "list of variable names:" << std::endl;
104 stream << _names2nodes_ << std::endl;
105
106 return stream.str();
107 }
108
110 void VariableNodeMap::_copy_(const VariableNodeMap& source) {
111 for (auto iter = source._nodes2vars_.begin(); iter != source._nodes2vars_.end(); ++iter)
112 _nodes2vars_.insert(iter.first(), iter.second()->clone());
113
114 // copy factory is used inside insert
115
116 _names2nodes_ = source._names2nodes_;
117 }
118
120 std::ostream& operator<<(std::ostream& stream, const VariableNodeMap& v) {
121 stream << v.toString();
122 return stream;
123 }
124
125} /* namespace gum */
126
127#endif /* DOXYGEN_SHOULD_SKIP_THIS */
Container used to map discrete variables with nodes.
VariableNodeMap & operator=(const VariableNodeMap &source)
Copy operator.
void _copy_(const VariableNodeMap &source)
effectively do the copy (for copy constructor or operator=)
~VariableNodeMap()
Destructor.
Bijection< std::string, NodeId > _names2nodes_
HashTable for easely find an id from a name.
void clear()
removes all the associations
Bijection< NodeId, const DiscreteVariable * > _nodes2vars_
Bijection between the node's NodeIds and the variables.
std::string toString() const
friendly displays the content of the VariableNodeMap
VariableNodeMap()
Default constructor.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Definition AVLTree.h:913
Header of class VariableNodeMap.
Inlined implementation of VariableNodeMap.