Public Member Functions | Protected Types | Protected Attributes

SimpleConstMappingIterator Class Reference
[mapping - classes representing mathematical mappings]

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

#include <MappingBase.h>

Inherits ConstMappingIterator.

Collaboration diagram for SimpleConstMappingIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SimpleConstMappingIterator (ConstMapping *mapping, const std::set< Argument > *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 (ConstMapping *mapping, const std::set< Argument > *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 double 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.

Protected Attributes

ConstMappingmapping
 The underlying ConstMapping to iterate over.
DimensionSet dimensions
 The dimensions of the underlying ConstMapping.
Argument 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.

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

Definition at line 1002 of file MappingBase.h.


Constructor & Destructor Documentation

SimpleConstMappingIterator::SimpleConstMappingIterator ( ConstMapping mapping,
const std::set< Argument > *  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.

Definition at line 360 of file MappingBase.cc.

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

                                     :
  mapping(mapping),
  dimensions(mapping->getDimensionSet()),
  position(dimensions),
  keyEntries(keyEntries)
{
  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 ( ConstMapping mapping,
const std::set< Argument > *  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.

Definition at line 382 of file MappingBase.cc.

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.

Definition at line 1055 of file MappingBase.h.

References keyEntries, and nextEntry.

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

Definition at line 1145 of file MappingBase.h.

References position.

{ return position; }

virtual double 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.

Definition at line 1154 of file MappingBase.h.

References ConstMapping::getValue(), mapping, and position.

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

Definition at line 1138 of file MappingBase.h.

References keyEntries, and nextEntry.

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

Definition at line 1127 of file MappingBase.h.

References keyEntries, and position.

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

Definition at line 1098 of file MappingBase.h.

References keyEntries, nextEntry, position, and Argument::setArgValues().

                                              {
    position.setArgValues(pos, true);
    while(nextEntry != keyEntries->end() && !(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.

Definition at line 1067 of file MappingBase.h.

References keyEntries, nextEntry, position, and Argument::setArgValues().

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

Definition at line 1078 of file MappingBase.h.

References dimensions, keyEntries, nextEntry, and position.

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.

Definition at line 1112 of file MappingBase.h.

References keyEntries, nextEntry, and position.


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