mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-14 05:47:14 +02:00
Nanosecond times in Python (#522)
* initital implementation * datetime replaces with sls::Duration in Python C bindings * using custom type caster * fix for conversion to seconds * added set_count in python * common header for pybind11 includes authored-by: Erik Frojdh <erik.frojdh@psi.ch>
This commit is contained in:
21
python/src/duration.cpp
Normal file
21
python/src/duration.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "py_headers.h"
|
||||
|
||||
#include "DurationWrapper.h"
|
||||
#include <sstream>
|
||||
namespace py = pybind11;
|
||||
using sls::DurationWrapper;
|
||||
|
||||
void init_duration(py::module &m) {
|
||||
py::class_<DurationWrapper>(m, "DurationWrapper")
|
||||
.def(py::init())
|
||||
.def(py::init<double>())
|
||||
.def("total_seconds", &DurationWrapper::total_seconds)
|
||||
.def("count", &DurationWrapper::count)
|
||||
.def("set_count", &DurationWrapper::set_count)
|
||||
.def("__repr__", [](const DurationWrapper &self) {
|
||||
std::stringstream ss;
|
||||
ss << "sls::DurationWrapper(total_seconds: " << self.total_seconds()
|
||||
<< " count: " << self.count() << ")";
|
||||
return ss.str();
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user