Project

General

Profile

BitmapToolkit Scol plugin

Timestamp. More...

#include <Timestamp.h>

Public Types

enum  tOptions { NONE = 0 , CURRENT_TIME = 0x1 , ZERO = 0x2 }
 Options to initiate a timestamp. More...
 

Public Member Functions

 Timestamp (Timestamp::tOptions option=NONE)
 
virtual ~Timestamp (void)
 
bool empty () const
 
void setToCurrentTime ()
 
void setTime (unsigned long secs, unsigned long usecs)
 
void getTime (unsigned long &secs, unsigned long &usecs) const
 
void setTime (const string &stime)
 
void setTime (double s)
 
double getFloatTime () const
 
string getStringTime () const
 
double operator- (const Timestamp &t) const
 
Timestamp plus (unsigned long s, unsigned long us) const
 
Timestamp minus (unsigned long s, unsigned long us) const
 
Timestampoperator+= (double s)
 
Timestampoperator-= (double s)
 
Timestamp operator+ (double s) const
 
Timestamp operator- (double s) const
 
bool operator> (const Timestamp &t) const
 
bool operator>= (const Timestamp &t) const
 
bool operator== (const Timestamp &t) const
 
bool operator< (const Timestamp &t) const
 
bool operator<= (const Timestamp &t) const
 
string Format (bool machine_friendly=false) const
 

Static Public Member Functions

static string Format (double s)
 

Protected Attributes

unsigned long m_secs
 Seconds.
 
unsigned long m_usecs
 Microseconds.
 

Detailed Description

Timestamp.

Definition at line 19 of file Timestamp.h.

Member Enumeration Documentation

◆ tOptions

Options to initiate a timestamp.

Enumerator
NONE 
CURRENT_TIME 
ZERO 

Definition at line 24 of file Timestamp.h.

Constructor & Destructor Documentation

◆ Timestamp()

Timestamp::Timestamp ( Timestamp::tOptions  option = NONE)

Creates a timestamp

Parameters
optionoption to set the initial time stamp

Definition at line 39 of file Timestamp.cpp.

◆ ~Timestamp()

Timestamp::~Timestamp ( void  )
virtual

Destructor

Definition at line 47 of file Timestamp.cpp.

Member Function Documentation

◆ empty()

bool Timestamp::empty ( ) const

Says if the timestamp is "empty": seconds and usecs are both 0, as when initiated with the ZERO flag

Returns
true iif secs == usecs == 0

Definition at line 51 of file Timestamp.cpp.

◆ Format() [1/2]

string Timestamp::Format ( bool  machine_friendly = false) const

Returns the timestamp in a human-readable string

Parameters
machine_friendlyif true, the returned string is formatted to yyyymmdd_hhmmss, without weekday or spaces
Note
This has not been tested under Windows
The timestamp is truncated to seconds

Definition at line 198 of file Timestamp.cpp.

◆ Format() [2/2]

string Timestamp::Format ( double  s)
static

Returns a string version of the elapsed time in seconds, with the format xd hh:mm:ss, hh:mm:ss, mm:ss or s.us

Parameters
selapsed seconds (given by getFloatTime) to format

Definition at line 224 of file Timestamp.cpp.

◆ getFloatTime()

double Timestamp::getFloatTime ( ) const

Returns this timestamp as the number of seconds in (long) float format

Definition at line 94 of file Timestamp.cpp.

◆ getStringTime()

string Timestamp::getStringTime ( ) const

Returns this timestamp as the number of seconds in fixed length string format

Definition at line 98 of file Timestamp.cpp.

◆ getTime()

void DUtils::Timestamp::getTime ( unsigned long &  secs,
unsigned long &  usecs 
) const
inline

Returns the timestamp in seconds and microseconds

Parameters
secsseconds
usecsmicroseconds

Definition at line 71 of file Timestamp.h.

◆ minus()

Timestamp Timestamp::minus ( unsigned long  s,
unsigned long  us 
) const

