INET Framework for OMNeT++/OMNEST
inet::physicallayer::SimpleConstMappingIterator Class Reference

A fully working ConstIterator-implementation usable with almost every ConstMapping. More...

#include <MappingBase.h>

Inheritance diagram for inet::physicallayer::SimpleConstMappingIterator:
inet::physicallayer::ConstMappingIterator

Public Member Functions

 SimpleConstMappingIterator (const ConstMapping *mapping, const SimpleConstMappingIterator::KeyEntrySet *keyEntries, const Argument &start)
 Initializes the ConstIterator for the passed ConstMapping, with the passed key entries to iterate over and the passed position as start. More...
 
 SimpleConstMappingIterator (const ConstMapping *mapping, const SimpleConstMappingIterator::KeyEntrySet *keyEntries)
 Initializes the ConstIterator for the passed ConstMapping, with the passed key entries to iterate over. More...
 
virtual const ArgumentgetNextPosition () const override
 Returns the next position a call to "next()" would iterate to. More...
 
virtual void jumpTo (const Argument &pos) override
 Lets the iterator point to the passed position. More...
 
virtual void jumpToBegin () override
 Lets the iterator point to the first "position of interest" of the underlying mapping. More...
 
virtual void iterateTo (const Argument &pos) override
 Increases the position of the iterator to the passed position. More...
 
virtual void next () override
 Iterates to the next "point of interest" of the Mapping. More...
 
virtual bool inRange () const override
 Returns true if the current position of the iterator is equal or bigger than the first point of interest and lower or equal than the last point of interest. More...
 
virtual bool hasNext () const override
 Returns true if there is a next position a call to "next()" can iterate to. More...
 
virtual const ArgumentgetPosition () const override
 Returns the current position of the iterator. More...
 
virtual argument_value_t getValue () const override
 Returns the value of the underlying mapping at the current position of the iterator. More...
 
- Public Member Functions inherited from inet::physicallayer::ConstMappingIterator
 ConstMappingIterator ()
 
virtual ~ConstMappingIterator ()
 
 ConstMappingIterator (const ConstMappingIterator &)
 Copy constructor. More...
 
ConstMappingIteratoroperator= (const ConstMappingIterator &)
 ConstMappingIterator assignment operator. More...
 
void swap (ConstMappingIterator &)
 Swaps data with another ConstMappingIterator. More...
 

Protected Types

typedef std::set< ArgumentKeyEntrySet
 Type for a set of Arguments defining key entries. More...
 
typedef KeyEntrySet::value_type KeyEntryType
 Type of a key entries item. More...
 

Protected Attributes

const ConstMapping *const mapping
 The underlying ConstMapping to iterate over. More...
 
const DimensionSetdimensions
 The dimensions of the underlying ConstMapping. More...
 
KeyEntryType position
 The current position of the iterator. More...
 
const KeyEntrySetkeyEntries
 A pointer to a set of Arguments defining the positions to iterate over. More...
 
KeyEntrySet::const_iterator nextEntry
 An iterator over the key entry set which defines the next bigger entry of the current position. More...
 

Private Member Functions

 SimpleConstMappingIterator (const SimpleConstMappingIterator &)
 Copy constructor is not allowed. More...
 
SimpleConstMappingIteratoroperator= (const SimpleConstMappingIterator &)
 Assignment operator is not allowed. More...
 

Additional Inherited Members

- Public Types inherited from inet::physicallayer::ConstMappingIterator
typedef Argument::mapped_type argument_value_t
 
typedef Argument::mapped_type_cref argument_value_cref_t
 

Detailed Description

A fully working ConstIterator-implementation usable with almost every ConstMapping.

Although this ConstIterator would work with almost any ConstMapping it should only be used for ConstMappings whose "getValue()"-method has constant complexity. This is because the iterator just calls the "getValue()"-method of the underlying ConstMapping on every call of its own "getValue()"-method.

The underlying ConstMapping has to provide a set of key-entries (Arguments) to the iterator to tell it the positions it should iterate over.

Author
Karl Wessel

Member Typedef Documentation

Type for a set of Arguments defining key entries.

typedef KeyEntrySet::value_type inet::physicallayer::SimpleConstMappingIterator::KeyEntryType
protected

Type of a key entries item.

Constructor & Destructor Documentation

