PhoenixClock  0.4.0
Library wrapping the usage of system's clock, allowing to use clock mock-ups
Loading...
Searching...
No Matches
PClockMock.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
8#include "PClockMock.h"
9
11
14bool phoenix_saveClockMock(const VecTime & vecTime){
15 return data_save("clock.clockmock", vecTime);
16}
17
19
23 return data_load("clock.clockmock", vecTime);
24}
25
26
31
33
36 copyPClockMock(other);
37}
38
42 //Let's save the vector of times
44 }
45}
46
48
52 copyPClockMock(other);
53 return *this;
54}
55
57
60 //If we opened the proper mock file
61 if(p_vecTime.size() == 0lu){
63 std::cerr << "PClockMock::now : cannot load clock mock file 'clock.mock'" << std::endl;
64 return 0l;
65 }
66 }
67 //If the current time index is too high, we loop it
68 if(p_currentTimeIndex >= p_vecTime.size()){
70 }
71 time_t currentTime = p_vecTime[p_currentTimeIndex];
72 //Then we increment the current time index
74 return currentTime;
75}
76
78
80void PClockMock::setCurrentTime(time_t currentTime){
81 p_isRecordMode = true;
82 //Let's record the given time
83 p_vecTime.push_back(currentTime);
84}
85
87
94
100
101
102
103
104
bool phoenix_loadClockMock(VecTime &vecTime)
Load the Clock Mock.
bool phoenix_saveClockMock(const VecTime &vecTime)
Save the Clock Mock.
bool phoenix_loadClockMock(VecTime &vecTime)
Load the Clock Mock.
bool phoenix_saveClockMock(const VecTime &vecTime)
Save the Clock Mock.
std::vector< time_t > VecTime
Definition PClockMock.h:12
bool p_isRecordMode
True if the clock mock is in record mode.
Definition PClockMock.h:32
VecTime p_vecTime
Vector of recorded time.
Definition PClockMock.h:34
PClockMock & operator=(const PClockMock &other)
Definition of equal operator of PClockMock.
size_t p_currentTimeIndex
Index of the current time.
Definition PClockMock.h:36
PClockMock()
Default constructor of PClockMock.
time_t now()
Get the mocked current time.
virtual ~PClockMock()
Destructor of PClockMock.
void setCurrentTime(time_t currentTime)
Set the current time to be recorded.
void copyPClockMock(const PClockMock &other)
Copy function of PClockMock.
void initialisationPClockMock()
Initialisation function of the class PClockMock.