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

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

#include <ModuleRefByGate.h>

Public Member Functions

Toperator* () const
 
Toperator-> () const
 
 operator T* () const
 
 operator bool () const
 
TgetNullable ()
 
const TgetNullable () const
 
Tget ()
 
const Tget () const
 
cGate * getGate ()
 
const cGate * getGate () const
 
void reference (cGate *gate, bool mandatory)
 

Private Member Functions

void checkReference () const
 

Private Attributes

opp_component_ptr< TreferencedModule
 
cGate * gate = nullptr
 

Detailed Description

template<typename T>
class inet::ModuleRefByGate< 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::ModuleRefByGate< T >::checkReference ( ) const
inlineprivate
31  {
32  if (referencedModule.getNullable() == nullptr) {
33  if (gate == nullptr)
34  throw cRuntimeError("Dereferencing uninitialized reference of type '%s'", opp_typename(typeid(T)));
35  else
36  throw cRuntimeError("Dereferencing nullptr of type '%s' referenced by '(%s)%s' through gate '%s'",
37  opp_typename(typeid(T)), gate->getOwnerModule()->getClassName(), gate->getOwnerModule()->getFullPath().c_str(), gate->getFullName());
38  }
39  }

◆ get() [1/2]

template<typename T >
T* inet::ModuleRefByGate< T >::get ( )
inline
61 { checkReference(); return get(); }

Referenced by inet::ModuleRefByGate< T >::get().

◆ get() [2/2]

template<typename T >
const T* inet::ModuleRefByGate< T >::get ( ) const
inline
62 { checkReference(); return get(); }

Referenced by inet::ModuleRefByGate< T >::get().

◆ getGate() [1/2]

template<typename T >
cGate* inet::ModuleRefByGate< T >::getGate ( )
inline
64 { return gate; }

◆ getGate() [2/2]

template<typename T >
const cGate* inet::ModuleRefByGate< T >::getGate ( ) const
inline
65 { return gate; }

◆ getNullable() [1/2]

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

◆ getNullable() [2/2]

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

◆ operator bool()

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

◆ operator T*()

template<typename T >
inet::ModuleRefByGate< T >::operator T* ( ) const
inline
52  {
53  return referencedModule;
54  }

◆ operator*()

template<typename T >
T& inet::ModuleRefByGate< T >::operator* ( ) const
inline
42  {
44  return *referencedModule;
45  }

◆ operator->()

template<typename T >
T* inet::ModuleRefByGate< T >::operator-> ( ) const
inline
47  {
49  return referencedModule;
50  }

◆ reference()

template<typename T >
void inet::ModuleRefByGate< T >::reference ( cGate *  gate,
bool  mandatory 
)
inline
67  {
68  if (gate == nullptr)
69  throw cRuntimeError("Gate is nullptr");
70  if (this->gate != nullptr)
71  throw cRuntimeError("Reference is already initialized");
72  this->gate = gate;
73  referencedModule = mandatory ? getConnectedModule<T>(gate) : findConnectedModule<T>(gate);
74  }

Member Data Documentation

◆ gate

template<typename T >
cGate* inet::ModuleRefByGate< T >::gate = nullptr
private

◆ referencedModule

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

The documentation for this class was generated from the following file:
inet::ModuleRefByGate::gate
cGate * gate
Definition: ModuleRefByGate.h:29
inet::units::units::T
compose< Wb, pow< m, -2 > > T
Definition: Units.h:951
inet::ModuleRefByGate::referencedModule
opp_component_ptr< T > referencedModule
Definition: ModuleRefByGate.h:28
inet::ModuleRefByGate::get
T * get()
Definition: ModuleRefByGate.h:61
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
inet::ModuleRefByGate::checkReference
void checkReference() const
Definition: ModuleRefByGate.h:31