inet::physicallayer::SimpleConstMappingIterator::SimpleConstMappingIterator ( const SimpleConstMappingIterator )
private

Copy constructor is not allowed.

inet::physicallayer::SimpleConstMappingIterator::SimpleConstMappingIterator ( const ConstMapping mapping,
const SimpleConstMappingIterator::KeyEntrySet keyEntries,
const Argument start 
)

Initializes the ConstIterator for the passed ConstMapping, with the passed key entries to iterate over and the passed position as start.

Note: The pointer to the key entries has to be valid as long as the iterator exists.

296  , mapping(mapping)
298  , position(mapping->getDimensionSet(), start.getTime())
300  , nextEntry()
301 {
302  assert(keyEntries);
303 
304  //the passed start position should define a value for every dimension
305  //of this iterators underlying mapping.
306  assert(start.getDimensions().isSubSet(dimensions));
307 
308  //Since the position is compared to the key entries we have to make
309  //sure it always contains only the dimensions of the underlying mapping.
310  //(the passed Argument might have more dimensions)
311  position.setArgValues(start, true);
312 
313  nextEntry = keyEntries->upper_bound(position);
314 }
ConstMappingIterator()
Definition: MappingBase.h:725
const DimensionSet & getDimensionSet() const
Returns this Mappings domain as DimensionSet.
Definition: MappingBase.h:995
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const DimensionSet & dimensions
The dimensions of the underlying ConstMapping.
Definition: MappingBase.h:1412
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
const ConstMapping *const mapping
The underlying ConstMapping to iterate over.
Definition: MappingBase.h:1409
inet::physicallayer::SimpleConstMappingIterator::SimpleConstMappingIterator ( const ConstMapping mapping,
const SimpleConstMappingIterator::KeyEntrySet keyEntries 
)

Initializes the ConstIterator for the passed ConstMapping, with the passed key entries to iterate over.

Note: The pointer to the key entries has to be valid as long as the iterator exists.

319  , mapping(mapping)
323  , nextEntry()
324 {
325  assert(keyEntries);
326 
327  jumpToBegin();
328 }
virtual void jumpToBegin() override
Lets the iterator point to the first "position of interest" of the underlying mapping.
Definition: MappingBase.h:1488
ConstMappingIterator()
Definition: MappingBase.h:725
const DimensionSet & getDimensionSet() const
Returns this Mappings domain as DimensionSet.
Definition: MappingBase.h:995
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const DimensionSet & dimensions
The dimensions of the underlying ConstMapping.
Definition: MappingBase.h:1412
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
const ConstMapping *const mapping
The underlying ConstMapping to iterate over.
Definition: MappingBase.h:1409

Member Function Documentation

virtual const Argument& inet::physicallayer::SimpleConstMappingIterator::getNextPosition ( ) const
inlineoverridevirtual

Returns the next position a call to "next()" would iterate to.

This method has constant complexity.

Throws an NoNextIteratorException if there is no next point of interest.

Implements inet::physicallayer::ConstMappingIterator.

1465  {
1466  if (nextEntry == keyEntries->end())
1467  throw NoNextIteratorException();
1468  return *nextEntry;
1469  }
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
virtual const Argument& inet::physicallayer::SimpleConstMappingIterator::getPosition ( ) const
inlineoverridevirtual

Returns the current position of the iterator.

Constant complexity.

Implements inet::physicallayer::ConstMappingIterator.

1560 { return position; }
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
virtual argument_value_t inet::physicallayer::SimpleConstMappingIterator::getValue ( ) const
inlineoverridevirtual

Returns the value of the underlying mapping at the current position of the iterator.

This method has the same complexity as the "getValue()" method of the underlying mapping.

Implements inet::physicallayer::ConstMappingIterator.

1569 { return mapping->getValue(position); }
virtual argument_value_t getValue(const Argument &pos) const =0
Returns the value of this Mapping at the position specified by the passed Argument.
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const ConstMapping *const mapping
The underlying ConstMapping to iterate over.
Definition: MappingBase.h:1409
virtual bool inet::physicallayer::SimpleConstMappingIterator::hasNext ( ) const
inlineoverridevirtual

Returns true if there is a next position a call to "next()" can iterate to.

Has constant complexity.

Implements inet::physicallayer::ConstMappingIterator.

