20#include <nlohmann/json.hpp>
21#include <pybind11/cast.h>
28 auto &m = root_module;
32 py::class_<UnitSystem>(m,
"UnitSystem")
34 py::init([](
f64 unit_time,
41 return std::make_unique<UnitSystem>(
51 py::arg(
"unit_time") = 1,
52 py::arg(
"unit_length") = 1,
53 py::arg(
"unit_mass") = 1,
54 py::arg(
"unit_current") = 1,
55 py::arg(
"unit_temperature") = 1,
56 py::arg(
"unit_qte") = 1,
57 py::arg(
"unit_lumint") = 1)
60 [](UnitSystem &self, std::string name,
i32 power, std::string pref) {
68 py::arg(
"pref") =
"None")
71 [](UnitSystem &self, std::string name,
i32 power, std::string pref) {
79 py::arg(
"pref") =
"None"
84 [](UnitSystem &self) {
85 auto json_loads = py::module_::import(
"json").attr(
"loads");
86 nlohmann::json j = self;
87 return json_loads(j.dump());
89 "Converts the unit system to a json like dictionary")
92 [](UnitSystem &self,
const py::object &json_data) {
93 auto json_dumps = py::module_::import(
"json").attr(
"dumps");
94 std::string s = json_dumps(json_data).cast<std::string>();
95 self = nlohmann::json::parse(s).get<UnitSystem>();
97 "Sets the unit system from a json like dictionary");
99 py::class_<shamunits::Constants<f64>>(m,
"Constants")
100 .def(py::init([](UnitSystem s) {
101 return std::make_unique<shamunits::Constants<f64>>(s);
109 return sycl::pown(cte.st(), power); \
111 py::arg(
"power") = 1)
#define UNITS_CONSTANTS
X macro to list all constants conversion & bindings.
const UnitName unit_from_name(std::string p)
Get the UnitName enum value from a unit name as a string.
double f64
Alias for double.
std::int32_t i32
32 bit integer
UnitPrefix
Enum of all prefixes.
const UnitPrefix unit_prefix_from_name(std::string p)
Get the UnitPrefix enum value from a prefix name as a string.
Pybind11 include and definitions.
#define ON_PYTHON_INIT
Register a Python module init function using static initialization.
#define X
Temp definition for the X macro call to define the log levels.