PhoenixClock  2.2.0
Library wrapping the usage of system's clock, allowing to use clock mock-ups
Loading...
Searching...
No Matches
PClockNs Class Reference

Nanosecond clock. More...

#include <PClockNs.h>

Public Types

typedef std::chrono::nanoseconds Nanosecond
 
typedef std::chrono::steady_clock SteadyClock
 
typedef std::chrono::time_point< SteadyClockTimeNs
 

Public Member Functions

std::string getDateCompactNs () const
 Get the date at nanosecond precision (even if it is not precise at the nanosecond scale, it is normally coherent at this scale)
 
std::string getDateNs () const
 Get the date at nanosecond precision (even if it is not precise at the nanosecond scale, it is normally coherent at this scale)
 
std::time_t getFullTimeNs () const
 Get the full time in nanoseconds.
 
std::time_t getOffsetTimeNs () const
 Get the offset in nanoseconds of the current clock.
 
std::time_t now () const
 Get the full time in nanoseconds.
 
 PClockNs ()
 Default constructor of PClockNs.
 
void setOffsetTimeNs (std::time_t offsetTimeNs)
 Set the offset in nanoseconds of the current clock.
 
void sleep (EllapsedTime ellapsedTime) const
 Sleep for the given ellapsed time.
 
virtual ~PClockNs ()
 Destructor of PClockNs.
 

Private Member Functions

void initialisationPClockNs ()
 Initialisation function of the class PClockNs.
 

Private Attributes

TimeNs p_baseSteadyClockNs
 Base clock time with a nanosecond precision but since the starting of the CPU.
 
std::time_t p_baseSystemClockSecond
 Base of the system clock in second.
 
std::time_t p_offsetTimeNs
 Offset of time with date and nanoseconds.
 

Detailed Description

Nanosecond clock.

Definition at line 18 of file PClockNs.h.

Member Typedef Documentation

◆ Nanosecond

typedef std::chrono::nanoseconds PClockNs::Nanosecond

Definition at line 21 of file PClockNs.h.

◆ SteadyClock

typedef std::chrono::steady_clock PClockNs::SteadyClock

Definition at line 20 of file PClockNs.h.

◆ TimeNs

typedef std::chrono::time_point<SteadyClock> PClockNs::TimeNs

Definition at line 22 of file PClockNs.h.

Constructor & Destructor Documentation

◆ PClockNs()

PClockNs::PClockNs ( )

Default constructor of PClockNs.

Definition at line 43 of file PClockNs.cpp.

43 {
45}
void initialisationPClockNs()
Initialisation function of the class PClockNs.
Definition PClockNs.cpp:106

References initialisationPClockNs().

+ Here is the call graph for this function:

◆ ~PClockNs()

PClockNs::~PClockNs ( )
virtual

Destructor of PClockNs.

Definition at line 48 of file PClockNs.cpp.

48 {
49
50}

Member Function Documentation

◆ getDateCompactNs()

std::string PClockNs::getDateCompactNs ( ) const

Get the date at nanosecond precision (even if it is not precise at the nanosecond scale, it is normally coherent at this scale)

Returns
current date in printed in a more compact way

Definition at line 87 of file PClockNs.cpp.

87 {
89}
std::string phoenix_dateCompactNs(std::time_t currentDateNs)
Convert a given date in nanosecond into a text date in a more compact way.
Definition PClockNs.cpp:38
std::time_t getFullTimeNs() const
Get the full time in nanoseconds.
Definition PClockNs.cpp:69

References getFullTimeNs(), and phoenix_dateCompactNs().

+ Here is the call graph for this function:

◆ getDateNs()

std::string PClockNs::getDateNs ( ) const

Get the date at nanosecond precision (even if it is not precise at the nanosecond scale, it is normally coherent at this scale)

Returns
current date

Definition at line 80 of file PClockNs.cpp.

80 {
82}
std::string phoenix_dateNs(std::time_t currentDateNs, const char *format)
Convert a given date in nanosecond into a text date.
Definition PClockNs.cpp:15

References getFullTimeNs(), and phoenix_dateNs().

