INET Framework for OMNeT++/OMNEST
inet::ModuleRefByPar< T > Class Template Reference

This template class implements a module reference that is parameterized by a string module parameter of the referencing module. More...

#include <ModuleRefByPar.h>

Public Member Functions

Toperator* () const
 
Toperator-> () const
 
 operator T* () const
 
 operator bool () const
 
TgetNullable ()
 
const TgetNullable () const
 
Tget ()
 
const Tget () const
 
void reference (cModule *referencingModule, const char *parameterName, bool mandatory)
 

Private Member Functions

void checkReference () const
 

Private Attributes

opp_component_ptr< TreferencedModule
 
cModule * referencingModule = nullptr
 
const char * parameterName = nullptr
 

Detailed Description

template<typename T>
class inet::ModuleRefByPar< T >

This template class implements a module reference that is parameterized by a string module parameter of the referencing module.

The reference can be set by providing the referencing module and the name of the module parameter. After the reference is set, it can be used similarly to a simple C++ pointer. The pointer is automatically set to nullptr when the referenced module is deleted.

TODO follow parameter change

Member Function Documentation

◆ checkReference()

template<typename T >
void inet::ModuleRefByPar< T >::checkReference ( ) const
inlineprivate
36  {
37 #ifndef NDEBUG
38  if (referencedModule.getNullable() == nullptr) {
39  if (referencingModule == nullptr)
40  throw cRuntimeError("Dereferencing uninitialized reference of type '%s'", opp_typename(typeid(T)));
41  else
42  throw cRuntimeError("Dereferencing nullptr of type '%s' referenced by module '(%s)%s' with a string module parameter '%s'",
43  opp_typename(typeid(T)), referencingModule->getClassName(), referencingModule->getFullPath().c_str(), parameterName);
44 
45  }
46 #else
47  if (referencedModule.getNullable() == nullptr)
48  throw cRuntimeError("Dereferencing nullptr of type '%s'", opp_typename(typeid(T)));
49 #endif
50  }

◆ get() [1/2]

template<typename T >
T* inet::ModuleRefByPar< T >::get ( )
inline
72 { checkReference(); return referencedModule.get(); }

◆ get() [2/2]

template<typename T >
const T* inet::ModuleRefByPar< T >::get ( ) const
inline
73 { checkReference(); return referencedModule.get(); }

◆ getNullable() [1/2]

template<typename T >
T* inet::ModuleRefByPar< T >::getNullable ( )
inline
69 { return referencedModule.getNullable(); }

◆ getNullable() [2/2]

template<typename T >
const T* inet::ModuleRefByPar< T >::getNullable ( ) const
inline
70 { return referencedModule.getNullable(); }

◆ operator bool()

template<typename T >
inet::ModuleRefByPar< T >::operator bool ( ) const
inlineexplicit
67 { return (bool)referencedModule; }

◆ operator T*()

template<typename T >
inet::ModuleRefByPar< T >::operator T* ( ) const
inline
63  {
64  return referencedModule;
65  }

◆ operator*()

template<typename T >
T& inet::ModuleRefByPar< T >::operator* ( ) const
inline
53  {
55  return *referencedModule;
56  }

◆ operator->()

template<typename T >
T* inet::ModuleRefByPar< T >::operator-> ( ) const
inline
58  {
60  return referencedModule;
61  }

◆ reference()

template<typename T >
void inet::ModuleRefByPar< T >::reference ( cModule *  referencingModule,
const char *  parameterName,
bool  mandatory 
)
inline
75  {
76  if (referencingModule == nullptr)
77  throw cRuntimeError("Referencing module is nullptr");
78  if (parameterName == nullptr)
79  throw cRuntimeError("Parameter name is nullptr");
80 #ifndef NDEBUG
81  if (this->referencingModule != nullptr)
82  throw cRuntimeError("Reference is already initialized");
85 #endif
86  auto& parameter = referencingModule->par(parameterName);
87  referencedModule = mandatory ? getModuleFromPar<T>(parameter, referencingModule) : findModuleFromPar<T>(parameter, referencingModule);
88  }

Member Data Documentation

◆ parameterName

template<typename T >
const char* inet::ModuleRefByPar< T >::parameterName = nullptr
private

◆ referencedModule

template<typename T >
opp_component_ptr<T> inet::ModuleRefByPar< T >::referencedModule
private

◆ referencingModule

template<typename T >
cModule* inet::ModuleRefByPar< T >::referencingModule = nullptr
private

The documentation for this class was generated from the following file:
inet::units::units::T
compose< Wb, pow< m, -2 > > T
Definition: Units.h:951
inet::ModuleRefByPar::parameterName
const char * parameterName
Definition: ModuleRefByPar.h:33
inet::ModuleRefByPar::checkReference
void checkReference() const
Definition: ModuleRefByPar.h:36
inet::ModuleRefByPar::referencedModule
opp_component_ptr< T > referencedModule
Definition: ModuleRefByPar.h:29
inet::ModuleRefByPar::referencingModule
cModule * referencingModule
Definition: ModuleRefByPar.h:32
inet::findModuleFromPar
T * findModuleFromPar(cPar &par, const cModule *from)
Finds a module in the module tree, given by its absolute or relative path defined by 'par' parameter.
Definition: ModuleAccess.h:55