PhoenixClockMock  2.0.0
Tool to manipulate mock of clock (split, merge and get info)
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 
14 bool 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 
30 }
31 
33 
36  copyPClockMock(other);
37 }
38 
41  if(p_isRecordMode){
42  //Let's save the vector of times
44  }
45 }
46 
48 
52  copyPClockMock(other);
53  return *this;
54 }
55 
57 
59 time_t PClockMock::now(){
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()){
69  p_currentTimeIndex = 0lu;
70  }
71  time_t currentTime = p_vecTime[p_currentTimeIndex];
72  //Then we increment the current time index
74  return currentTime;
75 }
76 
78 
80 void 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 
91  p_vecTime = other.p_vecTime;
93 }
94 
97  p_isRecordMode = false;
98  p_currentTimeIndex = 0lu;
99 }
100 
101 
102 
103 
104 
bool phoenix_loadClockMock(VecTime &vecTime)
Load the Clock Mock.
Definition: PClockMock.cpp:22
bool phoenix_saveClockMock(const VecTime &vecTime)
Save the Clock Mock.
Definition: PClockMock.cpp:14
std::vector< time_t > VecTime
Definition: PClockMock.h:12
Mock of a clock.
Definition: PClockMock.h:15
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.
Definition: PClockMock.cpp:51
size_t p_currentTimeIndex
Index of the current time.
Definition: PClockMock.h:36
PClockMock()
Default constructor of PClockMock.
Definition: PClockMock.cpp:28
time_t now()
Get the mocked current time.
Definition: PClockMock.cpp:59
virtual ~PClockMock()
Destructor of PClockMock.
Definition: PClockMock.cpp:40
void setCurrentTime(time_t currentTime)
Set the current time to be recorded.
Definition: PClockMock.cpp:80
void copyPClockMock(const PClockMock &other)
Copy function of PClockMock.
Definition: PClockMock.cpp:89
void initialisationPClockMock()
Initialisation function of the class PClockMock.
Definition: PClockMock.cpp:96
bool data_load(FILE *iter, T &data)
Load data from a message.
Definition: data_file.h:39
bool data_save(FILE *iter, const T &data)
Save data in a message.
Definition: data_file.h:18