aGrUM  0.13.2
gum::prm::o3prm::O3SystemFactory< GUM_SCALAR > Class Template Reference

Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System. More...

#include <agrum/PRM/o3prm/O3SystemFactory.h>

+ Collaboration diagram for gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >:

Public Member Functions

 O3SystemFactory (PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
 
 O3SystemFactory (const O3SystemFactory< GUM_SCALAR > &src)
 
 O3SystemFactory (O3SystemFactory< GUM_SCALAR > &&src)
 
 ~O3SystemFactory ()
 
O3SystemFactory< GUM_SCALAR > & operator= (const O3SystemFactory< GUM_SCALAR > &src)
 
O3SystemFactory< GUM_SCALAR > & operator= (O3SystemFactory< GUM_SCALAR > &&src)
 
void build ()
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >

Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System.

Template Parameters
GUM_SCALARThe scalar type used by the gum::prm::PRM.

Definition at line 56 of file O3SystemFactory.h.

Constructor & Destructor Documentation

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::O3SystemFactory ( PRM< GUM_SCALAR > &  prm,
O3PRM o3_prm,
O3NameSolver< GUM_SCALAR > &  solver,
ErrorsContainer errors 
)

Definition at line 36 of file O3SystemFactory_tpl.h.

40  :
41  __prm(&prm),
42  __o3_prm(&o3_prm), __solver(&solver), __errors(&errors) {
43  GUM_CONSTRUCTOR(O3SystemFactory);
44  }
O3NameSolver< GUM_SCALAR > * __solver
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::O3SystemFactory ( const O3SystemFactory< GUM_SCALAR > &  src)

Definition at line 47 of file O3SystemFactory_tpl.h.

48  :
49  __prm(src.__prm),
50  __o3_prm(src.__o3_prm), __solver(src.__solver), __errors(src.__errors),
51  __nameMap(src.__nameMap) {
52  GUM_CONS_CPY(O3SystemFactory);
53  }
O3NameSolver< GUM_SCALAR > * __solver
HashTable< std::string, O3Instance * > __nameMap
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::O3SystemFactory ( O3SystemFactory< GUM_SCALAR > &&  src)

Definition at line 56 of file O3SystemFactory_tpl.h.

57  :
58  __prm(std::move(src.__prm)),
59  __o3_prm(std::move(src.__o3_prm)), __solver(std::move(src.__solver)),
60  __errors(std::move(src.__errors)), __nameMap(std::move(src.__nameMap)) {
61  GUM_CONS_MOV(O3SystemFactory);
62  }
O3NameSolver< GUM_SCALAR > * __solver
HashTable< std::string, O3Instance * > __nameMap
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::~O3SystemFactory ( )

Definition at line 65 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::operator=().

65  {
66  GUM_DESTRUCTOR(O3SystemFactory);
67  }
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

+ Here is the call graph for this function:

Member Function Documentation

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addAssignments ( PRMFactory< GUM_SCALAR > &  factory,
O3System sys 
)
private

Definition at line 138 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3System::assignments(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3System::name(), and gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

139  {
140  const auto& real_sys = __prm->getSystem(sys.name().label());
141 
142  for (auto& ass : sys.assignments()) {
143  auto leftInstance = ass.leftInstance().label();
144  auto leftReference = ass.leftReference().label();
145  auto rightInstance = ass.rightInstance().label();
146 
147  if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
148  std::stringstream sBuff;
149  sBuff << leftInstance << "[" << ass.leftIndex().value() << "]";
150  leftInstance = sBuff.str();
151  }
152 
153  if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
154  std::stringstream sBuff;
155  sBuff << rightInstance << "[" << ass.rightIndex().value() << "]";
156  rightInstance = sBuff.str();
157  }
158 
159  factory.setReferenceSlot(leftInstance, leftReference, rightInstance);
160  }
161  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addIncrements ( PRMFactory< GUM_SCALAR > &  factory,
O3System sys 
)
private

Definition at line 164 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3System::increments(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3System::name(), and gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

165  {
166  const auto& real_sys = __prm->getSystem(sys.name().label());
167  for (auto& inc : sys.increments()) {
168  auto leftInstance = inc.leftInstance().label();
169  auto leftReference = inc.leftReference().label();
170  auto rightInstance = inc.rightInstance().label();
171 
172  if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
173  std::stringstream sBuff;
174  sBuff << leftInstance << "[" << inc.leftIndex().value() << "]";
175  leftInstance = sBuff.str();
176  }
177 
178  if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
179  std::stringstream sBuff;
180  sBuff << rightInstance << "[" << inc.rightIndex().value() << "]";
181  rightInstance = sBuff.str();
182  }
183 
184  factory.setReferenceSlot(leftInstance, leftReference, rightInstance);
185  }
186  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addInstances ( PRMFactory< GUM_SCALAR > &  factory,
O3System sys 
)
private

Definition at line 116 of file O3SystemFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addArray(), gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::HashTable< Key, Val, Alloc >::insert(), and gum::prm::o3prm::O3System::instances().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

117  {
118  for (auto& i : sys.instances()) {
119  if (i.parameters().size() > 0) {
120  auto params = HashTable< std::string, double >();
121  for (auto& p : i.parameters()) {
122  params.insert(p.name().label(), (double)p.value().value());
123  }
124  factory.addInstance(i.type().label(), i.name().label(), params);
125 
126  } else {
127  if (i.size().value() > 1) {
128  factory.addArray(
129  i.type().label(), i.name().label(), i.size().value());
130  } else {
131  factory.addInstance(i.type().label(), i.name().label());
132  }
133  }
134  }
135  }
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkAssignments ( O3System sys)
private

Definition at line 263 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3System::assignments().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem().

263  {
264  for (auto& ass : sys.assignments()) {
265  // if ( ass.leftInstance().label() == ass.leftReference().label() ) {
266  // O3PRM_SYSTEM_INVALID_LEFT_VALUE( ass.leftInstance(), *__errors );
267  // return false;
268  //}
269 
270  if (!__nameMap.exists(ass.leftInstance().label())) {
271  O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *__errors);
272  return false;
273  }
274 
275  auto i = __nameMap[ass.leftInstance().label()];
276  const auto& type = __prm->getClass(i->type().label());
277  const auto& ref = ass.leftReference().label();
278 
279  if (!(type.exists(ass.leftReference().label())
281  type.get(ref)))) {
282  O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
283  ass.leftReference(), type.name(), *__errors);
284  return false;
285  }
286 
287  const auto& real_ref =
288  static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(type.get(ref));
289 
290  if (!__nameMap.exists(ass.rightInstance().label())) {
291  O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *__errors);
292  return false;
293  }
294 
295  if (real_ref.isArray()
296  && __nameMap[ass.rightInstance().label()]->size().value() == 0) {
297  O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *__errors);
298  return false;
299  }
300 
301  if ((!real_ref.isArray())
302  && __nameMap[ass.rightInstance().label()]->size().value() > 0
303  && ass.rightIndex().value() == -1) {
304  O3PRM_SYSTEM_NOT_AN_ARRAY(ass.leftReference(), *__errors);
305  return false;
306  }
307  }
308  return true;
309  }
static INLINE bool isReferenceSlot(const PRMClassElement &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
HashTable< std::string, O3Instance * > __nameMap

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkIncrements ( O3System sys)
private

Definition at line 312 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3System::increments().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem().

312  {
313  for (auto& inc : sys.increments()) {
314  // if ( inc.leftInstance().label() == inc.leftReference().label() ) {
315  // O3PRM_SYSTEM_INVALID_LEFT_VALUE( inc.leftInstance(), *__errors );
316  // return false;
317  //}
318 
319  if (!__nameMap.exists(inc.leftInstance().label())) {
320  O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *__errors);
321  return false;
322  }
323 
324  auto i = __nameMap[inc.leftInstance().label()];
325  const auto& type = __prm->getClass(i->type().label());
326  const auto& ref = inc.leftReference().label();
327 
328  if (!(type.exists(inc.leftReference().label())
330  type.get(ref)))) {
331  O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
332  inc.leftReference(), type.name(), *__errors);
333  return false;
334  }
335 
336  const auto& real_ref =
337  static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(type.get(ref));
338 
339  if (!real_ref.isArray()) {
340  O3PRM_SYSTEM_NOT_AN_ARRAY(inc.leftReference(), *__errors);
341  return false;
342  }
343  }
344 
345  return true;
346  }
static INLINE bool isReferenceSlot(const PRMClassElement &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
HashTable< std::string, O3Instance * > __nameMap

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkInstance ( O3System sys)
private

Definition at line 199 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkParameters(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver, and gum::prm::o3prm::O3System::instances().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem().

199  {
200  for (auto& i : sys.instances()) {
201  if (!__solver->resolveClass(i.type())) { return false; }
202 
203  const auto& type = __prm->getClass(i.type().label());
204  if (type.parameters().size() > 0) {
205  if (!__checkParameters(type, i)) { return false; }
206  }
207 
208  if (__nameMap.exists(i.name().label())) {
209  O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *__errors);
210  return false;
211  }
212 
213  __nameMap.insert(i.name().label(), &i);
214  }
215 
216  return true;
217  }
bool __checkParameters(const PRMClass< GUM_SCALAR > &type, const O3Instance &inst)
O3NameSolver< GUM_SCALAR > * __solver
HashTable< std::string, O3Instance * > __nameMap

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkParameters ( const PRMClass< GUM_SCALAR > &  type,
const O3Instance inst 
)
private

Definition at line 220 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, and gum::prm::o3prm::O3Instance::parameters().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkInstance().

221  {
222  for (const auto& param : inst.parameters()) {
223  if (!type.exists(param.name().label())) {
224  O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *__errors);
225  return false;
226  }
227 
229  type.get(param.name().label()))) {
230  O3PRM_SYSTEM_NOT_A_PARAMETER(param, *__errors);
231  return false;
232  }
233 
234  const auto& type_param =
235  static_cast< const PRMParameter< GUM_SCALAR >& >(
236  type.get(param.name().label()));
237 
238  switch (type_param.valueType()) {
239  case PRMParameter< GUM_SCALAR >::ParameterType::INT: {
240  if (!param.isInteger()) {
241  O3PRM_SYSTEM_PARAMETER_NOT_INT(param, *__errors);
242  return false;
243  }
244  break;
245  }
246 
247  case PRMParameter< GUM_SCALAR >::ParameterType::REAL: {
248  if (param.isInteger()) {
249  O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(param, *__errors);
250  return false;
251  }
252  break;
253  }
254 
255  default: { GUM_ERROR(FatalError, "unknown parameter type"); }
256  }
257  }
258  return true;
259  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
static INLINE bool isParameter(const PRMClassElement &elt)
Return true if obj is of type PRMParameter.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem ( O3System sys)
private

