Skip to content

Commit b311f99

Browse files
committed
common: Added iterate NED function that generates elements from an array sequentially.
This can be used in a packet source packetInterval parameter, for example, to generate packets according to a specific schedule.
1 parent ff4fb88 commit b311f99

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/inet/common/NedFunctions.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ Define_NED_Function2(nedf_seq,
330330
"Returns the next integer (starting from 0) associated to the first argument which must be a string."
331331
);
332332

333+
cNEDValue nedf_iterate(cComponent *context, cNEDValue argv[], int argc)
334+
{
335+
static int handle = cSimulationOrSharedDataManager::registerSharedVariableName("inet::NedFunctions::iterate");
336+
auto& seqs = getSimulationOrSharedDataManager()->getSharedVariable<std::map<std::string, int>>(handle);
337+
auto key = context->getFullPath();
338+
auto it = seqs.find(key);
339+
if (it == seqs.end())
340+
seqs[key] = 0;
341+
else
342+
seqs[key]++;
343+
auto array = check_and_cast<cValueArray *>(argv[0].objectValue());
344+
return array->get(seqs[key]);
345+
}
346+
347+
Define_NED_Function2(nedf_iterate,
348+
"any iterate(any array)",
349+
"misc",
350+
"Returns the next number (starting from the front of the array) each time the expression is evaluated. The index is stored as associated to the full path of the context component."
351+
);
352+
333353
} // namespace utils
334354

335355
} // namespace inet

0 commit comments

Comments
 (0)