xorp

TimeVal Class Reference

TimeVal class. More...

#include <timeval.hh>

List of all members.

Public Member Functions

 TimeVal ()
 Default constructor.
 TimeVal (int32_t sec, int32_t usec)
 Constructor for given seconds and microseconds.
 TimeVal (const timeval &timeval)
 Constructor for given "struct timeval".
 TimeVal (const double &d)
 Constructor for given double-float time value.
int32_t sec () const
 Get the number of seconds.
int32_t usec () const
 Get the number of microseconds.
string str () const
string pretty_print () const
 Pretty print the time.
size_t copy_in (const timeval &timeval)
 Copy the time value from a timeval structure.
size_t copy_out (timeval &timeval) const
 Copy the time value to a timeval structure.
int64_t to_ms () const
 Return an int64_t containing the total number of milliseconds in the underlying structure.
void set_ms (int64_t ms)
double get_double () const
 Convert a TimeVal value to a double-float value.
TimeValoperator= (const TimeVal &other)
 Assignment Operator.
bool operator== (const TimeVal &other) const
 Equality Operator.
bool operator< (const TimeVal &other) const
 Less-Than Operator.
const TimeValoperator+= (const TimeVal &delta)
 Assign-Sum Operator.
TimeVal operator+ (const TimeVal &other) const
 Addition Operator.
const TimeValoperator-= (const TimeVal &delta)
 Assign-Difference Operator.
TimeVal operator- (const TimeVal &other) const
 Substraction Operator.
TimeVal operator* (int n) const
 Multiplication Operator for integer operand.
TimeVal operator* (unsigned int n) const
 Multiplication Operator for unsigned integer operand.
TimeVal operator* (const double &d) const
 Multiplication Operator for double float operand.
TimeVal operator/ (int n) const
 Division Operator for integer operand.
TimeVal operator/ (unsigned int n) const
 Division Operator for unsigned integer operand.
TimeVal operator/ (const double &d) const
 Division Operator for double-float operand.
bool is_zero () const
 Test if this time value is numerically zero.

Static Public Member Functions

static TimeVal ZERO ()
 Get zero value.
static TimeVal MAXIMUM ()
 Get the maximum permitted value.
static TimeVal MINIMUM ()
 Get the minimum permitted value.

Static Public Attributes

static const int32_t ONE_MILLION = 1000000
static const int32_t ONE_THOUSAND = 1000

Private Member Functions

 TimeVal (int i)

Private Attributes

int32_t _sec
int32_t _usec

Detailed Description

TimeVal class.

TimeVal class is used for storing time value. Similar to "struct timeval", the time value is in seconds and microseconds.


Constructor & Destructor Documentation

TimeVal::TimeVal ( int32_t  sec,
int32_t  usec 
) [inline]

Constructor for given seconds and microseconds.

Parameters:
secthe number of seconds.
usecthe number of microseconds.
TimeVal::TimeVal ( const timeval &  timeval) [inline, explicit]

Constructor for given "struct timeval".

Parameters:
timevalthe "struct timeval" time value to initialize this object with.
TimeVal::TimeVal ( const double &  d) [inline, explicit]

Constructor for given double-float time value.

Parameters:
dthe double-float time value to initialize this object with.

Member Function Documentation

size_t TimeVal::copy_in ( const timeval &  timeval) [inline]

Copy the time value from a timeval structure.

Parameters:
timevalthe storage to copy the time from.
Returns:
the number of copied octets.
size_t TimeVal::copy_out ( timeval &  timeval) const [inline]

Copy the time value to a timeval structure.

Parameters:
timevalthe storage to copy the time to.
Returns:
the number of copied octets.
double TimeVal::get_double ( ) const [inline]

Convert a TimeVal value to a double-float value.

Returns:
the double-float value of this TimeVal time.
bool TimeVal::is_zero ( ) const [inline]

Test if this time value is numerically zero.

Returns:
true if the address is numerically zero.
TimeVal TimeVal::operator* ( int  n) const [inline]

Multiplication Operator for integer operand.

Parameters:
nthe integer value used in multiplying the value of this object with.
Returns:
the TimeVal value of multiplying the value of this object by n.
TimeVal TimeVal::operator* ( unsigned int  n) const [inline]

Multiplication Operator for unsigned integer operand.

Parameters:
nthe unsigned integer value used in multiplying the value of this object with.
Returns:
the TimeVal value of multiplying the value of this object by n.
TimeVal TimeVal::operator* ( const double &  d) const [inline]

Multiplication Operator for double float operand.

Parameters:
dthe double float value used in multiplying the value of this object with.
Returns:
the TimeVal value of multiplying the value of this object by d.
TimeVal TimeVal::operator+ ( const TimeVal other) const [inline]

Addition Operator.

Parameters:
otherthe TimeVal value to add to the value of this TimeVal object.
Returns:
the TimeVal value after the addition of other.
const TimeVal & TimeVal::operator+= ( const TimeVal delta) [inline]

Assign-Sum Operator.

Parameters:
deltathe TimeVal value to add to this TimeVal object.
Returns:
the TimeVal value after the addition of delta.
TimeVal TimeVal::operator- ( const TimeVal other) const [inline]

Substraction Operator.

Parameters:
otherthe TimeVal value to substract from the value of this TimeVal object.
Returns:
the TimeVal value after the substraction of other.
const TimeVal & TimeVal::operator-= ( const TimeVal delta) [inline]

Assign-Difference Operator.

Parameters:
deltathe TimeVal value to substract from this TimeVal object.
Returns:
the TimeVal value after the substraction of delta.
TimeVal TimeVal::operator/ ( int  n) const [inline]

Division Operator for integer operand.

Parameters:
nthe integer value used in dividing the value of this object with.
Returns:
the TimeVal value of dividing the value of this object by n.
TimeVal TimeVal::operator/ ( unsigned int  n) const [inline]

Division Operator for unsigned integer operand.

Parameters:
nthe unsigned integer value used in dividing the value of this object with.
Returns:
the TimeVal value of dividing the value of this object by n.
TimeVal TimeVal::operator/ ( const double &  d) const [inline]

Division Operator for double-float operand.

Parameters:
dthe double-float value used in dividing the value of this object with.
Returns:
the TimeVal value of dividing the value of this object by d.
bool TimeVal::operator< ( const TimeVal other) const [inline]

Less-Than Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically smaller than the right-hand operand.
bool TimeVal::operator== ( const TimeVal other) const [inline]

Equality Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically same as the right-hand operand.
string TimeVal::pretty_print ( ) const

Pretty print the time.

Returns:
the time as formated by ctime(3) without the newline.
int32_t TimeVal::sec ( ) const [inline]

Get the number of seconds.

Returns:
the number of seconds.
string TimeVal::str ( ) const
Returns:
seconds and microseconds as a string.
int64_t TimeVal::to_ms ( ) const

Return an int64_t containing the total number of milliseconds in the underlying structure.

This is intended for convenience when working with Win32 APIs. XXX: This may overflow if _sec is too big.

Returns:
the number of milliseconds in total.
int32_t TimeVal::usec ( ) const [inline]

Get the number of microseconds.

Returns:
the number of microseconds.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations