aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
PRMClassElementContainer_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Inline implementation of gum::PRMClassElementContainer
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #include <agrum/PRM/elements/PRMClassElement.h>
30 #include <agrum/PRM/elements/PRMClassElementContainer.h>
31 
32 namespace gum {
33 
34  namespace prm {
35  template < typename GUM_SCALAR >
36  void PRMClassElementContainer< GUM_SCALAR >::copyIOFlags_(
38  for (const auto& flag: c.IOFlags__)
40  }
41 
42  template < typename GUM_SCALAR >
44  const std::string& name) :
45  PRMObject(name) {
47  }
48 
49  template < typename GUM_SCALAR >
52  }
53 
54  template < typename GUM_SCALAR >
58  GUM_ERROR(FatalError, "illegal call to ClassElementContainer copy operator");
59  }
60 
61  template < typename GUM_SCALAR >
64  PRMObject(source) {
67  "illegal call to ClassElementContainer copy constructor");
68  }
69 
70  template < typename GUM_SCALAR >
72  const PRMClassElement< GUM_SCALAR >& elt) const {
73  try {
74  return getIOFlag_(elt).first;
75  } catch (NotFound&) { return false; }
76  }
77 
78  template < typename GUM_SCALAR >
80  const PRMClassElement< GUM_SCALAR >& elt,
81  bool b) {
82  if (!exists(elt.safeName())) {
84  ": <" + elt.safeName() + "> is not in <" + name() + ">");
87  try {
88  getIOFlag_(elt).first = b;
89  } catch (NotFound&) { setIOFlag_(elt, std::make_pair(b, false)); }
90  } else {
92  "given id is not an PRMAttribute or an PRMAggregate");
93  }
94  }
95 
96  template < typename GUM_SCALAR >
98  const PRMClassElement< GUM_SCALAR >& elt,
99  bool b) {
100  if (!exists(elt.safeName())) {
101  GUM_ERROR(NotFound, "<" + elt.safeName() + "> is not in <" + name() + ">");
102  } else if (PRMClassElement< GUM_SCALAR >::isAttribute(elt)
104  try {
105  getIOFlag_(elt).second = b;
106  } catch (NotFound&) { setIOFlag_(elt, std::make_pair(false, b)); }
107 
108  if (b) { updateDescendants_(elt); }
109  } else {
111  "given ClassElement<GUM_SCALAR> is not an "
112  "PRMAttribute or an PRMAggregate");
113  }
114  }
115 
116  template < typename GUM_SCALAR >
118  const PRMClassElement< GUM_SCALAR >& elt) const {
119  try {
120  return !(getIOFlag_(elt).first || getIOFlag_(elt).second);
121  } catch (NotFound&) { return true; }
122  }
123 
124  template < typename GUM_SCALAR >
126  const PRMClassElementContainer< GUM_SCALAR >& cec) const {
127  return cec.isSubTypeOf(*this);
128  }
129 
130  template < typename GUM_SCALAR >
131  INLINE std::pair< bool, bool >&
133  const PRMClassElement< GUM_SCALAR >& elt) {
134  try {
135  return IOFlags__[elt.safeName()];
136  } catch (NotFound&) {
138  "this ClassElement<GUM_SCALAR> does not have any IO flags");
139  }
140  }
141 
142  template < typename GUM_SCALAR >
143  INLINE const std::pair< bool, bool >&
145  const PRMClassElement< GUM_SCALAR >& elt) const {
146  try {
147  return IOFlags__[elt.safeName()];
148  } catch (NotFound&) {
150  "this ClassElement<GUM_SCALAR> does not have any IO flags");
151  }
152  }
153 
154  template < typename GUM_SCALAR >
156  const PRMClassElement< GUM_SCALAR >& elt,
157  const std::pair< bool, bool >& flags) {
158  try {
160  } catch (NotFound&) { IOFlags__.insert(elt.safeName(), flags); }
161  }
162 
163  template < typename GUM_SCALAR >
165  return containerDag().exists(id);
166  }
167 
168  template < typename GUM_SCALAR >
170  const std::string& name) const {
171  try {
172  get(name);
173  return true;
174  } catch (NotFound&) { return false; }
175  }
176 
177  template < typename GUM_SCALAR >
179  const PRMClassElement< GUM_SCALAR >& elt) const {
180  try {
181  return &elt == &(get(elt.safeName()));
182  } catch (NotFound&) { return false; }
183  }
184 
185  template < typename GUM_SCALAR >
186  INLINE const DAG&
188  return dag_();
189  }
190 
191  } /* namespace prm */
192 } /* namespace gum */
193 
194 template < typename GUM_SCALAR >
195 std::ostream&
198  std::string tab = " ";
199  output << "digraph \"" << container.name() << "\" {" << std::endl;
200 
201  for (const auto node: container.containerDag().nodes()) {
202  if (container.containerDag().children(node).size() > 0) {
203  for (const auto chi: container.containerDag().children(node)) {
204  output << tab << "\"" << container.get(node).name() << "\" -> "
205  << "\"" << container.get(chi).name() << "\";" << std::endl;
206  }
207  } else if (container.containerDag().parents(node).size() == 0) {
208  output << tab << "\"" << container.get(node).name() << "\";" << std::endl;
209  }
210  }
211 
212  output << "}" << std::endl;
213  return output;
214 }
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
std::ostream & operator<<(std::ostream &output, const gum::prm::PRMClassElementContainer< GUM_SCALAR > &container)
An << operator for PRMClassElementContainer. Output in the graphviz-dot format.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)