Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

MultiDimMappingIterator< Interpolator > Class Template Reference
[mapping - classes representing mathematical mappings]

Implementation of the MappingIterator-interface which is able to iterate over every value in a MultiDimMapping. More...

#include <MappingUtils.h>

Inherits MappingIterator.

Collaboration diagram for MultiDimMappingIterator< Interpolator >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MultiDimMappingIterator (MultiDimMapping< Interpolator > &mapping)
 Initializes the Iterator for the passed MultiDimMapping and sets its position two the first entry of the passed MultiDimMapping.
 MultiDimMappingIterator (MultiDimMapping< Interpolator > &mapping, const Argument &pos)
 Intializes the Iterator for the passed MultiDimMapping and sets its position two the passed position.
virtual ~MultiDimMappingIterator ()
 Frees the memory allocated for the sub mappings.
void jumpTo (const Argument &pos)
 Lets the iterator point to the passed position.
void iterateTo (const Argument &pos)
 Iterates to the specified position. This method should be used if the new position is near the current position.
virtual void next ()
 Iterates to the next position of the function.
virtual bool inRange () const
 Returns true if the current position of the iterator is in range of the function.
virtual const ArgumentgetPosition () const
 Returns the current position of the iterator.
virtual const ArgumentgetNextPosition () const
 returns the next position a call to "next()" would jump to.
virtual double getValue () const
 Returns the value of the underlying mapping at the current position.
virtual void jumpToBegin ()
 Lets the iterator point to the begin of the function.
virtual bool hasNext () const
 Returns true if the iterator has a valid next value a call to "next()" could jump to.
virtual void setValue (double value)
 Changes the value of the function at the current position.

Protected Types

typedef InterpolateableMap
< double, Mapping
*, Interpolator< double,
Mapping *, std::map< double,
Mapping * >::value_type,
std::map< double, Mapping * >
::const_iterator > > 
MapType
 The type of the InterpolateableMap used by the underlying Mapping.
typedef MapType::intpl_iterator IteratorType
 Iterator type of the used InterpolateableMap type.

Protected Member Functions

void updateSubIterator (const Argument &pos)
 Helper method which updates the sub-iterator for the passed position.
void updateSubIterator ()
 Helper method which updates the sub-iterator and sets the position of the sub-iterator to its beginning.
void updateNextPosition ()
 Helper method which updates the nextPosition member.

Protected Attributes

MultiDimMapping< Interpolator > & mapping
 The MultiDimmapping to iterate over.
IteratorType valueIt
 Iterator storing the current position inside the underlying Mappings sub-mapping map.
MapType::interpolated subMapping
 The sub-mapping of the sub-mapping map at the current position.
MappingIteratorsubIterator
 An iterator for the sub-mapping which points two the current position in the next dimensions.
Argument position
 The current position in every Dimension of this Iterator.
Argument nextPosition
 The position a call to "next()" would jump to.

Detailed Description

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
class MultiDimMappingIterator< Interpolator >

Implementation of the MappingIterator-interface which is able to iterate over every value in a MultiDimMapping.

As the MultiDimMapping has a tree-like structure of sub-mappings to represent multiple dimensions, the MultiDimIterator consist of a number of sub-MultiDimIterator to represent the current position inside the sub-mappings. So every sub-mapping-iterator represents one dimension and the and Iterator to next Dimensions. The last iterator is an TimeMappingIterator.

Iteration works by sub-iterator-first-iteration. Which means that at first the sub-iterator at the current position is iterated to its end before the position inside the dimension of this iterator is increased. This assures the iteration order demanded by the MappingIterator-interface.

Author:
Karl Wessel

Definition at line 935 of file MappingUtils.h.


Member Function Documentation

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual const Argument& MultiDimMappingIterator< Interpolator >::getNextPosition (  )  const [inline, virtual]

returns the next position a call to "next()" would jump to.

Constant complexity.

Implements ConstMappingIterator.

Definition at line 1206 of file MappingUtils.h.

                                                  {
    return nextPosition;
  }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual const Argument& MultiDimMappingIterator< Interpolator >::getPosition (  )  const [inline, virtual]

Returns the current position of the iterator.

Constant complexity.

Implements ConstMappingIterator.

Definition at line 1197 of file MappingUtils.h.

                                              {
    return position;
  }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual double MultiDimMappingIterator< Interpolator >::getValue (  )  const [inline, virtual]

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

Has constant complexity.

Implements ConstMappingIterator.

Definition at line 1216 of file MappingUtils.h.

                                  {
    if(subIterator)
      return subIterator->getValue();
    else
      return 0.0;
  }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual bool MultiDimMappingIterator< Interpolator >::hasNext (  )  const [inline, virtual]

Returns true if the iterator has a valid next value a call to "next()" could jump to.

Constant complexity.

Implements ConstMappingIterator.

Definition at line 1247 of file MappingUtils.h.

                                 {
      return valueIt.hasNext() or (subIterator and subIterator->hasNext() and valueIt.inRange());
    }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual bool MultiDimMappingIterator< Interpolator >::inRange (  )  const [inline, virtual]

Returns true if the current position of the iterator is in range of the function.

This method should be used as end-condition when iterating over the function with the "next()" method.

Constant complexity.

Implements ConstMappingIterator.

