Timestamp Class Reference

List of all members.

Detailed Description

Represents a moment or interval in time.

The Click Timestamp class represents both moments in time and intervals in time. In most Click code, Timestamp replaces the Unix "struct timeval" and "struct timespec" structures; for example, Timer expiry times use the Timestamp class. Timestamps may be added, subtracted, and compared using the usual operators.

Timestamp measures time in seconds using a fixed-point representation, like "struct timeval" and "struct timespec". Seconds and "subseconds", or fractions of a second, are stored in separate integers. Timestamps have either microsecond or nanosecond precision, depending on how Click is configured. Thus, one subsecond might equal either one microsecond or one nanosecond. The subsec_per_sec enumeration constant equals the number of subseconds in a second; the timestamp's subsec() value should always lie between 0 and subsec_per_sec - 1. (The --enable-nanotimestamp configuration option enables nanosecond-precision timestamps at user level; kernel modules always use microsecond-precision timestamps.)

A Timestamp with sec() < 0 is negative. Note that subsec() is always nonnegative. A Timestamp's value always equals (sec() + subsec() / (double) subsec_per_sec); thus, the Timestamp value of -0.1 is represented as sec() == -1, usec() == +900000.


Public Types

enum  {
  max_seconds = (seconds_type) 2147483647U, min_seconds = (seconds_type) -2147483648U, nsec_per_sec = 1000000000, nsec_per_msec = 1000000,
  nsec_per_usec = 1000, usec_per_sec = 1000000, usec_per_msec = 1000, msec_per_sec = 1000,
  subsec_per_sec = nsec_per_sec, subsec_per_msec = subsec_per_sec / msec_per_sec, subsec_per_usec = subsec_per_sec / usec_per_sec
}
enum  { NSUBSEC = subsec_per_sec }
typedef int32_t seconds_type
 Type represents a number of seconds.
typedef int32_t value_type
 Return type for msecval(), usecval(), and nsecval().
typedef seconds_type(Timestamp::*) unspecified_bool_type () const

Public Member Functions

 Timestamp ()
 Construct a zero-valued Timestamp.
 Timestamp (long sec, uint32_t subsec=0)
 Construct a Timestamp of sec seconds plus subsec subseconds.
 Timestamp (int sec, uint32_t subsec=0)
 Timestamp (unsigned long sec, uint32_t subsec=0)
 Timestamp (unsigned sec, uint32_t subsec=0)
 Timestamp (double)
 Create a timestamp measuring d seconds.
 Timestamp (const struct timeval &tv)
 Create a Timestamp measuring tv.
 Timestamp (const struct timespec &ts)
 Create a Timestamp measuring ts.
 Timestamp (const uninitialized_t &unused)
 Construct an uninitialized timestamp.
 operator unspecified_bool_type () const
 Return true iff this timestamp is not zero-valued.
seconds_type sec () const
uint32_t subsec () const
uint32_t msec () const
 Return this timestamp's subseconds component, converted to milliseconds.
uint32_t usec () const
 Return this timestamp's subseconds component, converted to microseconds.
uint32_t nsec () const
 Return this timestamp's subseconds component, converted to nanoseconds.
void set_sec (seconds_type sec)
 Set this timestamp's seconds component.
void set_subsec (uint32_t subsec)
 Set this timestamp's subseconds component.
seconds_type msec1 () const
 Return this timestamp's interval length, converted to milliseconds.
seconds_type usec1 () const
 Return this timestamp's interval length, converted to microseconds.
seconds_type nsec1 () const
 Return this timestamp's interval length, converted to nanoseconds.
timeval timeval () const
 Return a struct timeval with the same value as this timestamp.
timespec timespec () const
 Return a struct timespec with the same value as this timestamp.
double doubleval () const
 Return this timestamp's value, converted to a real number.
value_type msecval () const
 Return this timestamp's interval length in milliseconds.
value_type usecval () const
 Return this timestamp's interval length in microseconds.
value_type nsecval () const
 Return this timestamp's interval length in nanoseconds.
click_jiffies_t jiffies () const
 Return the number of jiffies represented by this timestamp.
void assign (seconds_type sec, uint32_t subsec=0)
void assign_usec (seconds_type sec, uint32_t usec)
void assign_nsec (seconds_type sec, uint32_t nsec)
void set (seconds_type sec, uint32_t subsec=0)
void set_usec (seconds_type sec, uint32_t usec)
void set_nsec (seconds_type sec, uint32_t nsec)
void set_now ()
 Set this timestamp to the current time.
