EPANET-RTX  1.1
real-time extension for the EPANET toolkit
Public Types | Public Member Functions | List of all members
RTX::Clock Class Reference

A simple clock class for keeping time synchronized. More...

#include <Clock.h>

Inheritance diagram for RTX::Clock:
[legend]

Public Types

typedef boost::shared_ptr< ClocksharedPointer
 

Public Member Functions

 Clock (int period, time_t start=0)
 Constructor for Clock. Takes a period and offset time. More...
 
std::string name ()
 
void setName (std::string name)
 
virtual bool isCompatibleWith (Clock::sharedPointer clock)
 Test for compatibility (passed clock parameter may be faster, but must fall on even steps) More...
 
virtual bool isValid (time_t time)
 Test for validity of time value (if the passed value falls on this clock's regular steps) More...
 
virtual time_t validTime (time_t time)
 
virtual time_t timeAfter (time_t time)
 The next time step in this clock's regular pattern. More...
 
virtual time_t timeBefore (time_t time)
 The previous time step in this clock's regular pattern. More...
 
bool isRegular ()
 Test for regularity (period greater than zero) More...
 
int period ()
 The period of the time series. More...
 
void setPeriod (int p)
 
time_t start ()
 The starting point for the clock. More...
 
void setStart (time_t startTime)
 
virtual std::vector< time_t > timeValuesInRange (time_t start, time_t end)
 Get a list of time values that are valid within a range. More...
 
virtual std::ostream & toStream (std::ostream &stream)
 

Detailed Description

A simple clock class for keeping time synchronized.

Provides methods for comparing clocks to eachother for compatibility and testing the validity of a time value (e.g., if it falls on the regular intervals described by Clock. This class is meant to work with the TimeSeries class family to ensure that regular time series can be linked to eachother properly, and that irregular time series are only connected to TimeSeries classes that can resample (like Resampler).

Every Time Series object needs a clock. Whether the clock is based on an (offset,period) or based on a PointRecord, this clock needs to exist. By default, a TimeSeries' clock is irregular, and gets its pattern from the TS's PointRecord - the result of this is that the clock will show a valid time only for points that exist in the record. The other way to do this is to set a (offset,period) for the clock, and the result will be that the TimeSeries will only retrieve / store points on valid regular timesteps. In the first case, the PointRecord is the master synchronizer, and in the second case the Clock is the master synchronizer.

A reason for structuring it this (perhaps confusing) way is that it simplifies the implementation of TimeSeries, which is already quite complex. A TimeSeries-derived class can just depend on its clock to help it retrieve points. Whether the clock is synchronized manually or by a PointRecord is transparent to the user.

Constructor & Destructor Documentation

RTX::Clock::Clock ( int  period,
time_t  start = 0 
)

Constructor for Clock. Takes a period and offset time.

Parameters
periodThe regular period for the clock.
startThe start time (offset).

Member Function Documentation

bool RTX::Clock::isCompatibleWith ( Clock::sharedPointer  clock)
virtual

Test for compatibility (passed clock parameter may be faster, but must fall on even steps)

Parameters
clockA shared pointer to another clock object.
Returns
Boolean true/false value.

Reimplemented in RTX::IrregularClock.

bool RTX::Clock::isRegular ( )

Test for regularity (period greater than zero)

Returns
Boolean true/false value
bool RTX::Clock::isValid ( time_t  time)
virtual

Test for validity of time value (if the passed value falls on this clock's regular steps)

Parameters
timeA time value.
Returns
Boolean true/false value

Reimplemented in RTX::IrregularClock.

int RTX::Clock::period ( )

The period of the time series.

Returns
The period (in seconds) of the time series. Zero if irregular.
time_t RTX::Clock::start ( )

The starting point for the clock.

Returns
A unix-time value for the clock's start position (offset from zero-time).
time_t RTX::Clock::timeAfter ( time_t  time)
virtual

The next time step in this clock's regular pattern.

Parameters
timeA time value.
Returns
A unix-time value representing the next step in the pattern.
See also
http://www.youtube.com/watch?v=VdQY7BusJNU

Reimplemented in RTX::IrregularClock.

time_t RTX::Clock::timeBefore ( time_t  time)
virtual

The previous time step in this clock's regular pattern.

Parameters
timeA time value.
Returns
A unix-time value representing the previous step in the pattern.

Reimplemented in RTX::IrregularClock.

std::vector< time_t > RTX::Clock::timeValuesInRange ( time_t  start,
time_t  end 
)
virtual

Get a list of time values that are valid within a range.

Parameters
startA range start time.
endA range end time.
Returns
A vector of time_t values that are valid for this clock within the specified range.

Reimplemented in RTX::IrregularClock.


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