Returns a copy of this timestamp - s seconds - us microseconds

Parameters
sseconds
usmicroseconds

Definition at line 150 of file Timestamp.cpp.

◆ operator+()

Timestamp Timestamp::operator+ ( double  s) const

Returns a copy of this timestamp + s seconds

Parameters
sseconds

Definition at line 120 of file Timestamp.cpp.

◆ operator+=()

Timestamp & Timestamp::operator+= ( double  s)

Adds s seconds to this timestamp and returns a reference to itself

Parameters
sseconds
Returns
reference to this timestamp

Definition at line 108 of file Timestamp.cpp.

◆ operator-() [1/2]

double Timestamp::operator- ( const Timestamp t) const

Returns the difference in seconds between this timestamp (greater) and t (smaller) If the order is swapped, a negative number is returned

Parameters
ttimestamp to subtract from this timestamp
Returns
difference in seconds

Definition at line 104 of file Timestamp.cpp.

◆ operator-() [2/2]

Timestamp Timestamp::operator- ( double  s) const

Returns a copy of this timestamp - s seconds

Parameters
sseconds

Definition at line 142 of file Timestamp.cpp.

◆ operator-=()

Timestamp & Timestamp::operator-= ( double  s)

Substracts s seconds to this timestamp and returns a reference to itself

Parameters
sseconds
Returns
reference to this timestamp

Definition at line 114 of file Timestamp.cpp.

◆ operator<()

bool Timestamp::operator< ( const Timestamp t) const

Returns whether this timestamp is at the past of t

Parameters
t

Definition at line 178 of file Timestamp.cpp.

◆ operator<=()

bool Timestamp::operator<= ( const Timestamp t) const

Returns whether this timestamp is at the past of (or is the same as) t

Parameters
t

Definition at line 185 of file Timestamp.cpp.

◆ operator==()

bool Timestamp::operator== ( const Timestamp t) const

Returns whether this timestamp and t represent the same instant

Parameters
t

Definition at line 192 of file Timestamp.cpp.

◆ operator>()

bool Timestamp::operator> ( const Timestamp t) const

Returns whether this timestamp is at the future of t

Parameters
t

Definition at line 164 of file Timestamp.cpp.

◆ operator>=()

bool Timestamp::operator>= ( const Timestamp t) const

Returns whether this timestamp is at the future of (or is the same as) t

Parameters
t

Definition at line 171 of file Timestamp.cpp.

◆ plus()

Timestamp Timestamp::plus ( unsigned long  s,
unsigned long  us 
) const

Returns a copy of this timestamp + s seconds + us microseconds

Parameters
sseconds
usmicroseconds

Definition at line 128 of file Timestamp.cpp.

◆ setTime() [1/3]

void Timestamp::setTime ( const string &  stime)

Sets the timestamp from a string with the time in seconds

Parameters
stimestring such as "1235603336.036609"

Definition at line 73 of file Timestamp.cpp.

◆ setTime() [2/3]

void Timestamp::setTime ( double  s)

Sets the timestamp from a number of seconds from the epoch

Parameters
sseconds from the epoch

Definition at line 88 of file Timestamp.cpp.

◆ setTime() [3/3]

void DUtils::Timestamp::setTime ( unsigned long  secs,
unsigned long  usecs 
)
inline

Sets the timestamp from seconds and microseconds

Parameters
secsseconds
usecsmicroseconds

Definition at line 61 of file Timestamp.h.

◆ setToCurrentTime()

void Timestamp::setToCurrentTime ( )

Sets this instance to the current time

Definition at line 56 of file Timestamp.cpp.

Member Data Documentation

◆ m_secs

unsigned long DUtils::Timestamp::m_secs
protected

Seconds.

Definition at line 196 of file Timestamp.h.

◆ m_usecs

unsigned long DUtils::Timestamp::m_usecs
protected

Microseconds.

Definition at line 198 of file Timestamp.h.


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