aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
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 >:
[legend]

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)

Private Types

using NameMap = HashTable< std::string, std::string >

Private Attributes

PRM< GUM_SCALAR > * _prm_
O3PRM * _o3_prm_
ErrorsContainer * _errors_
NameMap _typeName_
NameMap _eltName_
NameMap _refName_
NameMap _interfaceName_
NameMap _className_

Detailed Description

template<GUM_Numeric 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 75 of file O3NameSolver.h.

Member Typedef Documentation

◆ NameMap

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

Definition at line 104 of file O3NameSolver.h.

Constructor & Destructor Documentation

◆ O3NameSolver() [1/3]

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

Definition at line 59 of file O3NameSolver_tpl.h.

61 :
64 }
Resolves names for the different O3PRM factories.
O3NameSolver(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, ErrorsContainer &errors)
PRM< GUM_SCALAR > * _prm_

References O3NameSolver(), _errors_, _o3_prm_, and _prm_.

Referenced by O3NameSolver(), O3NameSolver(), O3NameSolver(), ~O3NameSolver(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::_readStream_(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ O3NameSolver() [2/3]

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

Definition at line 67 of file O3NameSolver_tpl.h.

References O3NameSolver(), _className_, _eltName_, _errors_, _interfaceName_, _o3_prm_, _prm_, _refName_, and _typeName_.

Here is the call graph for this function:

◆ O3NameSolver() [3/3]

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

Definition at line 75 of file O3NameSolver_tpl.h.

References O3NameSolver(), _className_, _eltName_, _errors_, _interfaceName_, _o3_prm_, _prm_, _refName_, and _typeName_.

Here is the call graph for this function:

◆ ~O3NameSolver()

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

Definition at line 84 of file O3NameSolver_tpl.h.

84 {
86 }

References O3NameSolver().

Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

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

Definition at line 90 of file O3NameSolver_tpl.h.

90 {
91 if (this == &src) { return *this; }
92 _prm_ = src._prm_;
100 return *this;
101 }

References O3NameSolver(), _className_, _eltName_, _errors_, _interfaceName_, _o3_prm_, _prm_, _refName_, and _typeName_.

Here is the call graph for this function:

◆ operator=() [2/2]

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

Definition at line 105 of file O3NameSolver_tpl.h.

References O3NameSolver(), _className_, _eltName_, _errors_, _interfaceName_, _o3_prm_, _prm_, _refName_, and _typeName_.

Here is the call graph for this function:

◆ resolveClass()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClass ( O3Label & name)

Definition at line 385 of file O3NameSolver_tpl.h.

385 {
386 // If empty string, we return an empty string
387 if (name.label().empty()) { return true; }
388
389 // If we've already found super real name
390 if (_className_.exists(name.label())) {
391 name.label() = _className_[name.label()];
392 return true;
393 }
394
395 // If class name exists as is
396 if (_prm_->isClass(name.label())) {
397 _className_.insert(name.label(), name.label());
398 return true;
399 }
400
401 for (auto& c: _o3_prm_->classes()) {
402 if (c->name().label() == name.label()) {
403 _className_.insert(name.label(), name.label());
404 return true;
405 }
406 }
407
408 // If we didn't find it as is, then we must find a namespace
409 // in which it was declared
410 auto lookup = "." + name.label();
412 auto found = Set< std::string >();
413
414 // Try to complete with Class
415 for (auto c: _prm_->classes()) {
416 if (endsWith(c->name(), lookup)) {
417 if (!found.exists(c->name())) {
418 found.insert(c->name());
419 matches.push_back(c->name());
420 }
421 }
422 }
423
424 // Try to complete with O3Class
425 for (auto& c: _o3_prm_->classes()) {
426 if (endsWith(c->name().label(), lookup)) {
427 if (!found.exists(c->name().label())) {
428 found.insert(c->name().label());
429 matches.push_back(c->name().label());
430 }
431 }
432 }
433
434 if (matches.size() == 1) { // One match is good
435
436 _className_.insert(name.label(), matches.back());
437 name.label() = matches.back();
438 return true;
439
440 } else if (matches.size() == 0) { // 0 match is not found
441
442 // Unknown super class
444 return false;
445
446 } else { // More than one match is ambiguous
447
448 // Ambiguous name
450 return false;
451 }
452 }

References _className_, _errors_, _o3_prm_, _prm_, gum::endsWith(), and gum::prm::o3prm::O3Label::label().

Here is the call graph for this function:

◆ resolveClassElement()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveClassElement ( O3Label & name)

Definition at line 119 of file O3NameSolver_tpl.h.

119 {
120 // If empty string, we return an empty string
121 if (name.label().empty()) { return true; }
122 // If we've already found the element real name
123 if (_eltName_.exists(name.label())) {
124 name.label() = _eltName_[name.label()];
125 return true;
126 }
127 // If name exists as is
128 if (_prm_->isType(name.label())) {
129 _eltName_.insert(name.label(), name.label());
130 return true;
131 }
132 // If name exists as is
133 if (_prm_->isInterface(name.label())) {
134 _eltName_.insert(name.label(), name.label());
135 return true;
136 }
137 // If name exists as is
138 if (_prm_->isClass(name.label())) {
139 _eltName_.insert(name.label(), name.label());
140 return true;
141 }
142 // If name exists as is in O3PRM types
143 for (auto& t: _o3_prm_->types()) {
144 if (t->name().label() == name.label()) {
145 _eltName_.insert(name.label(), name.label());
146 return true;
147 }
148 }
149 // If name exists as is in O3PRM interfaces
150 for (auto& i: _o3_prm_->interfaces()) {
151 if (i->name().label() == name.label()) {
152 _eltName_.insert(name.label(), name.label());
153 return true;
154 }
155 }
156 // If name exists as is in O3PRM classes
157 for (auto& c: _o3_prm_->classes()) {
158 if (c->name().label() == name.label()) {
159 _eltName_.insert(name.label(), name.label());
160 return true;
161 }
162 }
163
164 auto lookup = "." + name.label();
165 auto found = Set< std::string >();
167
168 // Trying with types
169 for (auto t: _prm_->types()) {
170 if (endsWith(t->name(), lookup)) {
171 if (!found.exists(t->name())) {
172 found.insert(t->name());
173 matches.push_back(t->name());
174 }
175 }
176 }
177 // Trying with O3Types
178 for (auto& t: _o3_prm_->types()) {
179 if (endsWith(t->name().label(), lookup)) {
180 if (!found.exists(t->name().label())) {
181 found.insert(t->name().label());
182 matches.push_back(t->name().label());
183 }
184 }
185 }
186
187 // Trying with interfaces
188 for (auto i: _prm_->interfaces()) {
189 if (endsWith(i->name(), lookup)) {
190 if (!found.exists(i->name())) {
191 found.insert(i->name());
192 matches.push_back(i->name());
193 }
194 }
195 }
196 // Trying with O3Interface
197 for (auto& i: _o3_prm_->interfaces()) {
198 if (endsWith(i->name().label(), lookup)) {
199 if (!found.exists(i->name().label())) {
200 found.insert(i->name().label());
201 matches.push_back(i->name().label());
202 }
203 }
204 }
205
206 // Trying with class
207 for (auto c: _prm_->classes()) {
208 if (endsWith(c->name(), lookup)) {
209 if (!found.exists(c->name())) {
210 found.insert(c->name());
211 matches.push_back(c->name());
212 }
213 }
214 }
215 // Trying with O3Class
216 for (auto& c: _o3_prm_->classes()) {
217 if (endsWith(c->name().label(), lookup)) {
218 if (!found.exists(c->name().label())) {
219 found.insert(c->name().label());
220 matches.push_back(c->name().label());
221 }
222 }
223 }
224
225 if (matches.size() == 1) { // One match is good
226 _eltName_.insert(name.label(), matches.back());
227 name.label() = matches.back();
228 return true;
229
230 } else if (matches.size() == 0) { // 0 match is not found
231
232 // Unknown name type
234 return false;
235
236 } else { // More than one match is ambiguous
237
238 // Ambiguous name
240 return false;
241 }
242 }

References _eltName_, _errors_, _o3_prm_, _prm_, gum::endsWith(), and gum::prm::o3prm::O3Label::label().

Here is the call graph for this function:

◆ resolveInterface()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveInterface ( O3Label & name)

Definition at line 315 of file O3NameSolver_tpl.h.

315 {
316 // If empty string, we return an empty string
317 if (name.label().empty()) { return true; }
318
319 // If we've already found the interface real name
320 if (_interfaceName_.exists(name.label())) {
321 name.label() = _interfaceName_[name.label()];
322 return true;
323 }
324
325 // If name exists as is
326 if (_prm_->isInterface(name.label())) {
327 _interfaceName_.insert(name.label(), name.label());
328 return true;
329 }
330
331 for (auto& i: _o3_prm_->interfaces()) {
332 if (i->name().label() == name.label()) {
333 _interfaceName_.insert(name.label(), name.label());
334 return true;
335 }
336 }
337
338 // If we didn't find it as is, then we must find a namespace
339 // in which it was declared
340 auto lookup = "." + name.label();
341 auto found = Set< std::string >();
343
344 // Trying with interfaces
345 for (auto i: _prm_->interfaces()) {
346 if (endsWith(i->name(), lookup)) {
347 if (!found.exists(i->name())) {
348 found.insert(i->name());
349 matches.push_back(i->name());
350 }
351 }
352 }
353
354 // Trying with O3Interface
355 for (auto& i: _o3_prm_->interfaces()) {
356 if (endsWith(i->name().label(), lookup)) {
357 if (!found.exists(i->name().label())) {
358 found.insert(i->name().label());
359 matches.push_back(i->name().label());
360 }
361 }
362 }
363
364 if (matches.size() == 1) { // One match is good
365
366 _interfaceName_.insert(name.label(), matches.back());
367 name.label() = matches.back();
368 return true;
369
370 } else if (matches.size() == 0) { // 0 match is not found
371
372 // Unknown name type
374 return false;
375
376 } else { // More than one match is ambiguous
377
378 // Ambiguous name
380 return false;
381 }
382 }

References _errors_, _interfaceName_, _o3_prm_, _prm_, gum::endsWith(), and gum::prm::o3prm::O3Label::label().

Here is the call graph for this function:

◆ resolveSlotType()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveSlotType ( O3Label & name)

Definition at line 455 of file O3NameSolver_tpl.h.

455 {
456 // If empty string, we return an empty string
457 if (name.label().empty()) { return true; }
458 // If we've already found the reference real name
459 if (_refName_.exists(name.label())) {
460 name.label() = _refName_[name.label()];
461 return true;
462 }
463 // If name exists as is
464 if (_prm_->isInterface(name.label()) || _prm_->isClass(name.label())) {
465 _refName_.insert(name.label(), name.label());
466 return true;
467 }
468
469 // We check if it matches an O3Interface
470 for (auto& i: _o3_prm_->interfaces()) {
471 if (i->name().label() == name.label()) {
472 _interfaceName_.insert(name.label(), name.label());
473 return true;
474 }
475 }
476
477 // We check if it matches an O3Class
478 for (auto& c: _o3_prm_->classes()) {
479 if (c->name().label() == name.label()) {
480 _className_.insert(name.label(), name.label());
481 return true;
482 }
483 }
484
485 // If we didn't find it as is, then we must find a namespace
486 // in which it was declared
487 auto lookup = "." + name.label();
488 auto found = Set< std::string >();
490
491 // Trying with interfaces
492 for (auto i: _prm_->interfaces()) {
493 if (endsWith(i->name(), lookup)) {
494 if (!found.exists(i->name())) {
495 found.insert(i->name());
496 matches.push_back(i->name());
497 }
498 }
499 }
500
501 // Trying with O3Interface
502 for (auto& i: _o3_prm_->interfaces()) {
503 if (endsWith(i->name().label(), lookup)) {
504 if (!found.exists(i->name().label())) {
505 found.insert(i->name().label());
506 matches.push_back(i->name().label());
507 }
508 }
509 }
510
511 // Try to complete with Class
512 for (auto c: _prm_->classes()) {
513 if (endsWith(c->name(), lookup)) {
514 if (!found.exists(c->name())) {
515 found.insert(c->name());
516 matches.push_back(c->name());
517 }
518 }
519 }
520
521 // Try to complete with O3Class
522 for (auto& c: _o3_prm_->classes()) {
523 if (endsWith(c->name().label(), lookup)) {
524 if (!found.exists(c->name().label())) {
525 found.insert(c->name().label());
526 matches.push_back(c->name().label());
527 }
528 }
529 }
530
531 if (matches.size() == 1) { // One match is good
532
533 _refName_.insert(name.label(), matches.back());
534 name.label() = matches.back();
535 return true;
536
537 } else if (matches.size() == 0) { // 0 match is not found
538
539 // Unknown name type
541 return false;
542
543 } else { // More than one match is ambiguous
544
545 // Ambiguous name
547 return false;
548 }
549 }

References _className_, _errors_, _interfaceName_, _o3_prm_, _prm_, _refName_, gum::endsWith(), and gum::prm::o3prm::O3Label::label().

Here is the call graph for this function:

◆ resolveType()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::resolveType ( O3Label & name)

Definition at line 245 of file O3NameSolver_tpl.h.

245 {
246 // If empty string, we return an empty string
247 if (name.label().empty()) { return true; }
248
249 // If we've already found the type real name
250 if (_typeName_.exists(name.label())) {
251 name.label() = _typeName_[name.label()];
252 return true;
253 }
254
255 // If name exists as is in PRM
256 if (_prm_->isType(name.label())) {
257 _typeName_.insert(name.label(), name.label());
258 return true;
259 }
260
261 // If name exists as is in O3PRM
262 for (auto& t: _o3_prm_->types()) {
263 if (t->name().label() == name.label()) {
264 _typeName_.insert(name.label(), name.label());
265 return true;
266 }
267 }
268
269 // If we didn't find it as is, then we must find a namespace
270 // in which it was declared
271 auto lookup = "." + name.label();
272 auto found = Set< std::string >();
274
275 // Trying with types
276 for (auto t: _prm_->types()) {
277 if (endsWith(t->name(), lookup)) {
278 if (!found.exists(t->name())) {
279 found.insert(t->name());
280 matches.push_back(t->name());
281 }
282 }
283 }
284
285 // Trying with O3Types
286 for (auto& t: _o3_prm_->types()) {
287 if (endsWith(t->name().label(), lookup)) {
288 if (!found.exists(t->name().label())) {
289 found.insert(t->name().label());
290 matches.push_back(t->name().label());
291 }
292 }
293 }
294
295 if (matches.size() == 1) { // One match is good
296 _typeName_.insert(name.label(), matches.back());
297 name.label() = matches.back();
298 return true;
299
300 } else if (matches.size() == 0) { // 0 match is not found
301
302 // Unknown name type
304 return false;
305
306 } else { // More than one match is ambiguous
307
308 // Ambiguous name
310 return false;
311 }
312 }

References _errors_, _o3_prm_, _prm_, _typeName_, gum::endsWith(), and gum::prm::o3prm::O3Label::label().

Here is the call graph for this function:

Member Data Documentation

◆ _className_

template<GUM_Numeric GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::_className_
private

◆ _eltName_

template<GUM_Numeric GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::_eltName_
private

Definition at line 107 of file O3NameSolver.h.

Referenced by O3NameSolver(), O3NameSolver(), operator=(), operator=(), and resolveClassElement().

◆ _errors_

◆ _interfaceName_

template<GUM_Numeric GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::_interfaceName_
private

◆ _o3_prm_

template<GUM_Numeric GUM_SCALAR>
O3PRM* gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::_o3_prm_
private

◆ _prm_

template<GUM_Numeric GUM_SCALAR>
PRM< GUM_SCALAR >* gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::_prm_
private

◆ _refName_

template<GUM_Numeric GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::_refName_
private

Definition at line 108 of file O3NameSolver.h.

Referenced by O3NameSolver(), O3NameSolver(), operator=(), operator=(), and resolveSlotType().

◆ _typeName_

template<GUM_Numeric GUM_SCALAR>
NameMap gum::prm::o3prm::O3NameSolver< GUM_SCALAR >::_typeName_
private

Definition at line 106 of file O3NameSolver.h.

Referenced by O3NameSolver(), O3NameSolver(), operator=(), operator=(), and resolveType().


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