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

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

#include <ModuleRef.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)
 
void reference (cGate *gate, bool mandatory)
 

Private Member Functions

void checkReference () const
 

Private Attributes

opp_component_ptr< TreferencedModule
 

Detailed Description

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

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

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

TODO follow connection

Member Function Documentation

◆ checkReference()

template<typename T >
void inet::ModuleRef< T >::checkReference ( ) const
inlineprivate
30  {
31  if (referencedModule.getNullable() == nullptr)
32  throw cRuntimeError("Dereferencing uninitialized reference of type '%s'", opp_typename(typeid(T)));
33  }

◆ get() [1/2]

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

◆ get() [2/2]

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

◆ getNullable() [1/2]

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

◆ getNullable() [2/2]

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

◆ operator bool()

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

◆ operator T*()

template<typename T >
inet::ModuleRef< T >::operator T* ( ) const
inline
46  {
47  return referencedModule;
48  }

◆ operator*()

template<typename T >
T& inet::ModuleRef< T >::operator* ( ) const
inline
36  {
38  return *referencedModule;
39  }

◆ operator->()

template<typename T >
T* inet::ModuleRef< T >::operator-> ( ) const
inline
41  {
43  return referencedModule;
44  }

◆ reference() [1/2]

template<typename T >
void inet::ModuleRef< T >::reference ( cGate *  gate,
bool  mandatory 
)
inline
67  {
68  if (gate == nullptr)
69  throw cRuntimeError("Gate is nullptr");
70  referencedModule = mandatory ? getConnectedModule<T>(gate) : findConnectedModule<T>(gate);
71  }

◆ reference() [2/2]

template<typename T >
void inet::ModuleRef< T >::reference ( cModule *  referencingModule,
const char *  parameterName,
bool  mandatory 
)
inline
58  {
59  if (referencingModule == nullptr)
60  throw cRuntimeError("Referencing module is nullptr");
61  if (parameterName == nullptr)
62  throw cRuntimeError("Parameter name is nullptr");
63  auto& parameter = referencingModule->par(parameterName);
64  referencedModule = mandatory ? getModuleFromPar<T>(parameter, referencingModule) : findModuleFromPar<T>(parameter, referencingModule);
65  }

Member Data Documentation

◆ referencedModule

template<typename T >
opp_component_ptr<T> inet::ModuleRef< T >::referencedModule
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::ModuleRef::referencedModule
opp_component_ptr< T > referencedModule
Definition: ModuleRef.h:28
inet::ModuleRef::checkReference
void checkReference() const
Definition: ModuleRef.h:30
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
inet::findConnectedModule
T * findConnectedModule(cGate *gate, int direction=0)
Returns a module of type T that is on the path starting at the given gate.
Definition: ModuleAccess.h:138