+ Here is the call graph for this function:

◆ getFullTimeNs()

std::time_t PClockNs::getFullTimeNs ( ) const

Get the full time in nanoseconds.

Returns
full time in nanoseconds

Definition at line 69 of file PClockNs.cpp.

69 {
70 //Let's get the time in nanoseconds since the start of the PClockNs
71 std::time_t ellapsedTimeNsSinceStart = (PClockNs::SteadyClock::now() - p_baseSteadyClockNs).count();
72
73 std::time_t fullTimeNs = p_baseSystemClockSecond*1000000000l + ellapsedTimeNsSinceStart;
74 return fullTimeNs + p_offsetTimeNs;
75}
std::time_t p_baseSystemClockSecond
Base of the system clock in second.
Definition PClockNs.h:39
std::time_t p_offsetTimeNs
Offset of time with date and nanoseconds.
Definition PClockNs.h:43
TimeNs p_baseSteadyClockNs
Base clock time with a nanosecond precision but since the starting of the CPU.
Definition PClockNs.h:41

References p_baseSteadyClockNs, p_baseSystemClockSecond, and p_offsetTimeNs.

Referenced by getDateCompactNs(), getDateNs(), and now().

+ Here is the caller graph for this function:

◆ getOffsetTimeNs()

std::time_t PClockNs::getOffsetTimeNs ( ) const

Get the offset in nanoseconds of the current clock.

Returns
offset in nanoseconds of the current clock

Definition at line 62 of file PClockNs.cpp.

62 {
63 return p_offsetTimeNs;
64}

References p_offsetTimeNs.

◆ initialisationPClockNs()

void PClockNs::initialisationPClockNs ( )
private

Initialisation function of the class PClockNs.

Definition at line 106 of file PClockNs.cpp.

106 {
107 p_baseSystemClockSecond = std::time(0);
108 p_baseSteadyClockNs = PClockNs::SteadyClock::now();
109 p_offsetTimeNs = 0l;
110}

References p_baseSteadyClockNs, p_baseSystemClockSecond, and p_offsetTimeNs.

Referenced by PClockNs().

+ Here is the caller graph for this function:

◆ now()

std::time_t PClockNs::now ( ) const

Get the full time in nanoseconds.

Returns
full time in nanoseconds

Definition at line 94 of file PClockNs.cpp.

94 {
95 return getFullTimeNs();
96}

References getFullTimeNs().

+ Here is the call graph for this function:

◆ setOffsetTimeNs()

void PClockNs::setOffsetTimeNs ( std::time_t offsetTimeNs)

Set the offset in nanoseconds of the current clock.

Parameters
offsetTimeNs: offset in nanoseconds of the current clock

Definition at line 55 of file PClockNs.cpp.

55 {
56 p_offsetTimeNs = offsetTimeNs;
57}

References p_offsetTimeNs.

◆ sleep()

void PClockNs::sleep ( EllapsedTime ellapsedTime) const

Sleep for the given ellapsed time.

Parameters
ellapsedTime: time to sleep in nanoseconds

Definition at line 101 of file PClockNs.cpp.

101 {
102 std::this_thread::sleep_for(std::chrono::nanoseconds(ellapsedTime));
103}

Member Data Documentation

◆ p_baseSteadyClockNs

TimeNs PClockNs::p_baseSteadyClockNs
private

Base clock time with a nanosecond precision but since the starting of the CPU.

Definition at line 41 of file PClockNs.h.

Referenced by getFullTimeNs(), and initialisationPClockNs().

◆ p_baseSystemClockSecond

std::time_t PClockNs::p_baseSystemClockSecond
private

Base of the system clock in second.

Definition at line 39 of file PClockNs.h.

Referenced by getFullTimeNs(), and initialisationPClockNs().

◆ p_offsetTimeNs

std::time_t PClockNs::p_offsetTimeNs
private

Offset of time with date and nanoseconds.

Definition at line 43 of file PClockNs.h.

Referenced by getFullTimeNs(), getOffsetTimeNs(), initialisationPClockNs(), and setOffsetTimeNs().


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