GCC Code Coverage Report


Directory: src/
File: Timer_binding.cpp
Date: 2026-02-24 19:19:46
Exec Total Coverage
Lines: 16 18 88.9%
Functions: 6 8 75.0%
Branches: 3 11 27.3%

Line Branch Exec Source
1 /***************************************
2 Auteur : Thibaut Oprinsen
3 Mail : thibaut.oprinsen@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "PTimer.h"
8 #include <ctime>
9 #include <nanobind/nanobind.h>
10 #include <nanobind/stl/string.h>
11 #include <nanobind/stl/chrono.h>
12
13 namespace nb = nanobind;
14
15
1/7
✓ Branch 0 (7→8) taken 1 times.
✗ Branch 1 (7→12) not taken.
✗ Branch 2 (16→17) not taken.
✗ Branch 3 (16→18) not taken.
✗ Branch 4 (16→23) not taken.
✗ Branch 5 (25→26) not taken.
✗ Branch 6 (25→27) not taken.
4 NB_MODULE(timer, m) {
16
2/4
✓ Branch 0 (2→3) taken 1 times.
✗ Branch 1 (2→189) not taken.
✓ Branch 2 (3→4) taken 1 times.
✗ Branch 3 (3→187) not taken.
1 m.doc() = "Nanobind bindings for Timer class";
17 1 nb::class_<PTimer>(m, "PTimer")
18
19 // Attribute
20 1 .def_prop_rw("ellapsedTime",
21 2 [](PTimer &timer) { return timer.getEllapsedTime(); },
22 [](PTimer &timer, time_t value) { timer.setEllapsedTime(value); },
23 "Get or set the ellapsed time between timer triggers")
24
25 // Constructors
26 1 .def(nb::init<time_t>(),
27 2 nb::arg("ellapsedTime") = 1lu,
28 "Constructor with custom ellapsedTime")
29
30 1 .def(nb::init<const PTimer &>(),
31 1 nb::arg("other"),
32 "Copy constructor")
33
34 // Timer configuration methods
35 2 .def("setStartTime", [](PTimer &timer, time_t startTime) {
36 1 timer.setStartTime(startTime);
37 1 },
38 "Set the start time for the timer")
39
40 // Timer checking methods
41 3 .def("isTime", [](PTimer &timer, time_t currentTime) -> bool {
42 2 return timer.isTime(currentTime);
43 },
44 "Check if the elapsed time has passed since start time")
45
46 1 .def("isTimeWithEllapsed", [](PTimer &timer, time_t ellapsedTime, time_t currentTime) -> bool {
47 return timer.isTime(ellapsedTime, currentTime);
48 },
49 "Check if time has elapsed and return (bool, elapsed_time_ns) tuple");
50 1 }
51