Definition at line 189 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkAssignments(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkIncrements(), and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkInstance().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

189  {
190  if (__checkInstance(sys) && __checkAssignments(sys)
191  && __checkIncrements(sys)) {
192  return true;
193  }
194 
195  return false;
196  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build ( )

Definition at line 92 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addAssignments(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addIncrements(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addInstances(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::endSystem(), gum::prm::PRMFactory< GUM_SCALAR >::startSystem(), and gum::prm::o3prm::O3PRM::systems().

92  {
93  PRMFactory< GUM_SCALAR > factory(__prm);
94 
95  for (auto& sys : __o3_prm->systems()) {
96  // Reseting name map for each system
97  __nameMap = HashTable< std::string, O3Instance* >();
98 
99  if (__checkSystem(*sys)) {
100  factory.startSystem(sys->name().label());
101 
102  __addInstances(factory, *sys);
103  __addAssignments(factory, *sys);
104  __addIncrements(factory, *sys);
105 
106  try {
107  factory.endSystem();
108  } catch (FatalError&) {
109  O3PRM_SYSTEM_INSTANTIATION_FAILED(*sys, *__errors);
110  }
111  }
112  }
113  }
void __addIncrements(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
void __addAssignments(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
O3SystemList & systems()
Definition: O3prm.cpp:505
HashTable< std::string, O3Instance * > __nameMap
void __addInstances(PRMFactory< GUM_SCALAR > &factory, O3System &sys)

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE O3SystemFactory< GUM_SCALAR > & gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::operator= ( const O3SystemFactory< GUM_SCALAR > &  src)

Definition at line 71 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver.

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::~O3SystemFactory().

71  {
72  if (this == &src) { return *this; }
73  __prm = src.__prm;
74  __o3_prm = src.__o3_prm;
75  __solver = src.__solver;
76  __errors = src.__errors;
77  return *this;
78  }
O3NameSolver< GUM_SCALAR > * __solver

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE O3SystemFactory< GUM_SCALAR > & gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::operator= ( O3SystemFactory< GUM_SCALAR > &&  src)

Definition at line 82 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver.

82  {
83  if (this == &src) { return *this; }
84  __prm = std::move(src.__prm);
85  __o3_prm = std::move(src.__o3_prm);
86  __solver = std::move(src.__solver);
87  __errors = std::move(src.__errors);
88  return *this;
89  }
O3NameSolver< GUM_SCALAR > * __solver

Member Data Documentation

template<typename GUM_SCALAR>
O3PRM* gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm
private
template<typename GUM_SCALAR>
O3NameSolver< GUM_SCALAR >* gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver
private

The documentation for this class was generated from the following files: