MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Mezzanine::TimedTrackIterator< InterpolatorType > Class Template Reference

This will take the same amount of clock time to iterate over a range. More...

#include <trackiterator.h>

+ Collaboration diagram for Mezzanine::TimedTrackIterator< InterpolatorType >:

Public Types

typedef
InterpolatorType::InterpolatableType 
InterpolatableType
 The type the interpolator this works with uses.
 
typedef std::input_iterator_tag iterator_category
 This almost supports random access iteration, it does not support any kind of writing to the container.
 
typedef InterpolatableTypepointer
 The type of a pointer to the iterated type.
 
typedef InterpolatableTypereference
 The type of a reference to the iterated type.
 
typedef TrackBase
< InterpolatorType > 
TargetTrackType
 What kind of track with this iterate over.
 
typedef TimedTrackIterator
< InterpolatorType > 
ThisType
 The kind of this iterator.
 
typedef InterpolatableType value_type
 What type is this iterator working with.
 

Public Member Functions

 TimedTrackIterator (const TargetTrackType *const TrackToIterate=0, Real StartOnTrack=0.0, Real EndOnTrack=1.0, MaxInt Duration=1000000, MaxInt WhenToStart=crossplatform::GetTimeStamp())
 The constructor for and iterator. More...
 
 TimedTrackIterator (const ThisType &Copy)
 Create a copy of an TimedTrackIterator. More...
 
bool AtEnd () const
 Is this iterator at the end of its range on the track. More...
 
bool AtStart () const
 Is this iterator at the beginning of its range on the track. More...
 
bool operator!= (const ThisType &Other) const
 Is this TimedTrackIterator not on the same track and in the same place as another. More...
 
virtual InterpolatableType operator* () const
 Get the location on track from the last time it was incremented. More...
 
ThisTypeoperator++ ()
 Move the TimedTrackIterator forwards on the track by an amount proportionate to time elapsed. More...
 
const ThisType operator++ (int)
 Move the TimedTrackIterator forwards on the track by an amount proportionate to time elapsed. More...
 
virtual CountedPtr
< InterpolatableType
operator-> () const
 Dereference this with the syntax for pointer member access. More...
 
TimedTrackIterator
< InterpolatorType > & 
operator= (const ThisType &Other)
 Change this TimedTrackIterator to match another (Except for Track) More...
 
bool operator== (const ThisType &Other) const
 Is this TimedTrackIterator on the same track and in the same place as another. More...
 

Protected Member Functions

InterpolatableType GetDereferenced () const
 Do the math for determining where/when the iterator is. More...
 
void Update (MaxInt Now=crossplatform::GetTimeStamp())
 Update the current location of this iterator based on the current time.
 

Protected Attributes

MaxInt CurrentTime
 Where is this iterator now.
 
Real EndRange
 Where should iteration stop.
 
MaxInt EndTime
 What Time does iteration ed at.
 
Real StartRange
 Where Should Iteration Start.
 
MaxInt StartTime
 What Time does iteration start at.
 
const TargetTrackType *const TargetTrack
 The track this works against.
 

Detailed Description

template<typename InterpolatorType>
class Mezzanine::TimedTrackIterator< InterpolatorType >

This will take the same amount of clock time to iterate over a range.

This will spread movement over a range of a track evenly throughout a period of time. For example if you have a track of Real values ranging from 0.0 to 10.0, interpolating the point at 0.0 will return 0.0 and the point 1.0 will return 10.0. Continuing this example if we were to define an iterator over this range that will take exactly 1,000 milliseconds to complete its journey, if we increment and dereference this 500 milliseconds after it was instantiated it will return 5.0. This is the point halfway through the range of the track because the time is halfway consumed.

This iterator must be bounds checked to be safe to use. If incremented before its start time its current location is set to its start time, if incremented past its end time its current location becoms its end time.

Here is a code sample that takes 3/4 of a second to iterate over the first quarter of the data in a track.

TimedTrackIterator< LinearInterpolator<Vector3> > Iter(&SomeTrack,0.0,0.25,750);
bool SimulationIsStillRunning = true;
While(SimulationIsStillRunning)
{
// This does not increment the iterator like normal iterators, it
// just updates an internal record of time
Iter++;
// When de-referencing the time is update
std::cout << *Iter << std::endl;
// DoOtherSimulationStuff will return false when the simulation end, and
// presumably it does all the other stuff
SimulationIsStillRunning = DoOtherSimulationStuff();
}

This code will emit to the standard output at least one Vector3 to the standard output. All output will be between(inclusive) 0.0 and 0.25 with times closer to the iterator creation time being near 0.0 and times closer to 750

Definition at line 354 of file trackiterator.h.

Constructor & Destructor Documentation

template<typename InterpolatorType >
Mezzanine::TimedTrackIterator< InterpolatorType >::TimedTrackIterator ( const TargetTrackType *const  TrackToIterate = 0,
Real  StartOnTrack = 0.0,
Real  EndOnTrack = 1.0,
MaxInt  Duration = 1000000,
MaxInt  WhenToStart = crossplatform::GetTimeStamp() 
)
inline

