PhoenixClock  2.6.0
Library wrapping the usage of system's clock, allowing to use clock mock-ups
Loading...
Searching...
No Matches
PTimer.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include "PTimer.h"
8
10
12PTimer::PTimer(time_t ellapsedTime)
13 :p_startTime(0l),
14 p_ellapsedTime(ellapsedTime)
15{
17}
18
20
22PTimer::PTimer(const PTimer & other){
23 copyPTimer(other);
24}
25
27
29PTimer::PTimer(PTimer && other) noexcept{
30 copyPTimer(other);
31}
32
34
37PTimer & PTimer::operator = (PTimer && other) noexcept{
38 if(this != &other){
39 copyPTimer(other);
40 }
41 return *this;
42}
43
48
50
54 copyPTimer(other);
55 return *this;
56}
57
59
61void PTimer::setStartTime(time_t currentTime){
62 p_startTime = currentTime;
63}
64
66
68void PTimer::setEllapsedTime(time_t ellapsedTime){
69 p_ellapsedTime = ellapsedTime;
70}
71
73
76 return p_ellapsedTime;
77}
78
80
83bool PTimer::isTime(time_t currentTime){
84 time_t ellapsedTimeNs(0lu);
85 return isTime(ellapsedTimeNs, currentTime);
86}
87
89
93bool PTimer::isTime(time_t & ellapsedTimeNs, time_t currentTime){
94 ellapsedTimeNs = currentTime - p_startTime;
95 bool b(ellapsedTimeNs >= p_ellapsedTime);
96 if(b){
97 setStartTime(currentTime);
98 }
99 return b;
100}
101
103
105void PTimer::copyPTimer(const PTimer & other){
107 p_startTime = other.p_startTime;
108}
109
114
time_t p_ellapsedTime
Ellapsed time between to isTime() returns true (in nanoseconds).
Definition PTimer.h:39
void setEllapsedTime(time_t ellapsedTime)
Set the ellapsed time in nanoseconds.
Definition PTimer.cpp:68
time_t getEllapsedTime() const
Get the ellapsed time in nanoseconds.
Definition PTimer.cpp:75
void setStartTime(time_t startTime)
Start the current clock.
Definition PTimer.cpp:61
PTimer(time_t ellapsedTime=1lu)
Default constructor of PTimer.
Definition PTimer.cpp:12
bool isTime(time_t currentTime)
Returns true if the given ellapsed time between to call is passed.
Definition PTimer.cpp:83
void initialisationPTimer()
Initialisation function of the class PTimer.
Definition PTimer.cpp:111
time_t p_startTime
Clock of the PTimer.
Definition PTimer.h:37
virtual ~PTimer()
Destructor of PTimer.
Definition PTimer.cpp:45
void copyPTimer(const PTimer &other)
Copy function of PTimer.
Definition PTimer.cpp:105
PTimer & operator=(const PTimer &other)
Definition of equal operator of PTimer.
Definition PTimer.cpp:53