aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
PRMClassElementContainer_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 >
43  INLINE
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) {
66  GUM_ERROR(FatalError, "illegal call to ClassElementContainer copy constructor")
67  }
68 
69  template < typename GUM_SCALAR >
71  const PRMClassElement< GUM_SCALAR >& elt) const {
72  try {
73  return getIOFlag_(elt).first;
74  } catch (NotFound&) { return false; }
75  }
76 
77  template < typename GUM_SCALAR >
79  const PRMClassElement< GUM_SCALAR >& elt,
80  bool b) {
81  if (!exists(elt.safeName())) {
82  GUM_ERROR(NotFound, ": <" + elt.safeName() + "> is not in <" + name() + ">")
85  try {
86  getIOFlag_(elt).first = b;
87  } catch (NotFound&) { setIOFlag_(elt, std::make_pair(b, false)); }
88  } else {
89  GUM_ERROR(WrongClassElement, "given id is not an PRMAttribute or an PRMAggregate")
90  }
91  }
92 
93  template < typename GUM_SCALAR >
95  const PRMClassElement< GUM_SCALAR >& elt,
96  bool b) {
97  if (!exists(elt.safeName())) {
98  GUM_ERROR(NotFound, "<" + elt.safeName() + "> is not in <" + name() + ">")
101  try {
102  getIOFlag_(elt).second = b;
103  } catch (NotFound&) { setIOFlag_(elt, std::make_pair(false, b)); }
104 
105  if (b) { updateDescendants_(elt); }
106  } else {
108  "given ClassElement<GUM_SCALAR> is not an "
109  "PRMAttribute or an PRMAggregate");
110  }
111  }
112 
113  template < typename GUM_SCALAR >
115  const PRMClassElement< GUM_SCALAR >& elt) const {
116  try {
117  return !(getIOFlag_(elt).first || getIOFlag_(elt).second);
118  } catch (NotFound&) { return true; }
119  }
120 
121  template < typename GUM_SCALAR >
123  const PRMClassElementContainer< GUM_SCALAR >& cec) const {
124  return cec.isSubTypeOf(*this);
125  }
126 
127  template < typename GUM_SCALAR >
129  const PRMClassElement< GUM_SCALAR >& elt) {
130  try {
131  return _IOFlags_[elt.safeName()];
132  } catch (NotFound&) {
133  GUM_ERROR(NotFound, "this ClassElement<GUM_SCALAR> does not have any IO flags")
134  }
135  }
136 
137  template < typename GUM_SCALAR >
139  const PRMClassElement< GUM_SCALAR >& elt) const {
140  try {
141  return _IOFlags_[elt.safeName()];
142  } catch (NotFound&) {
143  GUM_ERROR(NotFound, "this ClassElement<GUM_SCALAR> does not have any IO flags")
144  }
145  }
146 
147  template < typename GUM_SCALAR >
148  INLINE void
150  const std::pair< bool, bool >& flags) {
151  try {
153  } catch (NotFound&) { _IOFlags_.insert(elt.safeName(), flags); }
154  }
155 
156  template < typename GUM_SCALAR >
158  return containerDag().exists(id);
159  }
160 
161  template < typename GUM_SCALAR >
163  try {
164  get(name);
165  return true;
166  } catch (NotFound&) { return false; }
167  }
168 
169  template < typename GUM_SCALAR >
171  const PRMClassElement< GUM_SCALAR >& elt) const {
172  try {
173  return &elt == &(get(elt.safeName()));
174  } catch (NotFound&) { return false; }
175  }
176 
177  template < typename GUM_SCALAR >
179  return dag_();
180  }
181 
182  } /* namespace prm */
183 } /* namespace gum */
184 
185 template < typename GUM_SCALAR >
188  std::string tab = " ";
189  output << "digraph \"" << container.name() << "\" {" << std::endl;
190 
191  for (const auto node: container.containerDag().nodes()) {
192  if (container.containerDag().children(node).size() > 0) {
193  for (const auto chi: container.containerDag().children(node)) {
194  output << tab << "\"" << container.get(node).name() << "\" -> "
195  << "\"" << container.get(chi).name() << "\";" << std::endl;
196  }
197  } else if (container.containerDag().parents(node).size() == 0) {
198  output << tab << "\"" << container.get(node).name() << "\";" << std::endl;
199  }
200  }
201 
202  output << "}" << std::endl;
203  return output;
204 }
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
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)