aGrUM  0.16.0
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 58 of file O3SystemFactory.h.

Constructor & Destructor Documentation

◆ O3SystemFactory() [1/3]

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 38 of file O3SystemFactory_tpl.h.

42  :
43  __prm(&prm),
44  __o3_prm(&o3_prm), __solver(&solver), __errors(&errors) {
45  GUM_CONSTRUCTOR(O3SystemFactory);
46  }
O3NameSolver< GUM_SCALAR > * __solver
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

◆ O3SystemFactory() [2/3]

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

Definition at line 49 of file O3SystemFactory_tpl.h.

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

◆ O3SystemFactory() [3/3]

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

Definition at line 58 of file O3SystemFactory_tpl.h.

59  :
60  __prm(std::move(src.__prm)),
61  __o3_prm(std::move(src.__o3_prm)), __solver(std::move(src.__solver)),
62  __errors(std::move(src.__errors)), __nameMap(std::move(src.__nameMap)) {
63  GUM_CONS_MOV(O3SystemFactory);
64  }
O3NameSolver< GUM_SCALAR > * __solver
HashTable< std::string, O3Instance *> __nameMap
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

◆ ~O3SystemFactory()

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

Definition at line 67 of file O3SystemFactory_tpl.h.

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

67  {
68  GUM_DESTRUCTOR(O3SystemFactory);
69  }
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

◆ __addAssignments()

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

Definition at line 140 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().

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

◆ __addIncrements()

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

Definition at line 166 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().

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

◆ __addInstances()

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

Definition at line 118 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().

119  {
120  for (auto& i : sys.instances()) {
121  if (i.parameters().size() > 0) {
122  auto params = HashTable< std::string, double >();
123  for (auto& p : i.parameters()) {
124  params.insert(p.name().label(), (double)p.value().value());
125  }
126  factory.addInstance(i.type().label(), i.name().label(), params);
127 
128  } else {
129  if (i.size().value() > 1) {
130  factory.addArray(
131  i.type().label(), i.name().label(), i.size().value());
132  } else {
133  factory.addInstance(i.type().label(), i.name().label());
134  }
135  }
136  }
137  }
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:

◆ __checkAssignments()

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

Definition at line 267 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().

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

◆ __checkIncrements()

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

Definition at line 316 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().

316  {
317  for (auto& inc : sys.increments()) {
318  // if ( inc.leftInstance().label() == inc.leftReference().label() ) {
319  // O3PRM_SYSTEM_INVALID_LEFT_VALUE( inc.leftInstance(), *__errors );
320  // return false;
321  //}
322 
323  if (!__nameMap.exists(inc.leftInstance().label())) {
324  O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *__errors);
325  return false;
326  }
327 
328  auto i = __nameMap[inc.leftInstance().label()];
329  const auto& type = __prm->getClass(i->type().label());
330  const auto& ref = inc.leftReference().label();
331 
332  if (!(type.exists(inc.leftReference().label())
334  type.get(ref)))) {
335  O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
336  inc.leftReference(), type.name(), *__errors);
337  return false;
338  }
339 
340  const auto& real_ref =
341  static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(type.get(ref));
342 
343  if (!real_ref.isArray()) {
344  O3PRM_SYSTEM_NOT_AN_ARRAY(inc.leftReference(), *__errors);
345  return false;
346  }
347  }
348 
349  return true;
350  }
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &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:

◆ __checkInstance()

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

Definition at line 201 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().

201  {
202  for (auto& i : sys.instances()) {
203  if (!__solver->resolveClass(i.type())) { return false; }
204 
205  const auto& type = __prm->getClass(i.type().label());
206  if (type.parameters().size() > 0) {
207  if (!__checkParameters(type, i)) { return false; }
208  }
209 
210  if (__nameMap.exists(i.name().label())) {
211  O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *__errors);
212  return false;
213  }
214 
215  __nameMap.insert(i.name().label(), &i);
216  }
217 
218  return true;
219  }
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:

◆ __checkParameters()

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 222 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().

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

◆ __checkSystem()

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

Definition at line 191 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().

191  {
192  if (__checkInstance(sys) && __checkAssignments(sys)
193  && __checkIncrements(sys)) {
194  return true;
195  }
196 
197  return false;
198  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ build()

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

Definition at line 94 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().

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

◆ operator=() [1/2]

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

Definition at line 73 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().

73  {
74  if (this == &src) { return *this; }
75  __prm = src.__prm;
76  __o3_prm = src.__o3_prm;
77  __solver = src.__solver;
78  __errors = src.__errors;
79  return *this;
80  }
O3NameSolver< GUM_SCALAR > * __solver
+ Here is the caller graph for this function:

◆ operator=() [2/2]

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

Definition at line 84 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.

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

Member Data Documentation

◆ __errors

◆ __nameMap

◆ __o3_prm

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

◆ __prm

◆ __solver

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: