aGrUM  0.16.0
PRMClassElementContainer_tpl.h
Go to the documentation of this file.
1 
32 
33 namespace gum {
34 
35  namespace prm {
36  template < typename GUM_SCALAR >
39  for (const auto& flag : c.__IOFlags)
40  _setIOFlag(get(flag.first), flag.second);
41  }
42 
43  template < typename GUM_SCALAR >
45  const std::string& name) :
46  PRMObject(name) {
47  GUM_CONSTRUCTOR(PRMClassElementContainer);
48  }
49 
50  template < typename GUM_SCALAR >
52  GUM_DESTRUCTOR(PRMClassElementContainer);
53  }
54 
55  template < typename GUM_SCALAR >
59  GUM_ERROR(FatalError, "illegal call to ClassElementContainer copy operator");
60  }
61 
62  template < typename GUM_SCALAR >
65  PRMObject(source) {
66  GUM_CONS_CPY(PRMClassElementContainer);
68  "illegal call to ClassElementContainer copy constructor");
69  }
70 
71  template < typename GUM_SCALAR >
73  const PRMClassElement< GUM_SCALAR >& elt) const {
74  try {
75  return _getIOFlag(elt).first;
76  } catch (NotFound&) { return false; }
77  }
78 
79  template < typename GUM_SCALAR >
81  const PRMClassElement< GUM_SCALAR >& elt, 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, bool b) {
99  if (!exists(elt.safeName())) {
100  GUM_ERROR(NotFound, "<" + elt.safeName() + "> is not in <" + name() + ">");
103  try {
104  _getIOFlag(elt).second = b;
105  } catch (NotFound&) { _setIOFlag(elt, std::make_pair(false, b)); }
106 
107  if (b) { _updateDescendants(elt); }
108  } else {
110  "given ClassElement<GUM_SCALAR> is not an "
111  "PRMAttribute or an PRMAggregate");
112  }
113  }
114 
115  template < typename GUM_SCALAR >
117  const PRMClassElement< GUM_SCALAR >& elt) const {
118  try {
119  return !(_getIOFlag(elt).first || _getIOFlag(elt).second);
120  } catch (NotFound&) { return true; }
121  }
122 
123  template < typename GUM_SCALAR >
125  const PRMClassElementContainer< GUM_SCALAR >& cec) const {
126  return cec.isSubTypeOf(*this);
127  }
128 
129  template < typename GUM_SCALAR >
130  INLINE std::pair< bool, bool >&
132  const PRMClassElement< GUM_SCALAR >& elt) {
133  try {
134  return __IOFlags[elt.safeName()];
135  } catch (NotFound&) {
137  "this ClassElement<GUM_SCALAR> does not have any IO flags");
138  }
139  }
140 
141  template < typename GUM_SCALAR >
142  INLINE const std::pair< bool, bool >&
144  const PRMClassElement< GUM_SCALAR >& elt) const {
145  try {
146  return __IOFlags[elt.safeName()];
147  } catch (NotFound&) {
149  "this ClassElement<GUM_SCALAR> does not have any IO flags");
150  }
151  }
152 
153  template < typename GUM_SCALAR >
156  const std::pair< bool, bool >& flags) {
157  try {
158  __IOFlags[elt.safeName()] = flags;
159  } catch (NotFound&) { __IOFlags.insert(elt.safeName(), flags); }
160  }
161 
162  template < typename GUM_SCALAR >
164  return containerDag().exists(id);
165  }
166 
167  template < typename GUM_SCALAR >
169  const std::string& name) const {
170  try {
171  get(name);
172  return true;
173  } catch (NotFound&) { return false; }
174  }
175 
176  template < typename GUM_SCALAR >
178  const PRMClassElement< GUM_SCALAR >& elt) const {
179  try {
180  return &elt == &(get(elt.safeName()));
181  } catch (NotFound&) { return false; }
182  }
183 
184  template < typename GUM_SCALAR >
185  INLINE const DAG&
187  return _dag();
188  }
189 
190  } /* namespace prm */
191 } /* namespace gum */
192 
193 template < typename GUM_SCALAR >
194 std::ostream&
195  operator<<(std::ostream& output,
197  std::string tab = " ";
198  output << "digraph \"" << container.name() << "\" {" << std::endl;
199 
200  for (const auto node : container.containerDag().nodes()) {
201  if (container.containerDag().children(node).size() > 0) {
202  for (const auto chi : container.containerDag().children(node)) {
203  output << tab << "\"" << container.get(node).name() << "\" -> "
204  << "\"" << container.get(chi).name() << "\";" << std::endl;
205  }
206  } else if (container.containerDag().parents(node).size() == 0) {
207  output << tab << "\"" << container.get(node).name() << "\";" << std::endl;
208  }
209  }
210 
211  output << "}" << std::endl;
212  return output;
213 }
PRMClassElementContainer(const std::string &name)
Default constructor.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:35
Abstract class representing an element of PRM class.
virtual PRMClassElement< GUM_SCALAR > & get(const std::string &name)=0
Getter on a member of this PRMClassElementContainer.
virtual bool exists(const std::string &name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
virtual void _copyIOFlags(const PRMClassElementContainer< GUM_SCALAR > &c)
Copy the IO Flags of c in this PRMClassElementContainer.
virtual bool isSubTypeOf(const PRMClassElementContainer< GUM_SCALAR > &cec) const =0
Test if this PRMClassElementContainer is a subtype of cec.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
std::ostream & operator<<(std::ostream &output, const gum::prm::PRMClassElementContainer< GUM_SCALAR > &container)
An << operator for PRMClassElementContainer. Output in the graphviz-dot format.
HashTable< std::string, std::pair< bool, bool > > __IOFlags
input / output flags, useful when inheriting or copying.
Abstract base class for any element defined in a PRM.
Definition: PRMObject.h:56
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/PRM/classElementContainer.h>
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
Base class for dag.
Definition: DAG.h:102
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55