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

Mock of a clock. More...

#include <PClockMock.h>

Public Member Functions

time_t now ()
 Get the mocked current time.
 
PClockMockoperator= (const PClockMock &other)
 Definition of equal operator of PClockMock.
 
 PClockMock ()
 Default constructor of PClockMock.
 
 PClockMock (const PClockMock &other)
 Copy constructor of PClockMock.
 
void setCurrentTime (time_t currentTime)
 Set the current time to be recorded.
 
virtual ~PClockMock ()
 Destructor of PClockMock.
 

Protected Member Functions

void copyPClockMock (const PClockMock &other)
 Copy function of PClockMock.
 

Private Member Functions

void initialisationPClockMock ()
 Initialisation function of the class PClockMock.
 

Private Attributes

size_t p_currentTimeIndex
 Index of the current time.
 
bool p_isRecordMode
 True if the clock mock is in record mode.
 
VecTime p_vecTime
 Vector of recorded time.
 

Detailed Description

Mock of a clock.

Definition at line 15 of file PClockMock.h.

Constructor & Destructor Documentation

◆ PClockMock() [1/2]

PClockMock::PClockMock ( )

Default constructor of PClockMock.

Definition at line 28 of file PClockMock.cpp.

28 {
30}
void initialisationPClockMock()
Initialisation function of the class PClockMock.

References initialisationPClockMock().

Referenced by copyPClockMock(), operator=(), and PClockMock().

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

◆ PClockMock() [2/2]

PClockMock::PClockMock ( const PClockMock & other)

Copy constructor of PClockMock.

Parameters
other: class to copy

Definition at line 35 of file PClockMock.cpp.

35 {
36 copyPClockMock(other);
37}
void copyPClockMock(const PClockMock &other)
Copy function of PClockMock.

References copyPClockMock(), and PClockMock().

+ Here is the call graph for this function:

◆ ~PClockMock()

PClockMock::~PClockMock ( )
virtual

Destructor of PClockMock.

Definition at line 40 of file PClockMock.cpp.

40 {
42 //Let's save the vector of times
44 }
45}
bool phoenix_saveClockMock(const VecTime &vecTime)
Save the Clock Mock.
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

References p_isRecordMode, p_vecTime, and phoenix_saveClockMock().

+ Here is the call graph for this function:

Member Function Documentation

◆ copyPClockMock()

void PClockMock::copyPClockMock ( const PClockMock & other)
protected

Copy function of PClockMock.

Parameters
other: class to copy

Definition at line 89 of file PClockMock.cpp.

89 {
91 p_vecTime = other.p_vecTime;
93}
size_t p_currentTimeIndex
Index of the current time.
Definition PClockMock.h:36

References p_currentTimeIndex, p_isRecordMode, p_vecTime, and PClockMock().

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

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

◆ initialisationPClockMock()

void PClockMock::initialisationPClockMock ( )
private

Initialisation function of the class PClockMock.

Definition at line 96 of file PClockMock.cpp.

96 {
97 p_isRecordMode = false;
99}

References p_currentTimeIndex, and p_isRecordMode.

Referenced by PClockMock().

+ Here is the caller graph for this function:

◆ now()

time_t PClockMock::now ( )

Get the mocked current time.

Returns
mocked current time

Definition at line 59 of file PClockMock.cpp.

59 {
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}
bool phoenix_loadClockMock(VecTime &vecTime)
Load the Clock Mock.

References p_currentTimeIndex, p_vecTime, and phoenix_loadClockMock().

+ Here is the call graph for this function:

◆ operator=()

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

Definition of equal operator of PClockMock.

Parameters
other: class to copy
Returns
copied class

Definition at line 51 of file PClockMock.cpp.

51 {
52 copyPClockMock(other);
53 return *this;
54}

References copyPClockMock(), and PClockMock().

+ Here is the call graph for this function:

◆ setCurrentTime()

void PClockMock::setCurrentTime ( time_t currentTime)

Set the current time to be recorded.

Parameters
currentTime: current time to be recorded

Definition at line 80 of file PClockMock.cpp.

80 {
81 p_isRecordMode = true;
82 //Let's record the given time
83 p_vecTime.push_back(currentTime);
84}

References p_isRecordMode, and p_vecTime.

Member Data Documentation

◆ p_currentTimeIndex

size_t PClockMock::p_currentTimeIndex
private

Index of the current time.

Definition at line 36 of file PClockMock.h.

Referenced by copyPClockMock(), initialisationPClockMock(), and now().

◆ p_isRecordMode

bool PClockMock::p_isRecordMode
private

True if the clock mock is in record mode.

Definition at line 32 of file PClockMock.h.

Referenced by copyPClockMock(), initialisationPClockMock(), setCurrentTime(), and ~PClockMock().

◆ p_vecTime

VecTime PClockMock::p_vecTime
private

Vector of recorded time.

Definition at line 34 of file PClockMock.h.

Referenced by copyPClockMock(), now(), setCurrentTime(), and ~PClockMock().


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