Template for an interpolateable const iterator for any container which maps from a key to a value. This doesn't necessarily has to be a map, but also can be a sorted list of pairs. More...
#include <Interpolation.h>
Public Types | |
typedef Interpolated< V > | interpolated |
typedef for the returned Interpolated value of this class. | |
Public Member Functions | |
ConstInterpolateableIterator (Iterator first, Iterator last, const Interpolator &intpl) | |
Initializes the iterator with the passed Iterators as boundaries. | |
bool | operator== (const ConstInterpolateableIterator &other) |
void | jumpTo (const Key &pos) |
Moves the iterator to the passed position. This position can be any value of the Key-type. | |
void | jumpToBegin () |
Moves the iterator to the first element. | |
void | iterateTo (const Key &pos) |
forward iterates the iterator to the passed position. This position can be any value of the Key-type. | |
void | next () |
Iterates to the next entry in the underlying data structure. | |
Key | getNextPosition () |
bool | inRange () const |
Returns true if the current position of the iterator is between the position of the first and the last entry of the data structure. | |
bool | hasNext () const |
Returns true if the a call of "next()" would increase to the position of an a valid entry of the data structure. This means if the current position is smaller than position of the last entry. | |
interpolated | getValue () const |
Returns the interpolated value at the current position of the Iterator. | |
interpolated | getNextValue () const |
Key | getPosition () const |
Returns the current position of the iterator. | |
Protected Attributes | |
Iterator | first |
Iterator | last |
Iterator | right |
Key | position |
const Interpolator & | interpolate |
PairLess< Pair, Key > | comp |
Template for an interpolateable const iterator for any container which maps from a key to a value. This doesn't necessarily has to be a map, but also can be a sorted list of pairs.
The ConstInterpolateableIterator provides an iterator which as able to iterate in arbitrary steps over a iterateable number of pairs of "Key" and "Value". To determine the Value for a Key which does not exist in within the iterateable number of pairs it Interpolates between the nearby existing pairs. The actual Interpolation is determined by the passed Interpolator-template parameter.
An example use would be to be able to iterate over a std::map<double, double> in arbitrary steps (even at positions for which no Key exist inside the map) and be able to return an interpolated Value.
NOTE: The ConstInterpolateableIterator will become invalid if the underlying data structure is changed!
Template parameters: Pair - the type of the pair used as values in the container. Default is std::map<Key, V>::value_type (which is of type std::pair<Key, V>. The Pair type has to provide the two public members "first" and "second". Key - The type of the "first" member of the Pair type V - the type of the "second" member of the Pair type Iterator - the type of the iterator of the container (should be a const iterator). Default is std::map<Key, V>::const_iterator Interpolator - The Interpolation operator to use, this has to be a class which overwrites the ()-operator with the following parameters: Interpolated operator()(const Iterator& first, const Iterator& last, const Key& pos) Interpolated operator()(const Iterator& first, const Iterator& last, const Key& pos, Iterator upperBound) See the NextSmaller template for an example of an Interpolator. Default is NextSmaller<Key, V, Pair, Iterator>.
Definition at line 339 of file Interpolation.h.
interpolated ConstInterpolateableIterator< Key, V, Pair, Iterator, Interpolator >::getValue | ( | ) | const [inline] |
Returns the interpolated value at the current position of the Iterator.
See definition of Interpolated on details on the return type.
Definition at line 464 of file Interpolation.h.
{
return interpolate(first, last, position, right);
}
void ConstInterpolateableIterator< Key, V, Pair, Iterator, Interpolator >::iterateTo | ( | const Key & | pos | ) | [inline] |
forward iterates the iterator to the passed position. This position can be any value of the Key-type.
This method assumes that the passed position is near the current position of the iterator. If this is the case this method will be faster than the jumpTo-method.
Definition at line 403 of file Interpolation.h.
{ if(pos == position) return; while(right != last && !(pos < right->first)) right++; position = pos; }
void ConstInterpolateableIterator< Key, V, Pair, Iterator, Interpolator >::next | ( | ) | [inline] |
Iterates to the next entry in the underlying data structure.
If the current position is before the position of the first element of the data structure this method will iterate to the first entry. If the current position is after the position of the last element of the data structure this method will increase the current position with the ++ operator.
Definition at line 421 of file Interpolation.h.
{ if(hasNext()) { position = right->first; right++; } else position += 1; }