aGrUM  0.14.2
PRM_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #include <agrum/PRM/PRM.h>
27 
28 namespace gum {
29  namespace prm {
30 
31  // Default constructor.
32  template < typename GUM_SCALAR >
34  GUM_CONSTRUCTOR(PRM);
35  __addBuiltInTypes();
36  }
37 
38  // Destructor.
39  template < typename GUM_SCALAR >
41  GUM_DESTRUCTOR(PRM);
42  __classMap.clear();
43  __typeMap.clear();
44  __systemMap.clear();
45 
46  for (const auto sys : __systems)
47  delete sys;
48 
49  for (const auto cla : __classes)
50  delete cla;
51 
52  for (const auto inter : __interfaces)
53  delete inter;
54 
55  for (const auto typ : __types)
56  delete typ;
57  }
58 
59  // Add the built-in types in the PRM
60  template < typename GUM_SCALAR >
62  LabelizedVariable var("boolean", "built-in type", 0);
63  var.addLabel("false");
64  var.addLabel("true");
65  PRMType* boolean = new PRMType(var);
66  __types.insert(boolean);
67  __typeMap.insert("boolean", boolean);
68  }
69 
70  template < typename GUM_SCALAR >
71  INLINE bool PRM< GUM_SCALAR >::isType(const std::string& name) const {
72  return __typeMap.exists(name);
73  }
74 
75  template < typename GUM_SCALAR >
76  INLINE bool PRM< GUM_SCALAR >::isClass(const std::string& name) const {
77  return __classMap.exists(name);
78  }
79 
80  template < typename GUM_SCALAR >
81  INLINE bool PRM< GUM_SCALAR >::isInterface(const std::string& name) const {
82  return __interfaceMap.exists(name);
83  }
84 
85  template < typename GUM_SCALAR >
86  INLINE bool PRM< GUM_SCALAR >::isSystem(const std::string& name) const {
87  return __systemMap.exists(name);
88  }
89 
90  template < typename GUM_SCALAR >
91  INLINE PRMType& PRM< GUM_SCALAR >::type(const std::string& name) {
92  return *(__typeMap[name]);
93  }
94 
95  template < typename GUM_SCALAR >
96  INLINE const PRMType& PRM< GUM_SCALAR >::type(const std::string& name) const {
97  return *(__typeMap[name]);
98  }
99 
100  template < typename GUM_SCALAR >
102  return __types;
103  }
104 
105  template < typename GUM_SCALAR >
106  INLINE PRMClass< GUM_SCALAR >&
107  PRM< GUM_SCALAR >::getClass(const std::string& name) {
108  return *(__classMap[name]);
109  }
110 
111  template < typename GUM_SCALAR >
112  INLINE const PRMClass< GUM_SCALAR >&
113  PRM< GUM_SCALAR >::getClass(const std::string& name) const {
114  return *(__classMap[name]);
115  }
116 
117  template < typename GUM_SCALAR >
118  INLINE const Set< PRMClass< GUM_SCALAR >* >&
120  return __classes;
121  }
122 
123  template < typename GUM_SCALAR >
125  PRM< GUM_SCALAR >::getInterface(const std::string& name) {
126  return *__interfaceMap[name];
127  }
128 
129  template < typename GUM_SCALAR >
130  INLINE const PRMInterface< GUM_SCALAR >&
131  PRM< GUM_SCALAR >::getInterface(const std::string& name) const {
132  return *__interfaceMap[name];
133  }
134 
135  template < typename GUM_SCALAR >
136  INLINE const Set< PRMInterface< GUM_SCALAR >* >&
138  return __interfaces;
139  }
140 
141  template < typename GUM_SCALAR >
143  PRM< GUM_SCALAR >::getSystem(const std::string& name) {
144  return *(__systemMap[name]);
145  }
146 
147  template < typename GUM_SCALAR >
148  INLINE const PRMSystem< GUM_SCALAR >&
149  PRM< GUM_SCALAR >::getSystem(const std::string& name) const {
150  return *(__systemMap[name]);
151  }
152 
153  template < typename GUM_SCALAR >
154  INLINE const Set< PRMSystem< GUM_SCALAR >* >&
156  return __systems;
157  }
158 
159  } /* namespace prm */
160 } /* namespace gum */
PRMInterface< GUM_SCALAR > & getInterface(const std::string &name)
Returns a constant reference on a Class<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:125
const Set< PRMType *> & types() const
Returns the Set of all PRMType in this PRM.
Definition: PRM_tpl.h:101
bool isClass(const std::string &name) const
Definition: PRM_tpl.h:76
class LabelizedVariable
PRM()
Default constructor.
Definition: PRM_tpl.h:33
const Set< PRMSystem< GUM_SCALAR > *> & systems() const
Returns the Set of all Systems in this PRM.
Definition: PRM_tpl.h:155
void __addBuiltInTypes()
Add the built-in types in the PRM.
Definition: PRM_tpl.h:61
const Set< PRMClass< GUM_SCALAR > *> & classes() const
Returns the Set of all Class<GUM_SCALAR> in this PRM.
Definition: PRM_tpl.h:119
Headers of PRM.
const Set< PRMInterface< GUM_SCALAR > *> & interfaces() const
Returns the Set of all Class<GUM_SCALAR> in this PRM.
Definition: PRM_tpl.h:137
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool isType(const std::string &name) const
Definition: PRM_tpl.h:71
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
~PRM()
Destructor.
Definition: PRM_tpl.h:40
PRMType & type(const std::string &name)
Returns a constant reference on a PRMType given it&#39;s name.
Definition: PRM_tpl.h:91
bool isSystem(const std::string &name) const
Definition: PRM_tpl.h:86
PRMSystem< GUM_SCALAR > & getSystem(const std::string &name)
Returns a constant reference on a PRMSystem<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:143
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition: PRMObject.h:226
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:60
An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALA...
Definition: PRMClass.h:51
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Definition: PRM.h:63
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Definition: PRMClass.h:63
PRMClass< GUM_SCALAR > & getClass(const std::string &name)
Returns a constant reference on a Class<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:107
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
bool isInterface(const std::string &name) const
Definition: PRM_tpl.h:81