aGrUM  0.13.2
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 55 of file O3NameSolver.h.

Member Typedef Documentation

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

Definition at line 87 of file O3NameSolver.h.

Constructor & Destructor Documentation

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

Definition at line 36 of file O3NameSolver_tpl.h.

38  :
39  __prm(&prm),
40  __o3_prm(&o3_prm), __errors(&errors) {
41  GUM_CONSTRUCTOR(O3NameSolver);
42  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
ErrorsContainer * __errors
Definition: O3NameSolver.h:85
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:83
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::O3NameSolver ( const O3NameSolver< GUM_SCALAR > &  src)

Definition at line 45 of file O3NameSolver_tpl.h.

46  :
47  __prm(src.__prm),
48  __o3_prm(src.__o3_prm), __errors(src.__errors),
49  __typeName(src.__typeName), __eltName(src.__eltName),
50  __refName(src.__refName), __interfaceName(src.__interfaceName),
51  __className(src.__className) {
52  GUM_CONS_CPY(O3NameSolver);
53  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
ErrorsContainer * __errors
Definition: O3NameSolver.h:85
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:83
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::O3NameSolver ( O3NameSolver< GUM_SCALAR > &&  src)

Definition at line 56 of file O3NameSolver_tpl.h.

57  :
58  __prm(std::move(src.__prm)),
59  __o3_prm(std::move(src.__o3_prm)), __errors(std::move(src.__errors)),
60  __typeName(std::move(src.__typeName)),
61  __eltName(std::move(src.__eltName)), __refName(std::move(src.__refName)),
62  __interfaceName(std::move(src.__interfaceName)),
63  __className(std::move(src.__className)) {
64  GUM_CONS_MOV(O3NameSolver);
65  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
ErrorsContainer * __errors
Definition: O3NameSolver.h:85
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:83
template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::~O3NameSolver ( )

Definition at line 68 of file O3NameSolver_tpl.h.

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

68  {
69  GUM_DESTRUCTOR(O3NameSolver);
70  }
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)

+ Here is the call graph for this function:

Member Function Documentation

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

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

74  {
75  if (this == &src) { return *this; }
76  __prm = src.__prm;
77  __o3_prm = src.__o3_prm;
78  __errors = src.__errors;
79  __typeName = src.__typeName;
80  __eltName = src.__eltName;
81  __refName = src.__refName;
82  __interfaceName = src.__interfaceName;
83  __className = src.__className;
84  return *this;
85  }
ErrorsContainer * __errors
Definition: O3NameSolver.h:85
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:83

+ Here is the caller graph for this function:

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

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

89  {
90  if (this == &src) { return *this; }
91  __prm = std::move(src.__prm);
92  __o3_prm = std::move(src.__o3_prm);
93  __errors = std::move(src.__errors);
94  __typeName = std::move(src.__typeName);
95  __eltName = std::move(src.__eltName);
96  __refName = std::move(src.__refName);
97  __interfaceName = std::move(src.__interfaceName);
98  __className = std::move(src.__className);
99  return *this;
100  }
ErrorsContainer * __errors
Definition: O3NameSolver.h:85
PRM< GUM_SCALAR > * __prm
Definition: O3NameSolver.h:83
template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClass ( O3Label name)

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

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

+ Here is the call graph for this function:

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

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

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

+ Here is the call graph for this function:

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

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

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

+ Here is the call graph for this function:

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

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

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

+ Here is the call graph for this function:

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

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

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

+ Here is the call graph for this function:

Member Data Documentation

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

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