String unparse () const
 Unparse this timestamp into a String.
String unparse_interval () const
 Unparse this timestamp into a String as an interval.

Static Public Member Functions

static Timestamp make_jiffies (click_jiffies_t jiffies)
 Return a timestamp representing jiffies.
static Timestamp make_sec (seconds_type sec)
 Return a timestamp representing sec seconds.
static Timestamp make_msec (seconds_type sec, uint32_t msec)
 Return a timestamp representing sec seconds plus msec milliseconds.
static Timestamp make_msec (value_type msec)
 Return a timestamp representing msec milliseconds.
static Timestamp make_usec (seconds_type sec, uint32_t usec)
 Return a timestamp representing sec seconds plus usec microseconds.
static Timestamp make_usec (value_type usec)
 Return a timestamp representing usec microseconds.
static Timestamp make_nsec (seconds_type sec, uint32_t nsec)
 Return a timestamp representing sec seconds plus nsec nanoseconds.
static Timestamp make_nsec (value_type nsec)
 Return a timestamp representing nsec nanoseconds.
static Timestamp now ()
 Return a timestamp representing the current time.
static Timestamp epsilon ()
 Return the smallest nonzero timestamp, Timestamp(0, 1).
static uint32_t msec_to_subsec (uint32_t msec)
 Convert milliseconds to subseconds.
static uint32_t usec_to_subsec (uint32_t usec)
 Convert microseconds to subseconds.
static uint32_t nsec_to_subsec (uint32_t nsec)
 Convert nanoseconds to subseconds.
static uint32_t subsec_to_msec (uint32_t subsec)
 Convert subseconds to milliseconds.
static uint32_t subsec_to_usec (uint32_t subsec)
 Convert subseconds to microseconds.
static uint32_t subsec_to_nsec (uint32_t subsec)
 Convert subseconds to nanoseconds.

Friends

bool operator== (const Timestamp &a, const Timestamp &b)
 Compare two timestamps for equality.
bool operator< (const Timestamp &a, const Timestamp &b)
 Compare two timestamps.
Timestamp operator- (const Timestamp &b)
 Negate a and return the result.
Timestampoperator+= (Timestamp &a, const Timestamp &b)
 Add b to a.
Timestampoperator-= (Timestamp &a, const Timestamp &b)
 Subtract b from a.

Related Functions

(Note that these are not member functions.)

bool operator!= (const Timestamp &a, const Timestamp &b)
 Compare two timestamps for inequality.
bool operator<= (const Timestamp &a, const Timestamp &b)
 Compare two timestamps.
bool operator>= (const Timestamp &a, const Timestamp &b)
 Compare two timestamps.
bool operator> (const Timestamp &a, const Timestamp &b)
 Compare two timestamps.
StringAccumoperator<< (StringAccum &sa, const Timestamp &ts)
 Append the unparsed representation of ts to sa.

Classes

struct  uninitialized_t


Member Typedef Documentation

typedef int32_t Timestamp::seconds_type

Type represents a number of seconds.

typedef int32_t Timestamp::value_type

Return type for msecval(), usecval(), and nsecval().


Member Enumeration Documentation

anonymous enum

Enumerator:
subsec_per_sec  Number of subseconds in a second. Can be 1000000 or 1000000000, depending on how Click is compiled.


Constructor & Destructor Documentation

Timestamp::Timestamp (  )  [inline]

Construct a zero-valued Timestamp.

Timestamp::Timestamp ( long  sec,
uint32_t  subsec = 0 
) [inline]

Construct a Timestamp of sec seconds plus subsec subseconds.

Parameters:
sec number of seconds
subsec number of subseconds (defaults to 0)
The subsec parameter must be between 0 and subsec_per_sec - 1, and the sec parameter must be between min_seconds and max_seconds . Errors are not necessarily checked.

Timestamp::Timestamp ( double   )  [inline]

Create a timestamp measuring d seconds.

Timestamp::Timestamp ( const struct timeval &  tv  )  [inline]

Create a Timestamp measuring tv.

Parameters:
tv timeval structure

Timestamp::Timestamp ( const struct timespec &  ts  )  [inline]

Create a Timestamp measuring ts.

Parameters:
ts timespec structure

Timestamp::Timestamp ( const uninitialized_t &  unused  )  [inline]

