DeSiGNAR  0.5a
Data Structures General Library
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Designar::Now Class Reference

#include <now.H>

Public Types

enum  Precision {
  Precision::HOURS, Precision::MINUTES, Precision::SECONDS, Precision::MILLISECONDS,
  Precision::MICROSECONDS, Precision::NANOSECONDS
}
 Precision for timing. More...
 

Public Member Functions

 Now (bool start_now=false)
 Builds a new object with default values. More...
 
 Now (const Precision &_precision, bool start_now=false)
 Builds a new object with parametric precision time. More...
 
const Precisionget_precision () const
 
void set_precision (const Precision &_precision)
 
time_point_t start ()
 
double elapsed ()
 
double delta ()
 

Static Public Member Functions

static int to_int (Precision p)
 
static time_point_t current_time_point ()
 Gets the current time point. More...
 
static double compute_time_diff (const time_point_t &rtp, const time_point_t &ltp, const Precision &precision)
 
static double elapsed (const time_point_t &tp, const Precision &precision=Precision::MILLISECONDS)
 
static double delta (const time_point_t &tp, const Precision &precision=Precision::MILLISECONDS)
 

Detailed Description

Class Now is a practical class for timing based in a high resolution clock.

An instance of this class allows to measure elapsed time between two instants.

Usage example:

Now now;
now.start();
// Any block of code
cout << "Time elapsed: " << now.elapsed() << "ms\n";

Furthermore you may use the static methods just like that:

// Any block of code
cout << "Time elapsed: " << Now::elapsed(t) << "ms\n";
Author
Alejandro J. Mujica

Member Enumeration Documentation

Precision for timing.

Enumerator
HOURS 
MINUTES 
SECONDS 
MILLISECONDS 
MICROSECONDS 
NANOSECONDS 

Constructor & Destructor Documentation

Designar::Now::Now ( bool  start_now = false)
inline

Builds a new object with default values.

Builds a new object with default time point and precision in MILLISECONDS. You may set the object to start counting time immediately by setting the parameter start_now in true. This constructor can be used as parametric or default.

Parameters
start_nowIf true, then the object starts counting the time immediately. By default is false.
See also
Precision
Designar::Now::Now ( const Precision _precision,
bool  start_now = false 
)
inline

Builds a new object with parametric precision time.

Builds a new object with default time point and precision given as a parameter. You may set the object to start counting time immediately by setting the parameter start_now in true.

Parameters
_precisionThe type of precision for timing.
start_nowIf true, then the object starts counting the time immediately. By default is false.
See also
Precision

Member Function Documentation

static double Designar::Now::compute_time_diff ( const time_point_t rtp,
const time_point_t ltp,
const Precision precision 
)
inlinestatic

Calculates the time that has elapsed between two time points.

Parameters
rtpRight time point.
ltpLeft time point.
precisionType of precision for calculating the time.
Returns
The time calculated.
See also
Precision
static time_point_t Designar::Now::current_time_point ( )
inlinestatic

Gets the current time point.

double Designar::Now::delta ( )
inline

Like elapsed().

See also
elapsed().
static double Designar::Now::delta ( const time_point_t tp,
const Precision precision = Precision::MILLISECONDS 
)
inlinestatic

Like elapsed(const time_point_t & tp, const Precision & precision = MILLISECONDS).

See also
elapsed(const time_point_t & tp, const Precision & precision = MILLISECONDS)
double Designar::Now::elapsed ( )
inline

Calculates the time that has elapsed since the last time start(), elapsed() or delta() was called.

The value calculated depends of precision.

Returns
The time calculated.
See also
start(), delta(), Precision
static double Designar::Now::elapsed ( const time_point_t tp,
const Precision precision = Precision::MILLISECONDS 
)
inlinestatic

Calculates the time that has elapsed since a given time point.

This is a class method. It's useful when is required massive time calculations and is not desired massive object instances of Now.

Parameters
tpTime point from which you want to calculate.
precisionThe type of precision for timing, by default is MILLISECONDS.
Returns
The time calculated.
See also
Precision
const Precision& Designar::Now::get_precision ( ) const
inline

Gets the type of precision.

See also
Precision
void Designar::Now::set_precision ( const Precision _precision)
inline

Sets the type of precision.

See also
Precision
time_point_t Designar::Now::start ( )
inline

Sets internally the current time point.

This method must be used before calling elapsed() or delta() the first time.

Returns
The current time point.
See also
current_time_point()
static int Designar::Now::to_int ( Precision  p)
inlinestatic

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