aGrUM  0.16.0
gum::prm::o3prm::O3NameSolver< GUM_SCALAR > Class Template Reference

Resolves names for the different O3PRM factories. More...

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

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

Public Member Functions

 O3NameSolver (PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
 
 O3NameSolver (const O3NameSolver< GUM_SCALAR > &src)
 
 O3NameSolver (O3NameSolver< GUM_SCALAR > &&src)
 
 ~O3NameSolver ()
 
O3NameSolver< GUM_SCALAR > & operator= (const O3NameSolver< GUM_SCALAR > &src)
 
O3NameSolver< GUM_SCALAR > & operator= (O3NameSolver< GUM_SCALAR > &&src)
 
bool resolveClassElement (O3Label &name)
 
bool resolveType (O3Label &name)
 
bool resolveInterface (O3Label &name)
 
bool resolveClass (O3Label &name)
 
bool resolveSlotType (O3Label &name)
 

Detailed Description

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

Resolves names for the different O3PRM factories.

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

Definition at line 57 of file O3NameSolver.h.

Member Typedef Documentation

◆ NameMap

template<typename GUM_SCALAR>
using gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::NameMap = HashTable< std::string, std::string >
private

Definition at line 89 of file O3NameSolver.h.

Constructor & Destructor Documentation

◆ O3NameSolver() [1/3]

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

Definition at line 38 of file O3NameSolver_tpl.h.

40  :
41  __prm(&prm),
42  __o3_prm(&o3_prm), __errors(&errors) {
43  GUM_CONSTRUCTOR(O3NameSolver);
44  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85

◆ O3NameSolver() [2/3]

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

Definition at line 47 of file O3NameSolver_tpl.h.

48  :
49  __prm(src.__prm),
50  __o3_prm(src.__o3_prm), __errors(src.__errors),
51  __typeName(src.__typeName), __eltName(src.__eltName),
52  __refName(src.__refName), __interfaceName(src.__interfaceName),
53  __className(src.__className) {
54  GUM_CONS_CPY(O3NameSolver);
55  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85

◆ O3NameSolver() [3/3]

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

Definition at line 58 of file O3NameSolver_tpl.h.

59  :
60  __prm(std::move(src.__prm)),
61  __o3_prm(std::move(src.__o3_prm)), __errors(std::move(src.__errors)),
62  __typeName(std::move(src.__typeName)),
63  __eltName(std::move(src.__eltName)), __refName(std::move(src.__refName)),
64  __interfaceName(std::move(src.__interfaceName)),
65  __className(std::move(src.__className)) {
66  GUM_CONS_MOV(O3NameSolver);
67  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85

◆ ~O3NameSolver()

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

Definition at line 70 of file O3NameSolver_tpl.h.

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

70  {
71  GUM_DESTRUCTOR(O3NameSolver);
72  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
+ Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

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

Definition at line 76 of file O3NameSolver_tpl.h.

References gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__className, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__eltName, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__errors, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__interfaceName, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__refName, and gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__typeName.

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

76  {
77  if (this == &src) { return *this; }
78  __prm = src.__prm;
79  __o3_prm = src.__o3_prm;
80  __errors = src.__errors;
81  __typeName = src.__typeName;
82  __eltName = src.__eltName;
83  __refName = src.__refName;
84  __interfaceName = src.__interfaceName;
85  __className = src.__className;
86  return *this;
87  }
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85
+ Here is the caller graph for this function:

◆ operator=() [2/2]

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

Definition at line 91 of file O3NameSolver_tpl.h.

References gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__className, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__eltName, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__errors, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__interfaceName, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__refName, and gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__typeName.

91  {
92  if (this == &src) { return *this; }
93  __prm = std::move(src.__prm);
94  __o3_prm = std::move(src.__o3_prm);
95  __errors = std::move(src.__errors);
96  __typeName = std::move(src.__typeName);
97  __eltName = std::move(src.__eltName);
98  __refName = std::move(src.__refName);
99  __interfaceName = std::move(src.__interfaceName);
100  __className = std::move(src.__className);
101  return *this;
102  }
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85

◆ resolveClass()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClass ( O3Label name)

Definition at line 371 of file O3NameSolver_tpl.h.

References gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__className, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__errors, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__prm, gum::prm::o3prm::O3PRM::classes(), gum::endsWith(), gum::HashTable< Key, Val, Alloc >::exists(), gum::HashTable< Key, Val, Alloc >::insert(), and gum::prm::o3prm::O3Label::label().

371  {
372  // If empty string, we return an empty string
373  if (name.label() == "") { return true; }
374 
375  // If we've already found super real name
376  if (__className.exists(name.label())) {
377  name.label() = __className[name.label()];
378  return true;
379  }
380 
381  // If class name exists as is
382  if (__prm->isClass(name.label())) {
383  __className.insert(name.label(), name.label());
384  return true;
385  }
386 
387  for (auto& c : __o3_prm->classes()) {
388  if (c->name().label() == name.label()) {
389  __className.insert(name.label(), name.label());
390  return true;
391  }
392  }
393 
394  // If we didn't find it as is, then we must find a namespace
395  // in which it was declared
396  auto lookup = "." + name.label();
397  auto matches = std::vector< std::string >();
398  auto found = Set< std::string >();
399 
400  // Try to complete with Class
401  for (auto c : __prm->classes()) {
402  if (endsWith(c->name(), lookup)) {
403  if (!found.exists(c->name())) {
404  found.insert(c->name());
405  matches.push_back(c->name());
406  }
407  }
408  }
409 
410  // Try to complete with O3Class
411  for (auto& c : __o3_prm->classes()) {
412  if (endsWith(c->name().label(), lookup)) {
413  if (!found.exists(c->name().label())) {
414  found.insert(c->name().label());
415  matches.push_back(c->name().label());
416  }
417  }
418  }
419 
420  if (matches.size() == 1) { // One match is good
421 
422  __className.insert(name.label(), matches.back());
423  name.label() = matches.back();
424  return true;
425 
426  } else if (matches.size() == 0) { // 0 match is not found
427 
428  // Unknown super class
429  O3PRM_CLASS_NOT_FOUND(name, *__errors);
430  return false;
431 
432  } else { // More than one match is ambiguous
433 
434  // Ambiguous name
435  O3PRM_CLASS_AMBIGUOUS(name, matches, *__errors);
436  return false;
437  }
438  }
O3ClassList & classes()
Definition: O3prm.cpp:503
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool endsWith(std::string const &value, std::string const &ending)
Returns true if value ends with ending.
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85
+ Here is the call graph for this function:

◆ resolveClassElement()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClassElement ( O3Label name)

Definition at line 105 of file O3NameSolver_tpl.h.

References gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__eltName, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__errors, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__prm, gum::prm::o3prm::O3PRM::classes(), gum::endsWith(), gum::HashTable< Key, Val, Alloc >::exists(), gum::Set< Key, Alloc >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), gum::prm::o3prm::O3PRM::interfaces(), gum::prm::o3prm::O3Label::label(), gum::Set< Key, Alloc >::size(), and gum::prm::o3prm::O3PRM::types().

105  {
106  // If empty string, we return an empty string
107  if (name.label() == "") { return true; }
108  // If we've already found the element real name
109  if (__eltName.exists(name.label())) {
110  name.label() = __eltName[name.label()];
111  return true;
112  }
113  // If name exists as is
114  if (__prm->isType(name.label())) {
115  __eltName.insert(name.label(), name.label());
116  return true;
117  }
118  // If name exists as is
119  if (__prm->isInterface(name.label())) {
120  __eltName.insert(name.label(), name.label());
121  return true;
122  }
123  // If name exists as is
124  if (__prm->isClass(name.label())) {
125  __eltName.insert(name.label(), name.label());
126  return true;
127  }
128  // If name exists as is in O3PRM types
129  for (auto& t : __o3_prm->types()) {
130  if (t->name().label() == name.label()) {
131  __eltName.insert(name.label(), name.label());
132  return true;
133  }
134  }
135  // If name exists as is in O3PRM interfaces
136  for (auto& i : __o3_prm->interfaces()) {
137  if (i->name().label() == name.label()) {
138  __eltName.insert(name.label(), name.label());
139  return true;
140  }
141  }
142  // If name exists as is in O3PRM classes
143  for (auto& c : __o3_prm->classes()) {
144  if (c->name().label() == name.label()) {
145  __eltName.insert(name.label(), name.label());
146  return true;
147  }
148  }
149 
150  auto lookup = "." + name.label();
151  auto found = Set< std::string >();
152  auto matches = std::vector< std::string >();
153 
154  // Trying with types
155  for (auto t : __prm->types()) {
156  if (endsWith(t->name(), lookup)) {
157  if (!found.exists(t->name())) {
158  found.insert(t->name());
159  matches.push_back(t->name());
160  }
161  }
162  }
163  // Trying with O3Types
164  for (auto& t : __o3_prm->types()) {
165  if (endsWith(t->name().label(), lookup)) {
166  if (!found.exists(t->name().label())) {
167  found.insert(t->name().label());
168  matches.push_back(t->name().label());
169  }
170  }
171  }
172 
173  // Trying with interfaces
174  for (auto i : __prm->interfaces()) {
175  if (endsWith(i->name(), lookup)) {
176  if (!found.exists(i->name())) {
177  found.insert(i->name());
178  matches.push_back(i->name());
179  }
180  }
181  }
182  // Trying with O3Interface
183  for (auto& i : __o3_prm->interfaces()) {
184  if (endsWith(i->name().label(), lookup)) {
185  if (!found.exists(i->name().label())) {
186  found.insert(i->name().label());
187  matches.push_back(i->name().label());
188  }
189  }
190  }
191 
192  // Trying with class
193  for (auto c : __prm->classes()) {
194  if (endsWith(c->name(), lookup)) {
195  if (!found.exists(c->name())) {
196  found.insert(c->name());
197  matches.push_back(c->name());
198  }
199  }
200  }
201  // Trying with O3Class
202  for (auto& c : __o3_prm->classes()) {
203  if (endsWith(c->name().label(), lookup)) {
204  if (!found.exists(c->name().label())) {
205  found.insert(c->name().label());
206  matches.push_back(c->name().label());
207  }
208  }
209  }
210 
211  if (matches.size() == 1) { // One match is good
212  __eltName.insert(name.label(), matches.back());
213  name.label() = matches.back();
214  return true;
215 
216  } else if (matches.size() == 0) { // 0 match is not found
217 
218  // Unknown name type
219  O3PRM_TYPE_NOT_FOUND(name, *__errors);
220  return false;
221 
222  } else { // More than one match is ambiguous
223 
224  // Ambiguous name
225  O3PRM_TYPE_AMBIGUOUS(name, matches, *__errors);
226  return false;
227  }
228  }
O3ClassList & classes()
Definition: O3prm.cpp:503
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool endsWith(std::string const &value, std::string const &ending)
Returns true if value ends with ending.
O3InterfaceList & interfaces()
Definition: O3prm.cpp:498
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
O3TypeList & types()
Definition: O3prm.cpp:487
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85
+ Here is the call graph for this function:

◆ resolveInterface()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveInterface ( O3Label name)

Definition at line 301 of file O3NameSolver_tpl.h.

References gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__errors, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__interfaceName, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__prm, gum::endsWith(), gum::HashTable< Key, Val, Alloc >::exists(), gum::Set< Key, Alloc >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), gum::prm::o3prm::O3PRM::interfaces(), gum::prm::o3prm::O3Label::label(), and gum::Set< Key, Alloc >::size().

301  {
302  // If empty string, we return an empty string
303  if (name.label() == "") { return true; }
304 
305  // If we've already found the interface real name
306  if (__interfaceName.exists(name.label())) {
307  name.label() = __interfaceName[name.label()];
308  return true;
309  }
310 
311  // If name exists as is
312  if (__prm->isInterface(name.label())) {
313  __interfaceName.insert(name.label(), name.label());
314  return true;
315  }
316 
317  for (auto& i : __o3_prm->interfaces()) {
318  if (i->name().label() == name.label()) {
319  __interfaceName.insert(name.label(), name.label());
320  return true;
321  }
322  }
323 
324  // If we didn't find it as is, then we must find a namespace
325  // in which it was declared
326  auto lookup = "." + name.label();
327  auto found = Set< std::string >();
328  auto matches = std::vector< std::string >();
329 
330  // Trying with interfaces
331  for (auto i : __prm->interfaces()) {
332  if (endsWith(i->name(), lookup)) {
333  if (!found.exists(i->name())) {
334  found.insert(i->name());
335  matches.push_back(i->name());
336  }
337  }
338  }
339 
340  // Trying with O3Interface
341  for (auto& i : __o3_prm->interfaces()) {
342  if (endsWith(i->name().label(), lookup)) {
343  if (!found.exists(i->name().label())) {
344  found.insert(i->name().label());
345  matches.push_back(i->name().label());
346  }
347  }
348  }
349 
350  if (matches.size() == 1) { // One match is good
351 
352  __interfaceName.insert(name.label(), matches.back());
353  name.label() = matches.back();
354  return true;
355 
356  } else if (matches.size() == 0) { // 0 match is not found
357 
358  // Unknown name type
359  O3PRM_INTERFACE_NOT_FOUND(name, *__errors);
360  return false;
361 
362  } else { // More than one match is ambiguous
363 
364  // Ambiguous name
365  O3PRM_INTERFACE_AMBIGUOUS(name, matches, *__errors);
366  return false;
367  }
368  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool endsWith(std::string const &value, std::string const &ending)
Returns true if value ends with ending.
O3InterfaceList & interfaces()
Definition: O3prm.cpp:498
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85
+ Here is the call graph for this function:

◆ resolveSlotType()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveSlotType ( O3Label name)

Definition at line 441 of file O3NameSolver_tpl.h.

References gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__className, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__errors, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__interfaceName, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__refName, gum::prm::o3prm::O3PRM::classes(), gum::endsWith(), gum::HashTable< Key, Val, Alloc >::exists(), gum::Set< Key, Alloc >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), gum::prm::o3prm::O3PRM::interfaces(), gum::prm::o3prm::O3Label::label(), and gum::Set< Key, Alloc >::size().

441  {
442  // If empty string, we return an empty string
443  if (name.label() == "") { return true; }
444  // If we've already found the reference real name
445  if (__refName.exists(name.label())) {
446  name.label() = __refName[name.label()];
447  return true;
448  }
449  // If name exists as is
450  if (__prm->isInterface(name.label()) || __prm->isClass(name.label())) {
451  __refName.insert(name.label(), name.label());
452  return true;
453  }
454 
455  // We check if it matches an O3Interface
456  for (auto& i : __o3_prm->interfaces()) {
457  if (i->name().label() == name.label()) {
458  __interfaceName.insert(name.label(), name.label());
459  return true;
460  }
461  }
462 
463  // We check if it matches an O3Class
464  for (auto& c : __o3_prm->classes()) {
465  if (c->name().label() == name.label()) {
466  __className.insert(name.label(), name.label());
467  return true;
468  }
469  }
470 
471  // If we didn't find it as is, then we must find a namespace
472  // in which it was declared
473  auto lookup = "." + name.label();
474  auto found = Set< std::string >();
475  auto matches = std::vector< std::string >();
476 
477  // Trying with interfaces
478  for (auto i : __prm->interfaces()) {
479  if (endsWith(i->name(), lookup)) {
480  if (!found.exists(i->name())) {
481  found.insert(i->name());
482  matches.push_back(i->name());
483  }
484  }
485  }
486 
487  // Trying with O3Interface
488  for (auto& i : __o3_prm->interfaces()) {
489  if (endsWith(i->name().label(), lookup)) {
490  if (!found.exists(i->name().label())) {
491  found.insert(i->name().label());
492  matches.push_back(i->name().label());
493  }
494  }
495  }
496 
497  // Try to complete with Class
498  for (auto c : __prm->classes()) {
499  if (endsWith(c->name(), lookup)) {
500  if (!found.exists(c->name())) {
501  found.insert(c->name());
502  matches.push_back(c->name());
503  }
504  }
505  }
506 
507  // Try to complete with O3Class
508  for (auto& c : __o3_prm->classes()) {
509  if (endsWith(c->name().label(), lookup)) {
510  if (!found.exists(c->name().label())) {
511  found.insert(c->name().label());
512  matches.push_back(c->name().label());
513  }
514  }
515  }
516 
517  if (matches.size() == 1) { // One match is good
518 
519  __refName.insert(name.label(), matches.back());
520  name.label() = matches.back();
521  return true;
522 
523  } else if (matches.size() == 0) { // 0 match is not found
524 
525  // Unknown name type
526  O3PRM_REFERENCE_NOT_FOUND(name, *__errors);
527  return false;
528 
529  } else { // More than one match is ambiguous
530 
531  // Ambiguous name
532  O3PRM_REFERENCE_AMBIGUOUS(name, matches, *__errors);
533  return false;
534  }
535  }
O3ClassList & classes()
Definition: O3prm.cpp:503
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool endsWith(std::string const &value, std::string const &ending)
Returns true if value ends with ending.
O3InterfaceList & interfaces()
Definition: O3prm.cpp:498
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85
+ Here is the call graph for this function:

◆ resolveType()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveType ( O3Label name)

Definition at line 231 of file O3NameSolver_tpl.h.

References gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__errors, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__prm, gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__typeName, gum::endsWith(), gum::HashTable< Key, Val, Alloc >::exists(), gum::Set< Key, Alloc >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), gum::prm::o3prm::O3Label::label(), gum::Set< Key, Alloc >::size(), and gum::prm::o3prm::O3PRM::types().

231  {
232  // If empty string, we return an empty string
233  if (name.label() == "") { return true; }
234 
235  // If we've already found the type real name
236  if (__typeName.exists(name.label())) {
237  name.label() = __typeName[name.label()];
238  return true;
239  }
240 
241  // If name exists as is in PRM
242  if (__prm->isType(name.label())) {
243  __typeName.insert(name.label(), name.label());
244  return true;
245  }
246 
247  // If name exists as is in O3PRM
248  for (auto& t : __o3_prm->types()) {
249  if (t->name().label() == name.label()) {
250  __typeName.insert(name.label(), name.label());
251  return true;
252  }
253  }
254 
255  // If we didn't find it as is, then we must find a namespace
256  // in which it was declared
257  auto lookup = "." + name.label();
258  auto found = Set< std::string >();
259  auto matches = std::vector< std::string >();
260 
261  // Trying with types
262  for (auto t : __prm->types()) {
263  if (endsWith(t->name(), lookup)) {
264  if (!found.exists(t->name())) {
265  found.insert(t->name());
266  matches.push_back(t->name());
267  }
268  }
269  }
270 
271  // Trying with O3Types
272  for (auto& t : __o3_prm->types()) {
273  if (endsWith(t->name().label(), lookup)) {
274  if (!found.exists(t->name().label())) {
275  found.insert(t->name().label());
276  matches.push_back(t->name().label());
277  }
278  }
279  }
280 
281  if (matches.size() == 1) { // One match is good
282  __typeName.insert(name.label(), matches.back());
283  name.label() = matches.back();
284  return true;
285 
286  } else if (matches.size() == 0) { // 0 match is not found
287 
288  // Unknown name type
289  O3PRM_TYPE_NOT_FOUND(name, *__errors);
290  return false;
291 
292  } else { // More than one match is ambiguous
293 
294  // Ambiguous name
295  O3PRM_TYPE_AMBIGUOUS(name, matches, *__errors);
296  return false;
297  }
298  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool endsWith(std::string const &value, std::string const &ending)
Returns true if value ends with ending.
ErrorsContainer * __errors
Definition: O3NameSolver.h:87
O3TypeList & types()
Definition: O3prm.cpp:487
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:85
+ Here is the call graph for this function:

Member Data Documentation

◆ __className

◆ __eltName

template<typename GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__eltName
private

◆ __errors

◆ __interfaceName

◆ __o3_prm

◆ __prm

◆ __refName

template<typename GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__refName
private

◆ __typeName

template<typename GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::__typeName
private

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