OMNeT++ API 6.1
Discrete Event Simulation Library
cModule::SubmoduleIterator Class Reference

Description

Iterates through the submodules of a compound module. Iteration order corresponds to declaration order in NED files.

It is not allowed to delete or insert modules during iteration. If such thing occurs, restart the iteration by calling reset(), or query the submodule list in advance.

Usage:

for (cModule::SubmoduleIterator it(module); !it.end(); ++it) {
cModule *submodule = *it;
...
}

When submodules may be created in the loop body:

for (cModule::SubmoduleIterator it(module); !it.end();) {
cModule *submodule = *it;
...
... (code that may create/delete/move submodules)
...
if (!it.changesDetected())
it++;
else
it.reset(); // start over
}

Public Member Functions

 SubmoduleIterator (const cModule *module)
 
void reset ()
 
cModuleoperator* () const
 
bool end () const
 
SubmoduleIteratoroperator++ ()
 
SubmoduleIterator operator++ (int)
 
bool changesDetected () const
 

Constructor & Destructor Documentation

◆ SubmoduleIterator()

SubmoduleIterator ( const cModule module)
inline

Constructor. It takes the parent module on which to iterate.

Member Function Documentation

◆ reset()

void reset ( )

Reinitializes the iterator.

◆ operator*()

cModule* operator* ( ) const
inline

Returns a pointer to the current module. Returns nullptr if the iterator has reached the end of the list.

◆ end()

bool end ( ) const
inline

Returns true if the iterator reached the end of the list.

◆ operator++() [1/2]

SubmoduleIterator& operator++ ( )
inline

Prefix increment operator (++it). Moves the iterator to the next submodule. It has no effect if the iterator has reached either end of the list.

◆ operator++() [2/2]

SubmoduleIterator operator++ ( int  )
inline

Postfix increment operator (it++). Moves the iterator to the next submodule, and returns the iterator's previous state. It has no effect if the iterator has reached either end of the list.

◆ changesDetected()

bool changesDetected ( ) const

Returns true if it was detected that the list of submodules has changed since the the start of the iteration due to insertion, removal, or possibly as a byproduct of name/index change. When this method returns true, incrementing the iterator will result in an exception being thrown. One possible solution for when changesDetected() returns true is starting over the iteration (see reset()).


The documentation for this class was generated from the following file:
omnetpp::cModule::cModule
cModule()