Click
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
timestamp.hh File Reference

The Timestamp class represents a moment or interval in time. More...

#include <click/glue.hh>
#include <click/type_traits.hh>
#include <click/integers.hh>

Go to the source code of this file.

Classes

class  Timestamp
 Represents a moment or interval in time. More...
 
union  Timestamp::rep_t
 Type of a Timestamp representation. More...
 
class  TimestampArg
 Parser class for timestamps. More...
 

Macros

#define TIMESTAMP_REP_LITTLE_ENDIAN   1
 
#define PRITIMESTAMP   "%d.%09d"
 
#define TIMESTAMP_DECLARE_TSP   struct timespec ts, &tsp = ts
 
#define TIMESTAMP_RESOLVE_TSP   assign(tsp.tv_sec, nsec_to_subsec(tsp.tv_nsec))
 
#define TIMESTAMP_DECLARE_TVP   struct timeval tv, &tvp = tv
 
#define TIMESTAMP_RESOLVE_TVP   assign(tvp.tv_sec, usec_to_subsec(tvp.tv_usec))
 

Functions

Timestamp operator+ (Timestamp a, const Timestamp &b)
 Add the two operands and return the result.
 
bool operator< (const Timestamp &a, int b)
 
bool operator<= (const Timestamp &a, int b)
 
bool operator>= (const Timestamp &a, int b)
 
bool operator> (const Timestamp &a, int b)
 
Timestamp & operator+= (Timestamp &a, const Timestamp &b)
 Add b to a.
 
Timestamp & operator-= (Timestamp &a, const Timestamp &b)
 Subtract b from a.
 
Timestamp operator- (Timestamp a, const Timestamp &b)
 Subtract b from a and return the result.
 
Timestamp operator- (const Timestamp &a)
 Negate a and return the result.
 
Timestamp operator* (const Timestamp &a, double b)
 Scale a by a factor of b and return the result.
 
Timestamp operator* (const Timestamp &a, int b)
 
Timestamp operator* (const Timestamp &a, unsigned b)
 
Timestamp operator* (double a, const Timestamp &b)
 
Timestamp operator* (int a, const Timestamp &b)
 
Timestamp operator* (unsigned a, const Timestamp &b)
 
Timestamp operator/ (const Timestamp &a, double b)
 Scale a down by a factor of b and return the result.
 
Timestamp operator/ (const Timestamp &a, int b)
 
Timestamp operator/ (const Timestamp &a, unsigned b)
 
double operator/ (const Timestamp &a, const Timestamp &b)
 Divide a by b and return the result.
 
StringAccum & operator<< (StringAccum &, const Timestamp &)
 
bool cp_time (const String &str, Timestamp *result, bool allow_negative)
 Parse a timestamp from str.
 

Variables

const ArgContext blank_args
 

Detailed Description

The Timestamp class represents a moment or interval in time.

Function Documentation

◆ operator+()

Timestamp operator+ ( Timestamp  a,
const Timestamp &  b 
)
inline

Add the two operands and return the result.

◆ operator<()

bool operator< ( const Timestamp &  a,
int  b 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator<=()

bool operator<= ( const Timestamp &  a,
int  b 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator>=()

bool operator>= ( const Timestamp &  a,
int  b 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator>()

bool operator> ( const Timestamp &  a,
int  b 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator+=()

Timestamp & operator+= ( Timestamp &  a,
const Timestamp &  b 
)
inline

Add b to a.

Returns the result (the new value of a).

◆ operator-=()

Timestamp & operator-= ( Timestamp &  a,
const Timestamp &  b 
)
inline

Subtract b from a.

Returns the result (the new value of a).

◆ operator-() [1/2]

Timestamp operator- ( Timestamp  a,
const Timestamp &  b 
)
inline

Subtract b from a and return the result.

◆ operator-() [2/2]

Timestamp operator- ( const Timestamp &  a)
inline

Negate a and return the result.

◆ operator*()

Timestamp operator* ( const Timestamp &  a,
double  b 
)
inline

Scale a by a factor of b and return the result.

◆ operator/() [1/2]

Timestamp operator/ ( const Timestamp &  a,
double  b 
)
inline

Scale a down by a factor of b and return the result.

◆ operator/() [2/2]

double operator/ ( const Timestamp &  a,
const Timestamp &  b 
)
inline

Divide a by b and return the result.

◆ cp_time()

bool cp_time ( const String &  str,
Timestamp *  result,
bool  allow_negative 
)

Parse a timestamp from str.

Parameters
strstring
[out]resultstores parsed result
allow_negativeallow negative timestamps if true
Returns
True if str parsed correctly, false otherwise.

Parses a timestamp from str. Timestamps are expressed as fractional amounts of seconds, usually measured in Unix time, such as "1189383079.180265331". The input format accepts the unit suffixes described at cp_seconds_as. If the string fully parses, then the resulting value is stored in *result and the function returns true. Otherwise, *result remains unchanged and the function returns false.

If a number is too large for result, then the maximum possible value is stored in result and the cp_errno variable is set to CPE_OVERFLOW; otherwise, cp_errno is set to CPE_FORMAT (unparsable) or CPE_OK (if all was well).

An overloaded version of this function is available for struct timeval result values.