Erik Fröjdh 045a28b5de
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>
2022-08-26 11:48:40 +02:00

22 lines
710 B
C++

#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();
});
}