SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
bindings.cpp
Go to the documentation of this file.
1#include <pybind11/pybind11.h>
2#include <pybind11/stl.h> // Needed for vectors, maps, sets, strings
3#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc if needed directly
4
5#include <string>
6#include "const.h"
7#include "bindings.h"
8
9namespace py = pybind11;
10
11
12void register_const_bindings(pybind11::module &const_submodule) {
13 py::class_<serif::constant::Constant>(const_submodule, "Constant")
14 .def_readonly("name", &serif::constant::Constant::name)
15 .def_readonly("value", &serif::constant::Constant::value)
16 .def_readonly("uncertainty", &serif::constant::Constant::uncertainty)
17 .def_readonly("unit", &serif::constant::Constant::unit)
18 .def_readonly("reference", &serif::constant::Constant::reference)
19 .def("__repr__", [](const serif::constant::Constant &c) {
20 return "<Constant(name='" + c.name + "', value=" + std::to_string(c.value) +
21 ", uncertainty=" + std::to_string(c.uncertainty) +
22 ", unit='" + c.unit + "')>";
23 });
24
25 py::class_<serif::constant::Constants>(const_submodule, "Constants")
26 .def_property_readonly("loaded", &serif::constant::Constants::isLoaded)
27 .def_static("get",
28 [](const std::string &name) {
29 return py::cast(
31 );
32 },
33 "Get a constant by name. Returns None if not found."
34 )
35 .def_static("has",
36 [](const std::string &name) {
38 },
39 "Check if a constant exists by name.")
40 .def_static("keys",
41 []() {
42 return py::cast(
44 );
45 },
46 "Get a list of all constant names.")
47 .def_static("__class_getitem__",
48 [](const std::string &name) {
49 return py::cast(
51 );
52 });
53
54}
bool has(const std::string &key) const
Check if a constant exists by key.
Definition const.cpp:55
static Constants & getInstance()
get instance of constants singleton
Definition const.h:99
bool isLoaded() const
Check if constants are loaded.
Definition const.h:108
void register_const_bindings(pybind11::module &const_submodule)
Definition bindings.cpp:12
Structure to hold a constant's details.
Definition const.h:31
const std::string unit
Unit of the constant.
Definition const.h:35
const double uncertainty
Uncertainty in the constant's value.
Definition const.h:34
const std::string name
Name of the constant.
Definition const.h:32
const std::string reference
Reference for the constant's value.
Definition const.h:36
const double value
Value of the constant.
Definition const.h:33