Construct an uninitialized timestamp.


Member Function Documentation

Timestamp::operator unspecified_bool_type (  )  const [inline]

Return true iff this timestamp is not zero-valued.

uint32_t Timestamp::msec (  )  const [inline]

Return this timestamp's subseconds component, converted to milliseconds.

uint32_t Timestamp::usec (  )  const [inline]

Return this timestamp's subseconds component, converted to microseconds.

uint32_t Timestamp::nsec (  )  const [inline]

Return this timestamp's subseconds component, converted to nanoseconds.

void Timestamp::set_sec ( seconds_type  sec  )  [inline]

Set this timestamp's seconds component.

The subseconds component is left unchanged.

void Timestamp::set_subsec ( uint32_t  subsec  )  [inline]

Set this timestamp's subseconds component.

Parameters:
subsec number of subseconds
The seconds component is left unchanged.

Timestamp::seconds_type Timestamp::msec1 (  )  const [inline]

Return this timestamp's interval length, converted to milliseconds.

Will overflow on intervals of more than 2147483.647 seconds.

Timestamp::seconds_type Timestamp::usec1 (  )  const [inline]

Return this timestamp's interval length, converted to microseconds.

Will overflow on intervals of more than 2147.483647 seconds.

Timestamp::seconds_type Timestamp::nsec1 (  )  const [inline]

Return this timestamp's interval length, converted to nanoseconds.

Will overflow on intervals of more than 2.147483647 seconds.

struct timeval Timestamp::timeval (  )  const [inline]

Return a struct timeval with the same value as this timestamp.

If Timestamp and struct timeval have the same size and representation, then this operation returns a "const struct timeval &" whose address is the same as this Timestamp.

struct timespec Timestamp::timespec (  )  const [inline]

Return a struct timespec with the same value as this timestamp.

If Timestamp and struct timespec have the same size and representation, then this operation returns a "const struct timespec &" whose address is the same as this Timestamp.

double Timestamp::doubleval (  )  const [inline]

Return this timestamp's value, converted to a real number.

value_type Timestamp::msecval (  )  const [inline]

Return this timestamp's interval length in milliseconds.

value_type Timestamp::usecval (  )  const [inline]

Return this timestamp's interval length in microseconds.

value_type Timestamp::nsecval (  )  const [inline]

Return this timestamp's interval length in nanoseconds.

Timestamp Timestamp::make_jiffies ( click_jiffies_t  jiffies  )  [inline, static]

Return a timestamp representing jiffies.

click_jiffies_t Timestamp::jiffies (  )  const [inline]

Return the number of jiffies represented by this timestamp.

static Timestamp Timestamp::make_sec ( seconds_type  sec  )  [inline, static]

Return a timestamp representing sec seconds.

static Timestamp Timestamp::make_msec ( seconds_type  sec,
uint32_t  msec 
) [inline, static]

Return a timestamp representing sec seconds plus msec milliseconds.

Precondition:
0 <= msec < 1000

static Timestamp Timestamp::make_msec ( value_type  msec  )  [inline, static]

Return a timestamp representing msec milliseconds.

static Timestamp Timestamp::make_usec ( seconds_type  sec,
uint32_t  usec 
) [inline, static]

Return a timestamp representing sec seconds plus usec microseconds.

Precondition:
0 <= usec < 1000000

static Timestamp Timestamp::make_usec ( value_type  usec  )  [inline, static]

Return a timestamp representing usec microseconds.

static Timestamp Timestamp::make_nsec ( seconds_type  sec,
uint32_t  nsec 
) [inline, static]

Return a timestamp representing sec seconds plus nsec nanoseconds.

Precondition:
0 <= nsec < 1000000000

static Timestamp Timestamp::make_nsec ( value_type  nsec  )  [inline, static]

Return a timestamp representing nsec nanoseconds.

Timestamp Timestamp::now (  )  [inline, static]

Return a timestamp representing the current time.

The current time is measured in seconds since January 1, 1970 GMT.

See also:
set_now()

static Timestamp Timestamp::epsilon (  )  [inline, static]

Return the smallest nonzero timestamp, Timestamp(0, 1).

void Timestamp::assign ( seconds_type  sec,
uint32_t  subsec = 0 
) [inline]

Set this timestamp to a seconds-and-subseconds value.

See also:
Timestamp(int, int)