Definition at line 1188 of file MappingUtils.h.

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
void MultiDimMappingIterator< Interpolator >::iterateTo ( const Argument pos  )  [inline, virtual]

Iterates to the specified position. This method should be used if the new position is near the current position.

The new position has to be compared bigger than the current position

Has linear complexity over the number of entries between the current position and the passed position. This leads to nearly constant complexity for position close together.

Implements ConstMappingIterator.

Definition at line 1135 of file MappingUtils.h.

                                     {
    double argVal = pos.getArgValue(mapping.myDimension);

    if(argVal != valueIt.getPosition() && pos.hasArgVal(mapping.myDimension)) {
      valueIt.iterateTo(argVal);
      updateSubIterator(pos);
    } else {
      if(subIterator)
        subIterator->iterateTo(pos);
    }

    position.setArgValues(pos);
    updateNextPosition();
  }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
void MultiDimMappingIterator< Interpolator >::jumpTo ( const Argument pos  )  [inline, virtual]

Lets the iterator point to the passed position.

The passed new position can be at arbitrary places.

Has logarithmic complexity in number of dimensions and number of entries inside each dimension.

Implements ConstMappingIterator.

Definition at line 1109 of file MappingUtils.h.

                                    {
    double argVal = pos.getArgValue(mapping.myDimension);

    if(argVal != valueIt.getPosition() && pos.hasArgVal(mapping.myDimension)) {
      valueIt.jumpTo(argVal);
      updateSubIterator(pos);
    } else {
      if(subIterator)
        subIterator->jumpTo(pos);
    }

    position.setArgValues(pos);
    nextPosition.setArgValues(position);
    updateNextPosition();
  }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual void MultiDimMappingIterator< Interpolator >::jumpToBegin (  )  [inline, virtual]

Lets the iterator point to the begin of the function.

The beginning of the function depends is the position of the first entry in the underlying Mapping.

Constant complexity.

Implements ConstMappingIterator.

Definition at line 1231 of file MappingUtils.h.

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual void MultiDimMappingIterator< Interpolator >::next (  )  [inline, virtual]

Iterates to the next position of the function.

The next position depends on the implementation of the Function. Calling this method will always work, but if their is no next entry to iterate to inside the underlying Mapping the actual position next jumps will be valid but without meaning. Therefore "hasNext()" should be called before calling this method.

Has constant complexity.

Implements ConstMappingIterator.

Definition at line 1162 of file MappingUtils.h.

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
virtual void MultiDimMappingIterator< Interpolator >::setValue ( double  value  )  [inline, virtual]

Changes the value of the function at the current position.

Constant complexity.

Implements MappingIterator.

Reimplemented in FilledUpMappingIterator.

Definition at line 1257 of file MappingUtils.h.

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
void MultiDimMappingIterator< Interpolator >::updateNextPosition (  )  [inline, protected]

Helper method which updates the nextPosition member.

Called when the current position has changed.

Definition at line 1023 of file MappingUtils.h.

                           {
    bool intp = subMapping.isInterpolated;

    bool noSubIt = false;
    bool hasNoNext = false;
    if(!intp){
      noSubIt = !subIterator;
      if(!noSubIt)
        hasNoNext = !subIterator->hasNext();
    }
    if(intp || noSubIt || hasNoNext){
      if(valueIt.hasNext()){
        ConstMappingIterator* tmp = (*valueIt.getNextValue())->createConstIterator();
        nextPosition.setArgValues(tmp->getPosition());
        delete tmp;
      }else{
        nextPosition = position;
      }
      nextPosition.setArgValue(mapping.myDimension, valueIt.getNextPosition());

    } else {
      nextPosition.setArgValues(subIterator->getNextPosition());
    }
  }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
void MultiDimMappingIterator< Interpolator >::updateSubIterator (  )  [inline, protected]

Helper method which updates the sub-iterator and sets the position of the sub-iterator to its beginning.

Called when the position of of the iterator inside the dimension this Iterator represents has changed.

Definition at line 998 of file MappingUtils.h.

                           {
    typename MapType::interpolated subM = valueIt.getValue();
    if(subM != subMapping) {
      if(subIterator)
        delete subIterator;

      subMapping = subM;
      if(*subMapping){
        if(subMapping.isInterpolated)
          subIterator = (*subMapping)->createIterator(position);
        else
          subIterator = (*subMapping)->createIterator();
      }else
        subIterator = 0;
    } else {
      if(subIterator)
        subIterator->jumpToBegin();
    }
  }

template<template< class Key, class Value, class Pair, class iterator > class Interpolator>
void MultiDimMappingIterator< Interpolator >::updateSubIterator ( const Argument pos  )  [inline, protected]

Helper method which updates the sub-iterator for the passed position.

Called when the position of of the iterator inside the dimension this Iterator represents has changed.

Definition at line 974 of file MappingUtils.h.

                                              {
    typename MapType::interpolated subM = valueIt.getValue();
    if(subM != subMapping) {
      if(subIterator)
        delete subIterator;

      subMapping = subM;
      if(*subMapping)
        subIterator = (*subMapping)->createIterator(pos);
      else
        subIterator = 0;
    } else {
      if(subIterator)
        subIterator->jumpTo(pos);
    }
  }


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