The constructor for and iterator.

Tracks

Parameters
TrackToIterateWhich track with this work against.
StartOnTrackIn the range of 0.0 to 1.0 Where on the track should iteration start. Defaults to 0.0.
EndOnTrackIn the range of 0.0 to 1.0 Where on the track should iteration end. Defaults to 1.0.
DurationIn microseconds how long should traversing the range of the track take. Defaults to 1 second.
WhenToStartThe time iteration should start. Defaults to now.

Definition at line 418 of file trackiterator.h.

template<typename InterpolatorType >
Mezzanine::TimedTrackIterator< InterpolatorType >::TimedTrackIterator ( const ThisType Copy)
inline

Create a copy of an TimedTrackIterator.

Parameters
CopyThe TimedTrackIterator to copy.

Definition at line 431 of file trackiterator.h.

Member Function Documentation

template<typename InterpolatorType >
bool Mezzanine::TimedTrackIterator< InterpolatorType >::AtEnd ( ) const
inline

Is this iterator at the end of its range on the track.

Returns
True if the iterator has been incremented to its bounds

Definition at line 504 of file trackiterator.h.

template<typename InterpolatorType >
bool Mezzanine::TimedTrackIterator< InterpolatorType >::AtStart ( ) const
inline

Is this iterator at the beginning of its range on the track.

Returns
True if the iterator has not been incremented or its time has not yet come.

Definition at line 509 of file trackiterator.h.

template<typename InterpolatorType >
InterpolatableType Mezzanine::TimedTrackIterator< InterpolatorType >::GetDereferenced ( ) const
inlineprotected

Do the math for determining where/when the iterator is.

Returns
A value on the track corresponding to how far through time

Definition at line 400 of file trackiterator.h.

template<typename InterpolatorType >
bool Mezzanine::TimedTrackIterator< InterpolatorType >::operator!= ( const ThisType Other) const
inline

Is this TimedTrackIterator not on the same track and in the same place as another.

Parameters
OtherThe Other TimedTrackIterator to compare this one too.
Returns
False if the track is the same and the location on the same track.

Definition at line 467 of file trackiterator.h.

template<typename InterpolatorType >
virtual InterpolatableType Mezzanine::TimedTrackIterator< InterpolatorType >::operator* ( ) const
inlinevirtual

Get the location on track from the last time it was incremented.

Returns
An instance of InterpolatableType that is read only
Warning
Most iterators return a reference, to allow changes in the underlying container. This returns points that are not stored, so they cannot be changed.
Note
Everytime this is called this it calls the interpolator in the Target Track, This should run in constant time, but is much slower than normal pointer dereferences.

Definition at line 474 of file trackiterator.h.

template<typename InterpolatorType >
ThisType& Mezzanine::TimedTrackIterator< InterpolatorType >::operator++ ( )
inline

Move the TimedTrackIterator forwards on the track by an amount proportionate to time elapsed.

Returns
A Reference to this iterator after the change has been made.

Definition at line 485 of file trackiterator.h.

template<typename InterpolatorType >
const ThisType Mezzanine::TimedTrackIterator< InterpolatorType >::operator++ ( int  )
inline

Move the TimedTrackIterator forwards on the track by an amount proportionate to time elapsed.

Like the prefix ++ this moves the iterator, but this returns a copy of the iterator before being incremented.

Returns
An iterator that is a copy of this one before the decrement.
Note
Even though the results of this could be assignable doing so is useless without storing the results in a new iterator so this is made const.

Definition at line 495 of file trackiterator.h.

template<typename InterpolatorType >
virtual CountedPtr<InterpolatableType> Mezzanine::TimedTrackIterator< InterpolatorType >::operator-> ( ) const
inlinevirtual

Dereference this with the syntax for pointer member access.

Returns
A Counted pointer to a temporary InterpolatableType instance.
Warning
This is read only because it is not stored anywhere.
Note
Everytime this is called it calls the interpolator in the Target Track.

Definition at line 480 of file trackiterator.h.

template<typename InterpolatorType >
TimedTrackIterator<InterpolatorType>& Mezzanine::TimedTrackIterator< InterpolatorType >::operator= ( const ThisType Other)
inline

Change this TimedTrackIterator to match another (Except for Track)

Parameters
OtherThe TimedTrackIterator to copy, except for its target track
Returns
A TimedTrackIterator<InterpolatableType>

Definition at line 442 of file trackiterator.h.

template<typename InterpolatorType >
bool Mezzanine::TimedTrackIterator< InterpolatorType >::operator== ( const ThisType Other) const
inline

Is this TimedTrackIterator on the same track and in the same place as another.

Parameters
OtherThe Other TimedTrackIterator to compare this one too.
Returns
True if the track is the same and the location on the same track.

Definition at line 455 of file trackiterator.h.


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