MiXiM  2.3
SimpleConstMappingIterator Class Reference

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

#include <MappingBase.h>

Inheritance diagram for SimpleConstMappingIterator:
Collaboration diagram for SimpleConstMappingIterator:

List of all members.

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.
 SimpleConstMappingIterator (const ConstMapping *mapping, const SimpleConstMappingIterator::KeyEntrySet *keyEntries)
 Initializes the ConstIterator for the passed ConstMapping, with the passed key entries to iterate over.
virtual const ArgumentgetNextPosition () const
 Returns the next position a call to "next()" would iterate to.
virtual void jumpTo (const Argument &pos)
 Lets the iterator point to the passed position.
virtual void jumpToBegin ()
 Lets the iterator point to the first "position of interest" of the underlying mapping.
virtual void iterateTo (const Argument &pos)
 Increases the position of the iterator to the passed position.
virtual void next ()
 Iterates to the next "point of interest" of the Mapping.
virtual bool inRange () const
 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.
virtual bool hasNext () const
 Returns true if there is a next position a call to "next()" can iterate to.
virtual const ArgumentgetPosition () const
 Returns the current position of the iterator.
virtual argument_value_t getValue () const
 Returns the value of the underlying mapping at the current position of the iterator.

Protected Types

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

Protected Attributes

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

Private Member Functions

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

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

Constructor & Destructor Documentation

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.

References dimensions, Argument::getDimensions(), DimensionSet::isSubSet(), nextEntry, and position.

  : ConstMappingIterator()
  , mapping(mapping)
  , dimensions(mapping->getDimensionSet())
  , position(mapping->getDimensionSet(), start.getTime())
  , keyEntries(keyEntries)
  , nextEntry()
{
  assert(keyEntries);

  //the passed start position should define a value for every dimension
  //of this iterators underlying mapping.
  assert(start.getDimensions().isSubSet(dimensions));

  //Since the position is compared to the key entries we have to make
  //sure it always contains only the dimensions of the underlying mapping.
  //(the passed Argument might have more dimensions)
  position.setArgValues(start, true);

  nextEntry = keyEntries->upper_bound(position);
}
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.

References jumpToBegin().


Member Function Documentation

virtual const Argument& SimpleConstMappingIterator::getNextPosition ( ) const [inline, virtual]

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 ConstMappingIterator.

                                                  {
    if(nextEntry == keyEntries->end())
      throw NoNextIteratorException();
    return *nextEntry;
  }
virtual const Argument& SimpleConstMappingIterator::getPosition ( ) const [inline, virtual]

Returns the current position of the iterator.

Constant complexity.

Implements ConstMappingIterator.

{ return position; }
virtual argument_value_t SimpleConstMappingIterator::getValue ( ) const [inline, virtual]

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 ConstMappingIterator.

{ return mapping->getValue(position); }
virtual bool SimpleConstMappingIterator::hasNext ( ) const [inline, virtual]

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

Has constant complexity.

Implements ConstMappingIterator.

{ return nextEntry != keyEntries->end(); }
virtual bool SimpleConstMappingIterator::inRange ( ) const [inline, virtual]

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 ConstMappingIterator.

                               {
    return !(keyEntries->empty()
         || (*(keyEntries->rbegin()) < position)
         || (position < *(keyEntries->begin())));
  }
virtual void SimpleConstMappingIterator::iterateTo ( const Argument pos) [inline, virtual]

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 ConstMappingIterator.

                                              {
    position.setArgValues(pos, true);
    const KeyEntrySet::const_iterator keyEntriesEnd = keyEntries->end();
    while(nextEntry != keyEntriesEnd && !(position < *nextEntry))
      ++nextEntry;
  }
virtual void SimpleConstMappingIterator::jumpTo ( const Argument pos) [inline, virtual]

Lets the iterator point to the passed position.

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

Implements ConstMappingIterator.

                                           {
    position.setArgValues(pos, true);
    nextEntry = keyEntries->upper_bound(position);
  }
virtual void SimpleConstMappingIterator::jumpToBegin ( ) [inline, virtual]

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

This method has constant complexity.

Implements ConstMappingIterator.

Referenced by SimpleConstMappingIterator().

                            {
    nextEntry = keyEntries->begin();

    if(nextEntry == keyEntries->end()) {
      position = Argument(dimensions);
    } else {
      position = *nextEntry;
      ++nextEntry;
    }
  }
virtual void SimpleConstMappingIterator::next ( ) [inline, virtual]

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 ConstMappingIterator.


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