GCC Code Coverage Report


Directory: src/
File: timer_binding.h
Date: 2026-03-03 09:43:10
Exec Total Coverage
Lines: 15 17 88.2%
Functions: 4 6 66.7%
Branches: 0 0 -%

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