PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
PTimer Class Reference

Timer which allows to call function every time a defined ellapsed time is out. More...

#include <PTimer.h>

Public Member Functions

size_t getEllapsedTime () const
 Get the ellapsed time in nanoseconds. More...
 
bool isTime ()
 Returns true if the given ellapsed time between to call is passed. More...
 
bool isTime (size_t &ellapsedTimeNs)
 Returns true if the given ellapsed time between to call is passed. More...
 
PTimeroperator= (const PTimer &other)
 Definition of equal operator of PTimer. More...
 
 PTimer (const PTimer &other)
 Copy constructor of PTimer. More...
 
 PTimer (size_t ellapsedTime=1lu)
 Default constructor of PTimer. More...
 
void setEllapsedTime (size_t ellapsedTime)
 Set the ellapsed time in nanoseconds. More...
 
void start ()
 Start the current clock. More...
 
virtual ~PTimer ()
 Destructor of PTimer. More...
 

Protected Member Functions

void copyPTimer (const PTimer &other)
 Copy function of PTimer. More...
 

Private Member Functions

void initialisationPTimer ()
 Initialisation function of the class PTimer. More...
 

Private Attributes

size_t p_ellapsedTime
 Ellapsed time between to isTime() returns true (in nanoseconds) More...
 
std::chrono::time_point< std::chrono::steady_clock > p_startTime
 Clock of the PTimer. More...
 

Detailed Description

Timer which allows to call function every time a defined ellapsed time is out.

Definition at line 13 of file PTimer.h.

Constructor & Destructor Documentation

◆ PTimer() [1/2]

PTimer::PTimer ( size_t  ellapsedTime = 1lu)

Default constructor of PTimer.

Parameters
ellapsedTime: ellapsed time between two calls (in nanoseconds)

Definition at line 12 of file PTimer.cpp.

13  :p_ellapsedTime(ellapsedTime)
14 {
16 }

References initialisationPTimer().

+ Here is the call graph for this function:

◆ PTimer() [2/2]

PTimer::PTimer ( const PTimer other)

Copy constructor of PTimer.

Parameters
other: class to copy

Definition at line 21 of file PTimer.cpp.

21  {
22  copyPTimer(other);
23 }

References copyPTimer().

+ Here is the call graph for this function:

◆ ~PTimer()

PTimer::~PTimer ( )
virtual

Destructor of PTimer.

Definition at line 26 of file PTimer.cpp.

26  {
27 
28 }

Member Function Documentation

◆ copyPTimer()

void PTimer::copyPTimer ( const PTimer other)
protected

Copy function of PTimer.

Parameters
other: class to copy

Definition at line 83 of file PTimer.cpp.

83  {
85  p_startTime = other.p_startTime;
86 }

References p_ellapsedTime, and p_startTime.

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

+ Here is the caller graph for this function:

◆ getEllapsedTime()

size_t PTimer::getEllapsedTime ( ) const

Get the ellapsed time in nanoseconds.

Returns
ellapsed time in nanoseconds

Definition at line 54 of file PTimer.cpp.

54  {
55  return p_ellapsedTime;
56 }

References p_ellapsedTime.

Referenced by testPTimer().

+ Here is the caller graph for this function:

◆ initialisationPTimer()

void PTimer::initialisationPTimer ( )
private

Initialisation function of the class PTimer.

Definition at line 89 of file PTimer.cpp.

89  {
90  start();
91 }

References start().

Referenced by PTimer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isTime() [1/2]

bool PTimer::isTime ( )

Returns true if the given ellapsed time between to call is passed.

Returns
true if the given ellapsed time between to call is passed, false otherwise

Definition at line 61 of file PTimer.cpp.

61  {
62  size_t ellapsedTimeNs(0lu);
63  return isTime(ellapsedTimeNs);
64 }

Referenced by testPTimer().

+ Here is the caller graph for this function:

◆ isTime() [2/2]

bool PTimer::isTime ( size_t &  ellapsedTimeNs)

Returns true if the given ellapsed time between to call is passed.

Parameters
[out]ellapsedTimeNs: real ellapsed time in nanoseconds between the call of isTime and the last start of the PTimer (maybe in another isTime)
Returns
true if the given ellapsed time between to call is passed, false otherwise

Definition at line 70 of file PTimer.cpp.

70  {
71  std::chrono::nanoseconds ellapsedTime(std::chrono::steady_clock::now() - p_startTime);
72  ellapsedTimeNs = ellapsedTime.count();
73  bool b(ellapsedTimeNs >= p_ellapsedTime);
74  if(b){
75  start();
76  }
77  return b;
78 }

References p_ellapsedTime, p_startTime, and start().

+ Here is the call graph for this function:

◆ operator=()

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

Definition of equal operator of PTimer.

Parameters
other: class to copy
Returns
copied class

Definition at line 34 of file PTimer.cpp.

34  {
35  copyPTimer(other);
36  return *this;
37 }

References copyPTimer().

+ Here is the call graph for this function:

◆ setEllapsedTime()

void PTimer::setEllapsedTime ( size_t  ellapsedTime)

Set the ellapsed time in nanoseconds.

Parameters
ellapsedTime: ellapsed time in nanoseconds

Definition at line 47 of file PTimer.cpp.

47  {
48  p_ellapsedTime = ellapsedTime;
49 }

References p_ellapsedTime.

Referenced by testPTimer().

+ Here is the caller graph for this function:

◆ start()

void PTimer::start ( )

Start the current clock.

Definition at line 40 of file PTimer.cpp.

40  {
41  p_startTime = std::chrono::steady_clock::now();
42 }

References p_startTime.

Referenced by initialisationPTimer(), and isTime().

+ Here is the caller graph for this function:

Member Data Documentation

◆ p_ellapsedTime

size_t PTimer::p_ellapsedTime
private

Ellapsed time between to isTime() returns true (in nanoseconds)

Definition at line 41 of file PTimer.h.

Referenced by copyPTimer(), getEllapsedTime(), isTime(), and setEllapsedTime().

◆ p_startTime

std::chrono::time_point<std::chrono::steady_clock> PTimer::p_startTime
private

Clock of the PTimer.

Definition at line 39 of file PTimer.h.

Referenced by copyPTimer(), isTime(), and start().


The documentation for this class was generated from the following files:
PTimer::initialisationPTimer
void initialisationPTimer()
Initialisation function of the class PTimer.
Definition: PTimer.cpp:89
PTimer::isTime
bool isTime()
Returns true if the given ellapsed time between to call is passed.
Definition: PTimer.cpp:61
PTimer::copyPTimer
void copyPTimer(const PTimer &other)
Copy function of PTimer.
Definition: PTimer.cpp:83
PTimer::p_startTime
std::chrono::time_point< std::chrono::steady_clock > p_startTime
Clock of the PTimer.
Definition: PTimer.h:39
PTimer::p_ellapsedTime
size_t p_ellapsedTime
Ellapsed time between to isTime() returns true (in nanoseconds)
Definition: PTimer.h:41
PTimer::start
void start()
Start the current clock.
Definition: PTimer.cpp:40