1553 { return nextEntry != keyEntries->end(); }
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
virtual bool inet::physicallayer::SimpleConstMappingIterator::inRange ( ) const
inlineoverridevirtual

Returns true if the current position of the iterator is equal or bigger than the first point of interest and lower or equal than the last point of interest.

Has constant complexity.

Implements inet::physicallayer::ConstMappingIterator.

1542  {
1543  return !(keyEntries->empty()
1544  || (*(keyEntries->rbegin()) < position)
1545  || (position < *(keyEntries->begin())));
1546  }
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
virtual void inet::physicallayer::SimpleConstMappingIterator::iterateTo ( const Argument pos)
inlineoverridevirtual

Increases the position of the iterator to the passed position.

The passed position has to be compared greater than the previous position.

This method has constant complexity.

Implements inet::physicallayer::ConstMappingIterator.

1511  {
1512  position.setArgValues(pos, true);
1513  const KeyEntrySet::const_iterator keyEntriesEnd = keyEntries->end();
1514  while (nextEntry != keyEntriesEnd && !(position < *nextEntry))
1515  ++nextEntry;
1516  }
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
virtual void inet::physicallayer::SimpleConstMappingIterator::jumpTo ( const Argument pos)
inlineoverridevirtual

Lets the iterator point to the passed position.

This method has logarithmic complexity (over the number of key entries).

Implements inet::physicallayer::ConstMappingIterator.

1477  {
1478  position.setArgValues(pos, true);
1479  nextEntry = keyEntries->upper_bound(position);
1480  }
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
virtual void inet::physicallayer::SimpleConstMappingIterator::jumpToBegin ( )
inlineoverridevirtual

Lets the iterator point to the first "position of interest" of the underlying mapping.

This method has constant complexity.

Implements inet::physicallayer::ConstMappingIterator.

Referenced by SimpleConstMappingIterator().

1489  {
1490  nextEntry = keyEntries->begin();
1491 
1492  if (nextEntry == keyEntries->end()) {
1493  position = Argument(dimensions);
1494  }
1495  else {
1496  position = *nextEntry;
1497  ++nextEntry;
1498  }
1499  }
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const DimensionSet & dimensions
The dimensions of the underlying ConstMapping.
Definition: MappingBase.h:1412
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
virtual void inet::physicallayer::SimpleConstMappingIterator::next ( )
inlineoverridevirtual

Iterates to the next "point of interest" of the Mapping.

Throws an NoNextIteratorException if there is no next point of interest.

This method has constant complexity.

Implements inet::physicallayer::ConstMappingIterator.

1526  {
1527  if (nextEntry == keyEntries->end())
1528  throw NoNextIteratorException();
1529 
1530  position = *nextEntry;
1531  ++nextEntry;
1532  }
KeyEntrySet::const_iterator nextEntry
An iterator over the key entry set which defines the next bigger entry of the current position...
Definition: MappingBase.h:1424
KeyEntryType position
The current position of the iterator.
Definition: MappingBase.h:1415
const KeyEntrySet * keyEntries
A pointer to a set of Arguments defining the positions to iterate over.
Definition: MappingBase.h:1420
SimpleConstMappingIterator& inet::physicallayer::SimpleConstMappingIterator::operator= ( const SimpleConstMappingIterator )
private

Assignment operator is not allowed.

Member Data Documentation

const DimensionSet& inet::physicallayer::SimpleConstMappingIterator::dimensions
protected
const KeyEntrySet* inet::physicallayer::SimpleConstMappingIterator::keyEntries
protected

A pointer to a set of Arguments defining the positions to iterate over.

Referenced by inet::physicallayer::SimpleConstMapping::createKeyEntries(), and inet::physicallayer::SimpleConstMapping::initializeArguments().

const ConstMapping* const inet::physicallayer::SimpleConstMappingIterator::mapping
protected

The underlying ConstMapping to iterate over.

KeyEntrySet::const_iterator inet::physicallayer::SimpleConstMappingIterator::nextEntry
protected

An iterator over the key entry set which defines the next bigger entry of the current position.

Referenced by SimpleConstMappingIterator().

KeyEntryType inet::physicallayer::SimpleConstMappingIterator::position
protected

The current position of the iterator.

Referenced by SimpleConstMappingIterator().


The documentation for this class was generated from the following files: