CARMA C++
sza::util::TimeVal Class Reference

A class for managing timeval/timespec structs. More...

#include <carma/szautil/TimeVal.h>

Public Member Functions

std::string dateString ()
 
double getElapsedTimeInMicroSeconds ()
 Return the time in our timeVal struct as integer microseconds. More...
 
unsigned long getElapsedTimeInNanoSeconds ()
 Return the time in our timeVal struct as integer nanoseconds. More...
 
double getElapsedTimeInSeconds ()
 Return the time elapsed as fractional seconds. More...
 
double getFractionalMjdDay ()
 Return the feactional part only of the mjd day as a double. More...
 
double getFractionalTimeInSeconds ()
 Return just the fractional seconds, as a double. More...
 
unsigned long getMicroSeconds ()
 Return just the integer micro seconds. More...
 
double getMjd ()
 Return the complete mjd day as a double. More...
 
unsigned long getMjdDays ()
 Return the mjd day number corresponding to this time. More...
 
unsigned int getMjdId (unsigned nanoSecondInterval)
 Get a unique identifier based on the MJD. More...
 
unsigned long getMjdMilliSeconds ()
 Return the mjd milliseconds corresponding to this time. More...
 
unsigned long getMjdNanoSeconds ()
 Return the mjd nanoseconds corresponding to this time. More...
 
unsigned long getMjdSeconds ()
 Return the mjd seconds corresponding to this time. More...
 
unsigned long getNanoSeconds ()
 Return just the integer nano seconds. More...
 
unsigned long getSeconds ()
 Return just the integer seconds. More...
 
double getTimeInMicroSeconds ()
 Return the total time in microseconds. More...
 
double getTimeInMilliSeconds ()
 Return the total time in milliseconds. More...
 
double getTimeInMjdDays ()
 Return the total time in MJD days. More...
 
unsigned long getTimeInNanoSeconds ()
 Return the total time as integer nanoseconds. More...
 
double getTimeInSeconds ()
 Return the time in our timeval struct as fractional seconds. More...
 
std::string getUtcString ()
 
void incrementNanoSeconds (unsigned nanoSeconds)
 Increment the time by nanoseconds. More...
 
void incrementSeconds (double seconds)
 Increment the time by fractional seconds. More...
 
const TimeVal operator+ (const TimeVal &tVal)
 Add two TimeVal objects. More...
 
const TimeVal operator- (const TimeVal &tVal)
 Subtract two TimeVal objects. More...
 
void reset ()
 Reset our internal timeval struct to stored values. More...
 
void setMicroSeconds (unsigned long microSeconds)
 Set the microseconds in this struct. More...
 
void setMjd (unsigned long days, unsigned long seconds, unsigned long nanoSeconds)
 Set the time, as an MJD. More...
 
void setMjd (unsigned long days, unsigned long milliSeconds)
 Set the time, as an MJD. More...
 
void setMjd (double mjd)
 Set the time, as a double MJD. More...
 
void setSeconds (unsigned long seconds)
 Set the seconds in this object. More...
 
void setTime (unsigned long seconds, unsigned long microSeconds, unsigned long nanoSeconds)
 Set the time. More...
 
void setTime (unsigned long seconds, unsigned long nanoSeconds)
 Set the time. More...
 
void setTime (const struct timespec &timeSpec)
 Set the time with a timespec struct. More...
 
void setTime (const struct timeval &tVal)
 Set the time with a timeval struct. More...
 
void setToCurrentTime (clockid_t clock=CLOCK_REALTIME)
 Fill this structure with the current time from the specified clock. More...
 
struct timespec * timeSpec ()
 Return a pointer to our internal timespec struct. More...
 
 TimeVal ()
 Constructors with no initialization. More...
 
 TimeVal (unsigned long seconds, unsigned long microSeconds, unsigned long nanoSeconds)
 Constructors with initialization. More...
 
 TimeVal (unsigned long seconds, unsigned long nanoSeconds)
 Constructor with seconds and nanoseconds. More...
 
 TimeVal (const struct timeval &tVal)
 Initialize from a timeval struct. More...
 
 TimeVal (const struct timespec &timeSpec)
 Initialize from a timespec struct. More...
 
 TimeVal (double mjd)
 Initialize from a double MJD. More...
 
struct timeval * timeVal ()
 Return a pointer to our internal timeval struct. More...
 

Friends

std::ostream & operator<< (std::ostream &os, TimeVal &tVal)
 Allows cout << timeVal. More...
 

Detailed Description

A class for managing timeval/timespec structs.

These are defined in sys/time.h as:

struct timeval { long tv_sec; long tv_usec; } and

struct timespec { long tv_sec; long tv_nsec; }

struct timeval (with microsecond resolution) is used by functions like select() as a timeout specifier, while struct timespec (with nanosecond resolution) is used by functions like clock_gettime(). Many system functions which require a time specification user one or the other in an irritatingly inconsistent fashion.

This class is intended as a meta-time specifier, which stores a time with nanosecond granularity, and can present either a timeval or timespec face to the world, via the timeVal() and timeSpec() methods below.

Note that functions like select() can modify their timeval arguments, while most uses of timespec are as a static container. The ***Elapsed() methods below reflect the mutability of a timeval struct when used as a timeout argument to select(), which decrements the timeval struct to reflect elapsed time.

Definition at line 53 of file TimeVal.h.

Constructor & Destructor Documentation

sza::util::TimeVal::TimeVal ( )

Constructors with no initialization.

sza::util::TimeVal::TimeVal ( unsigned long  seconds,
unsigned long  microSeconds,
unsigned long  nanoSeconds 
)

Constructors with initialization.

