GCC Code Coverage Report


Directory: ./
File: src/PTimer.cpp
Date: 2026-09-04 12:37:17
Exec Total Coverage
Lines: 36 43 83.7%
Functions: 11 14 78.6%
Branches: 3 5 60.0%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "PTimer.h"
8
9 ///Default constructor of PTimer
10 /** @param ellapsedTime : ellapsed time between two calls (in nanoseconds)
11 */
12 3 PTimer::PTimer(time_t ellapsedTime)
13 3 :p_startTime(0l),
14 3 p_ellapsedTime(ellapsedTime)
15 {
16 3 initialisationPTimer();
17 3 }
18
19 ///Copy constructor of PTimer
20 /** @param other : class to copy
21 */
22 1 PTimer::PTimer(const PTimer & other){
23 1 copyPTimer(other);
24 1 }
25
26 ///Move constructor
27 /** @param other : PTimer to be moved
28 */
29 PTimer::PTimer(PTimer && other) noexcept{
30 copyPTimer(other);
31 }
32
33 ///Move assignment operator
34 /** @param other : PTimer to be moved
35 @return reference to this PTimer
36 */
37 PTimer & PTimer::operator = (PTimer && other) noexcept{
38 if(this != &other){
39 copyPTimer(other);
40 }
41 return *this;
42 }
43
44 ///Destructor of PTimer
45 4 PTimer::~PTimer(){
46
47 4 }
48
49 ///Definition of equal operator of PTimer
50 /** @param other : class to copy
51 * @return copied class
52 */
53 1 PTimer & PTimer::operator = (const PTimer & other){
54 1 copyPTimer(other);
55 1 return *this;
56 }
57
58 ///Start the current clock
59 /** @param currentTime : current time
60 */
61 2 void PTimer::setStartTime(time_t currentTime){
62 2 p_startTime = currentTime;
63 2 }
64
65 ///Set the ellapsed time in nanoseconds
66 /** @param ellapsedTime : ellapsed time in nanoseconds
67 */
68 1 void PTimer::setEllapsedTime(time_t ellapsedTime){
69 1 p_ellapsedTime = ellapsedTime;
70 1 }
71
72 ///Get the ellapsed time in nanoseconds
73 /** @return ellapsed time in nanoseconds
74 */
75 2 time_t PTimer::getEllapsedTime() const{
76 2 return p_ellapsedTime;
77 }
78
79 ///Returns true if the given ellapsed time between to call is passed
80 /** @param currentTime : current time
81 * @return true if the given ellapsed time between to call is passed, false otherwise
82 */
83 2 bool PTimer::isTime(time_t currentTime){
84 2 time_t ellapsedTimeNs(0lu);
85
1/1
✓ Branch 0 (2→3) taken 2 times.
4 return isTime(ellapsedTimeNs, currentTime);
86 }
87
88 ///Returns true if the given ellapsed time between to call is passed
89 /** @param[out] ellapsedTimeNs : real ellapsed time in nanoseconds between the call of isTime and the last start of the PTimer (maybe in another isTime)
90 * @param currentTime : current time
91 * @return true if the given ellapsed time between to call is passed, false otherwise
92 */
93 2 bool PTimer::isTime(time_t & ellapsedTimeNs, time_t currentTime){
94 2 ellapsedTimeNs = currentTime - p_startTime;
95 2 bool b(ellapsedTimeNs >= p_ellapsedTime);
96
2/2
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→4) taken 1 times.
2 if(b){
97 1 setStartTime(currentTime);
98 }
99 2 return b;
100 }
101
102 ///Copy function of PTimer
103 /** @param other : class to copy
104 */
105 2 void PTimer::copyPTimer(const PTimer & other){
106 2 p_ellapsedTime = other.p_ellapsedTime;
107 2 p_startTime = other.p_startTime;
108 2 }
109
110 ///Initialisation function of the class PTimer
111 3 void PTimer::initialisationPTimer(){
112
113 3 }
114
115