PhoenixClockMock  2.0.0
Tool to manipulate mock of clock (split, merge and get info)
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) More...
 
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) More...
 
std::time_t getFullTimeNs () const
 Get the full time in nanoseconds. More...
 
std::time_t getOffsetTimeNs () const
 Get the offset in nanoseconds of the current clock. More...
 
PClockNsoperator= (const PClockNs &other)
 Definition of equal operator of PClockNs. More...
 
 PClockNs ()
 Default constructor of PClockNs. More...
 
 PClockNs (const PClockNs &other)
 Copy constructor of PClockNs. More...
 
void setOffsetTimeNs (std::time_t offsetTimeNs)
 Set the offset in nanoseconds of the current clock. More...
 
virtual ~PClockNs ()
 Destructor of PClockNs. More...
 

Protected Member Functions

void copyPClockNs (const PClockNs &other)
 Copy function of PClockNs. More...
 

Private Member Functions

void initialisationPClockNs ()
 Initialisation function of the class PClockNs. More...
 

Private Attributes

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

Detailed Description

Nanosecond clock.

Definition at line 16 of file PClockNs.h.

Member Typedef Documentation

◆ Nanosecond

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

Definition at line 19 of file PClockNs.h.

◆ SteadyClock

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

Definition at line 18 of file PClockNs.h.

◆ TimeNs

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

Definition at line 20 of file PClockNs.h.

Constructor & Destructor Documentation

◆ PClockNs() [1/2]

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:117

References initialisationPClockNs().

+ Here is the call graph for this function:

◆ PClockNs() [2/2]

PClockNs::PClockNs ( const PClockNs other)

Copy constructor of PClockNs.

Parameters
other: class to copy

Definition at line 50 of file PClockNs.cpp.

50  {
51  copyPClockNs(other);
52 }
void copyPClockNs(const PClockNs &other)
Copy function of PClockNs.
Definition: PClockNs.cpp:110

References copyPClockNs().

+ Here is the call graph for this function:

◆ ~PClockNs()

PClockNs::~PClockNs ( )
virtual

Destructor of PClockNs.

Definition at line 55 of file PClockNs.cpp.

55  {
56 
57 }

Member Function Documentation

◆ copyPClockNs()

void PClockNs::copyPClockNs ( const PClockNs other)
protected

Copy function of PClockNs.

Parameters
other: class to copy

Definition at line 110 of file PClockNs.cpp.

110  {
114 }
std::time_t p_baseSystemClockSecond
Base of the system clock in second.
Definition: PClockNs.h:42
std::time_t p_offsetTimeNs
Offset of time with date and nanoseconds.
Definition: PClockNs.h:46
TimeNs p_baseSteadyClockNs
Base clock time with a nanosecond precision but since the starting of the CPU.
Definition: PClockNs.h:44

References p_baseSteadyClockNs, p_baseSystemClockSecond, and p_offsetTimeNs.

Referenced by operator=(), and PClockNs().

+ Here is the caller graph for this function:

◆ 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 103 of file PClockNs.cpp.

103  {
105 }
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:85

References getFullTimeNs(), and phoenix_dateCompactNs().

Referenced by testPClockNs().

+ Here is the call graph for this function:
+ Here is the caller 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 96 of file PClockNs.cpp.

96  {
97  return phoenix_dateNs(getFullTimeNs());
98 }
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().

Referenced by testPClockNs().

+ Here is the call graph for this function:
+ Here is the caller 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 85 of file PClockNs.cpp.

85  {
86  //Let's get the time in nanoseconds since the start of the PClockNs
87  std::time_t ellapsedTimeNsSinceStart = (PClockNs::SteadyClock::now() - p_baseSteadyClockNs).count();
88 
89  std::time_t fullTimeNs = p_baseSystemClockSecond*1000000000l + ellapsedTimeNsSinceStart;
90  return fullTimeNs + p_offsetTimeNs;
91 }

References p_baseSteadyClockNs, p_baseSystemClockSecond, and p_offsetTimeNs.

Referenced by getDateCompactNs(), getDateNs(), PClockNsBackend::now(), testPClockNs(), and testPClockNsCoherence().

+ 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 78 of file PClockNs.cpp.

78  {
79  return p_offsetTimeNs;
80 }

References p_offsetTimeNs.

Referenced by testPClockNs().

+ Here is the caller graph for this function:

◆ initialisationPClockNs()

void PClockNs::initialisationPClockNs ( )
private

Initialisation function of the class PClockNs.

Definition at line 117 of file PClockNs.cpp.

117  {
118  p_baseSystemClockSecond = std::time(0);
119  p_baseSteadyClockNs = PClockNs::SteadyClock::now();
120  p_offsetTimeNs = 0l;
121 }

References p_baseSteadyClockNs, p_baseSystemClockSecond, and p_offsetTimeNs.

Referenced by PClockNs().

+ Here is the caller graph for this function:

◆ operator=()

PClockNs & PClockNs::operator= ( const PClockNs other)

Definition of equal operator of PClockNs.

Parameters
other: class to copy
Returns
copied class

Definition at line 63 of file PClockNs.cpp.

63  {
64  copyPClockNs(other);
65  return *this;
66 }

References copyPClockNs().

+ 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 71 of file PClockNs.cpp.

71  {
72  p_offsetTimeNs = offsetTimeNs;
73 }

References p_offsetTimeNs.

Referenced by testPClockNs().

+ Here is the caller graph for this function:

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 44 of file PClockNs.h.

Referenced by copyPClockNs(), getFullTimeNs(), and initialisationPClockNs().

◆ p_baseSystemClockSecond

std::time_t PClockNs::p_baseSystemClockSecond
private

Base of the system clock in second.

Definition at line 42 of file PClockNs.h.

Referenced by copyPClockNs(), getFullTimeNs(), and initialisationPClockNs().

◆ p_offsetTimeNs

std::time_t PClockNs::p_offsetTimeNs
private

Offset of time with date and nanoseconds.

Definition at line 46 of file PClockNs.h.

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


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