void Timestamp::assign_usec ( seconds_type  sec,
uint32_t  usec 
) [inline]

Assign this timestamp to a seconds-and-microseconds value.

void Timestamp::assign_nsec ( seconds_type  sec,
uint32_t  nsec 
) [inline]

Assign this timestamp to a seconds-and-nanoseconds value.

void Timestamp::set ( seconds_type  sec,
uint32_t  subsec = 0 
) [inline]

Assign this timestamp to a seconds-and-subseconds value.

Deprecated:
Use assign() instead.

void Timestamp::set_usec ( seconds_type  sec,
uint32_t  usec 
) [inline]

Assign this timestamp to a seconds-and-microseconds value.

Deprecated:
Use assign_usec() instead.

void Timestamp::set_nsec ( seconds_type  sec,
uint32_t  nsec 
) [inline]

Assign this timestamp to a seconds-and-nanoseconds value.

Deprecated:
Use assign_nsec() instead.

void Timestamp::set_now (  )  [inline]

Set this timestamp to the current time.

The current time is measured in seconds since January 1, 1970 GMT. Returns the most precise timestamp available.

See also:
now()

String Timestamp::unparse (  )  const

Unparse this timestamp into a String.

Returns a string formatted like "10.000000", with at least six subsecond digits. (Nanosecond-precision timestamps where the number of nanoseconds is not evenly divisible by 1000 have nine subsecond digits.)

String Timestamp::unparse_interval (  )  const

Unparse this timestamp into a String as an interval.

Returns a string formatted like "1us" or "1.000002s".

static uint32_t Timestamp::msec_to_subsec ( uint32_t  msec  )  [inline, static]

Convert milliseconds to subseconds.

Subseconds are either microseconds or nanoseconds, depending on configuration options and driver choice.

See also:
usec_to_subsec(), nsec_to_subsec(), subsec_to_msec(), subsec_to_usec(), subsec_to_nsec()

static uint32_t Timestamp::usec_to_subsec ( uint32_t  usec  )  [inline, static]

Convert microseconds to subseconds.

static uint32_t Timestamp::nsec_to_subsec ( uint32_t  nsec  )  [inline, static]

Convert nanoseconds to subseconds.

static uint32_t Timestamp::subsec_to_msec ( uint32_t  subsec  )  [inline, static]

Convert subseconds to milliseconds.

static uint32_t Timestamp::subsec_to_usec ( uint32_t  subsec  )  [inline, static]

Convert subseconds to microseconds.

static uint32_t Timestamp::subsec_to_nsec ( uint32_t  subsec  )  [inline, static]

Convert subseconds to nanoseconds.


Friends And Related Function Documentation

bool operator== ( const Timestamp a,
const Timestamp b 
) [friend]

Compare two timestamps for equality.

Returns true iff the two operands have the same seconds and subseconds components.

bool operator< ( const Timestamp a,
const Timestamp b 
) [friend]

Compare two timestamps.

Returns true iff a represents a shorter interval than b, or considered as absolute time, a happened before b.

Timestamp operator- ( const Timestamp b  )  [friend]

Negate a and return the result.

Timestamp& operator+= ( Timestamp a,
const Timestamp b 
) [friend]

Add b to a.

Returns the result (the new value of a).

Timestamp& operator-= ( Timestamp a,
const Timestamp b 
) [friend]

Subtract b from a.

Returns the result (the new value of a).

bool operator!= ( const Timestamp a,
const Timestamp b 
) [related]

Compare two timestamps for inequality.

Returns true iff !(a == b).

bool operator<= ( const Timestamp a,
const Timestamp b 
) [related]

Compare two timestamps.

Returns true iff a measures an interval no larger than b, or considered as absolute time, a happened at or before b.

bool operator>= ( const Timestamp a,
const Timestamp b 
) [related]

Compare two timestamps.

Returns true iff a measures an interval no shorter than b, or considered as absolute time, a happened at or after b.

bool operator> ( const Timestamp a,
const Timestamp b 
) [related]

Compare two timestamps.

Returns true iff a measures a longer interval than b, or considered as absolute time, a happened after b.

StringAccum & operator<< ( StringAccum sa,
const Timestamp ts 
) [related]

Append the unparsed representation of ts to sa.

Same as sa << ts.unparse().


The documentation for this class was generated from the following files:
Generated on Sun Nov 9 18:12:46 2008 for Click by  doxygen 1.5.1