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

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

#include <PTimer.h>

Public Member Functions

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

Protected Member Functions

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

Private Member Functions

void initialisationPTimer ()
 Initialisation function of the class PTimer.
 

Private Attributes

time_t p_ellapsedTime
 Ellapsed time between to isTime() returns true (in nanoseconds)
 
time_t p_startTime
 Clock of the PTimer.
 

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 ( time_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_startTime(0l),
14 p_ellapsedTime(ellapsedTime)
15{
17}
time_t p_ellapsedTime
Ellapsed time between to isTime() returns true (in nanoseconds)
Definition PTimer.h:37
void initialisationPTimer()
Initialisation function of the class PTimer.
Definition PTimer.cpp:93
time_t p_startTime
Clock of the PTimer.
Definition PTimer.h:35

References initialisationPTimer(), p_ellapsedTime, and p_startTime.

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

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

◆ PTimer() [2/2]

PTimer::PTimer ( const PTimer & other)

Copy constructor of PTimer.

Parameters
other: class to copy

Definition at line 22 of file PTimer.cpp.

22 {
23 copyPTimer(other);
24}
void copyPTimer(const PTimer &other)
Copy function of PTimer.
Definition PTimer.cpp:87

References copyPTimer(), and PTimer().

+ Here is the call graph for this function:

◆ ~PTimer()

PTimer::~PTimer ( )
virtual

Destructor of PTimer.

Definition at line 27 of file PTimer.cpp.

27 {
28
29}

Member Function Documentation

◆ copyPTimer()

void PTimer::copyPTimer ( const PTimer & other)
protected

Copy function of PTimer.

Parameters
other: class to copy

Definition at line 87 of file PTimer.cpp.

87 {
90}

References p_ellapsedTime, p_startTime, and PTimer().

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

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

◆ getEllapsedTime()

time_t PTimer::getEllapsedTime ( ) const

Get the ellapsed time in nanoseconds.

Returns
ellapsed time in nanoseconds

Definition at line 57 of file PTimer.cpp.

57 {
58 return p_ellapsedTime;
59}

References p_ellapsedTime.

◆ initialisationPTimer()

void PTimer::initialisationPTimer ( )
private

Initialisation function of the class PTimer.

Definition at line 93 of file PTimer.cpp.

93 {
94
95}

Referenced by PTimer().

+ Here is the caller graph for this function:

◆ isTime() [1/2]

bool PTimer::isTime ( time_t & ellapsedTimeNs,
time_t currentTime )

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)
currentTime: current time
Returns
true if the given ellapsed time between to call is passed, false otherwise

Definition at line 75 of file PTimer.cpp.

75 {
76 ellapsedTimeNs = currentTime - p_startTime;
77 bool b(ellapsedTimeNs >= p_ellapsedTime);
78 if(b){
79 setStartTime(currentTime);
80 }
81 return b;
82}
void setStartTime(time_t startTime)
Start the current clock.
Definition PTimer.cpp:43

References p_ellapsedTime, p_startTime, and setStartTime().

+ Here is the call graph for this function:

◆ isTime() [2/2]

bool PTimer::isTime ( time_t currentTime)

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

Parameters
currentTime: current time
Returns
true if the given ellapsed time between to call is passed, false otherwise

Definition at line 65 of file PTimer.cpp.

65 {
66 time_t ellapsedTimeNs(0lu);
67 return isTime(ellapsedTimeNs, currentTime);
68}
bool isTime(time_t currentTime)
Returns true if the given ellapsed time between to call is passed.
Definition PTimer.cpp:65

References isTime().

Referenced by isTime().

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

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

References copyPTimer(), and PTimer().

+ Here is the call graph for this function:

◆ setEllapsedTime()

void PTimer::setEllapsedTime ( time_t ellapsedTime)

Set the ellapsed time in nanoseconds.

Parameters
ellapsedTime: ellapsed time in nanoseconds

Definition at line 50 of file PTimer.cpp.

50 {
51 p_ellapsedTime = ellapsedTime;
52}

References p_ellapsedTime.

◆ setStartTime()

void PTimer::setStartTime ( time_t currentTime)

Start the current clock.

Parameters
currentTime: current time

Definition at line 43 of file PTimer.cpp.

43 {
44 p_startTime = currentTime;
45}

References p_startTime.

Referenced by isTime().

+ Here is the caller graph for this function:

Member Data Documentation

◆ p_ellapsedTime

time_t PTimer::p_ellapsedTime
private

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

Definition at line 37 of file PTimer.h.

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

◆ p_startTime

time_t PTimer::p_startTime
private

Clock of the PTimer.

Definition at line 35 of file PTimer.h.

Referenced by copyPTimer(), isTime(), PTimer(), and setStartTime().


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