We make this one have three arguments, otherwise there's no way of distinguishing a constructor with seconds and microseconds from a constructor with seconds and nanoseconds.

Although the internal time representation is always kept either in seconds and microseconds (struct timeval) or seconds and nanoseconds (struct timespec), the time set in the constructor will be the addition of all three arguments.

sza::util::TimeVal::TimeVal ( unsigned long  seconds,
unsigned long  nanoSeconds 
)

Constructor with seconds and nanoseconds.

sza::util::TimeVal::TimeVal ( const struct timeval &  tVal)

Initialize from a timeval struct.

sza::util::TimeVal::TimeVal ( const struct timespec &  timeSpec)

Initialize from a timespec struct.

sza::util::TimeVal::TimeVal ( double  mjd)

Initialize from a double MJD.

Member Function Documentation

double sza::util::TimeVal::getElapsedTimeInMicroSeconds ( )

Return the time in our timeVal struct as integer microseconds.

unsigned long sza::util::TimeVal::getElapsedTimeInNanoSeconds ( )

Return the time in our timeVal struct as integer nanoseconds.

double sza::util::TimeVal::getElapsedTimeInSeconds ( )

Return the time elapsed as fractional seconds.

Note that the ***Elapsed() methods only apply to our timeval struct, since a timespec struct is not used as a countdown timer.

double sza::util::TimeVal::getFractionalMjdDay ( )

Return the feactional part only of the mjd day as a double.

double sza::util::TimeVal::getFractionalTimeInSeconds ( )

Return just the fractional seconds, as a double.

unsigned long sza::util::TimeVal::getMicroSeconds ( )

Return just the integer micro seconds.

double sza::util::TimeVal::getMjd ( )

Return the complete mjd day as a double.

unsigned long sza::util::TimeVal::getMjdDays ( )

Return the mjd day number corresponding to this time.

unsigned int sza::util::TimeVal::getMjdId ( unsigned  nanoSecondInterval)

Get a unique identifier based on the MJD.

This will return the integral number of nanoSecondIntervals corresponding to this MJD.

unsigned long sza::util::TimeVal::getMjdMilliSeconds ( )

Return the mjd milliseconds corresponding to this time.

unsigned long sza::util::TimeVal::getMjdNanoSeconds ( )

Return the mjd nanoseconds corresponding to this time.

unsigned long sza::util::TimeVal::getMjdSeconds ( )

Return the mjd seconds corresponding to this time.

unsigned long sza::util::TimeVal::getNanoSeconds ( )

Return just the integer nano seconds.

unsigned long sza::util::TimeVal::getSeconds ( )

Return just the integer seconds.

double sza::util::TimeVal::getTimeInMicroSeconds ( )

Return the total time in microseconds.

double sza::util::TimeVal::getTimeInMilliSeconds ( )

Return the total time in milliseconds.

double sza::util::TimeVal::getTimeInMjdDays ( )

Return the total time in MJD days.

unsigned long sza::util::TimeVal::getTimeInNanoSeconds ( )

Return the total time as integer nanoseconds.

double sza::util::TimeVal::getTimeInSeconds ( )

Return the time in our timeval struct as fractional seconds.

void sza::util::TimeVal::incrementNanoSeconds ( unsigned  nanoSeconds)

Increment the time by nanoseconds.

void sza::util::TimeVal::incrementSeconds ( double  seconds)

Increment the time by fractional seconds.

const TimeVal sza::util::TimeVal::operator+ ( const TimeVal tVal)

Add two TimeVal objects.

const TimeVal sza::util::TimeVal::operator- ( const TimeVal tVal)

Subtract two TimeVal objects.

void sza::util::TimeVal::reset ( )

Reset our internal timeval struct to stored values.

void sza::util::TimeVal::setMicroSeconds ( unsigned long  microSeconds)

Set the microseconds in this struct.

Does not increment the seconds portion of the time kept by this class.

Exceptions
Errorif microSeconds is greater than 1 second.
void sza::util::TimeVal::setMjd ( unsigned long  days,
unsigned long  seconds,
unsigned long  nanoSeconds 
)

Set the time, as an MJD.

void sza::util::TimeVal::setMjd ( unsigned long  days,
unsigned long  milliSeconds 
)

Set the time, as an MJD.

void sza::util::TimeVal::setMjd ( double  mjd)

Set the time, as a double MJD.

void sza::util::TimeVal::setSeconds ( unsigned long  seconds)

Set the seconds in this object.

void sza::util::TimeVal::setTime ( unsigned long  seconds,
unsigned long  microSeconds,
unsigned long  nanoSeconds 
)

Set the time.

For the MJD representation, passed times will be interpreted as time since the Epoch.

void sza::util::TimeVal::setTime ( unsigned long  seconds,
unsigned long  nanoSeconds 
)

Set the time.

void sza::util::TimeVal::setTime ( const struct timespec &  timeSpec)

Set the time with a timespec struct.

void sza::util::TimeVal::setTime ( const struct timeval &  tVal)

Set the time with a timeval struct.

void sza::util::TimeVal::setToCurrentTime ( clockid_t  clock = CLOCK_REALTIME)

Fill this structure with the current time from the specified clock.

Supported clocks include at least:

CLOCK_REALTIME – the realtime clock for the system, relative to an Epoch (specified where?)

CLOCK_HIGHRES – the high-resolution non-adjustable clock, relative to some arbitrary time in the past.

struct timespec* sza::util::TimeVal::timeSpec ( )

Return a pointer to our internal timespec struct.

struct timeval* sza::util::TimeVal::timeVal ( )

Return a pointer to our internal timeval struct.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
TimeVal tVal 
)
friend

Allows cout << timeVal.


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