Class TimeStampBase

Class Documentation

class TimeStampBase

This class provides common functionality across platforms for the timestamps.

Most of the operations on a timestamp class is common from one platform to the next. These functions are bundled together in this class.

Public Functions

inline explicit TimeStampBase()
explicit TimeStampBase(const double &decimal_time_value)

Default constructor.

Initialise the timestamp with a default value.

Initialises the timestamp with the specified double value. Note that this is slower than the manual initialisation with a sec/nsec pair.

Parameters

decimal_time_value – : time units in seconds (integral part) and nanoseconds (decimal part).

Throws

StandardException – : throws if the input arguments is not positive [debug mode only].

TimeStampBase(const time_t &seconds, const long &nanoseconds)

Initialises the timestamp with the specified sec/nsec pair.

This is the fastest means of initialisation to a set time value.

Parameters
  • seconds – : discrete time value measured in whole seconds.

  • nanoseconds – : fraction of a second measured in nanoseconds.

Throws

StandardException – : throws if input arguments are not positive [debug mode only].

inline virtual ~TimeStampBase()
const TimeStampBase &stamp(const double &decimal_time_value)

Manually set the timestamp.

Manually sets the timestamp with the specified double value. Note that this is slower than the stamp with a sec/nsec pair.

Parameters

decimal_time_value – : time units in seconds (integral part) and nanoseconds (decimal part).

Throws

StandardException – : throws if the input arguments is not positive [debug mode only].

const TimeStampBase &stamp(const time_t &seconds, const long &nanoseconds)

Manually sets the timestamp with the specified values.

This is the fastest way of setting the timestamp.

Parameters
  • seconds – : discrete time value measured in whole seconds.

  • nanoseconds – : fraction of a second measured in nanoseconds.

Throws

StandardException – : throws if input arguments are not positive [debug mode only].

inline long sec() const

Seconds component.

Get the current number of whole seconds recorded by this timestamp.

Returns

Seconds : the number of whole seconds recorded by this timestamp.

inline long msec() const

Milliseconds component (after removing seconds).

Get the fractional number of milliseconds recorded in this timestamp.

Returns

long : the fractional amount of time recorded by this timestamp (in ms).

inline long usec() const

Microseconds component (after removing seconds).

Get the fractional number of microseconds recorded in this timestamp.

Returns

long : the fractional amount of time recorded by this timestamp (in us).

inline long nsec() const

Nanoseconds component (after removing seconds).

Get the fractional number of nanoseconds recorded in this timestamp.

Returns

long : the fractional amount of time recorded by this timestamp (in ns).

inline operator double() const

Disguises the timestamp as a regular double.

Converts the posix timespec structure to a double (seconds->integral part, nanoseconds->fractional part). This is sometimes useful in time calculations.

bool operator==(const TimeStampBase &time_stamp)

Equality operator.

Parameters

time_stamp – : the rhv (timestamp) to be compared to this instance.

Returns

bool : the result of the comparison operation.

bool operator!=(const TimeStampBase &time_stamp)

Inequality operator.

Parameters

time_stamp – : the rhv (timestamp) to be compared to this instance.

Returns

bool : the result of the comparison operation.

bool operator<=(const TimeStampBase &time_stamp)

Less than or equal to operator.

Parameters

time_stamp – : the rhv (timestamp) to be compared to this instance.

Returns

bool : the result of the comparison operation.

bool operator>=(const TimeStampBase &time_stamp)

Greater than or equal to operator.

Parameters

time_stamp – : the rhv (timestamp) to be compared to this instance.

Returns

bool : the result of the comparison operation.

bool operator<(const TimeStampBase &time_stamp)

Less than operator.

Parameters

time_stamp – : the rhv (timestamp) to be compared to this instance.

Returns

bool : the result of the comparison operation.

bool operator>(const TimeStampBase &time_stamp)

Greater than or equal to operator.

Parameters

time_stamp – : the rhv (timestamp) to be compared to this instance.

Returns

bool : the result of the comparison operation.

TimeStampBase operator+(const TimeStampBase &time_stamp)

Sum operator that returns a new timestamp holding the sum.

Parameters

time_stamp – : the rhv (timestamp to be added to this instance).

Returns

TimeStamp : the sum of the two timestamps.

void operator+=(const TimeStampBase &time_stamp)

Sum operator that modifies this instance with the result.

Parameters

time_stamp – : the rhv (timestamp to be added to this instance).

TimeStampBase operator-(const TimeStampBase &time_stamp)

Difference operator that returns a new timestamp holding the difference. Note that a difference that would result in a negative timestamp is not permitted (design requirement). Subsequently, this method will throw when in debug mode if this situation occurs.

Parameters

time_stamp – : the rhv (timestamp to be subtracted from this instance).

Throws

StandardException – : throws if difference would create a negative timestamp [debug mode only].

Returns

TimeStamp : the difference of the two timestamps.

void operator-=(const TimeStampBase &time_stamp)

Difference operator that modifies this instance with the result. Note that a difference that would result in a negative timestamp is not permitted (design requirement). Subsequently, this method will throw when in debug mode if this situation occurs.

Parameters

time_stamp – : the rhv (timestamp to be subtracted from this instance).

Throws

StandardException – : throws if difference would create a negative timestamp [debug mode only].

Protected Attributes

TimeStructure time

Friends

template<typename OutputStream>
friend OutputStream &operator<<(OutputStream &ostream, const TimeStampBase &time_stamp)