GridFire 0.0.1a General Purpose Nuclear Network

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 "bindings.h"
6
7 namespace py = pybind11;
8
9#include "gridfire/expectations/expectations.h"
10
11 void register_expectation_bindings(py::module &m) {
12 py::enum_<gridfire::expectations::EngineErrorTypes>(m, "EngineErrorTypes")
13 .value("FAILURE", gridfire::expectations::EngineErrorTypes::FAILURE)
14 .value("INDEX", gridfire::expectations::EngineErrorTypes::INDEX)
15 .value("STALE", gridfire::expectations::EngineErrorTypes::STALE)
16 .export_values();
17
18 py::enum_<gridfire::expectations::StaleEngineErrorTypes>(m, "StaleEngineErrorTypes")
19 .value("SYSTEM_RESIZED", gridfire::expectations::StaleEngineErrorTypes::SYSTEM_RESIZED)
20 .export_values();
21
22 // Bind the base class
23 py::class_<gridfire::expectations::EngineError>(m, "EngineError")
24 .def_readonly("message", &gridfire::expectations::EngineError::m_message)
25 .def_readonly("type", &gridfire::expectations::EngineError::type)
26 .def("__str__", [](const gridfire::expectations::EngineError &e) {return e.m_message;});
27
28 // Bind the EngineIndexError, specifying EngineError as the base
29 py::class_<gridfire::expectations::EngineIndexError, gridfire::expectations::EngineError>(m, "EngineIndexError")
30 .def(py::init<int>(), py::arg("index"))
31 .def_readonly("index", &gridfire::expectations::EngineIndexError::m_index)
32 .def("__str__", [](const gridfire::expectations::EngineIndexError &e) {
33 return e.m_message + " at index " + std::to_string(e.m_index);
34 });
35
36 // Bind the StaleEngineError, specifying EngineError as the base
37 py::class_<gridfire::expectations::StaleEngineError, gridfire::expectations::EngineError>(m, "StaleEngineError")
38 .def(py::init<gridfire::expectations::StaleEngineErrorTypes>(), py::arg("stale_type"))
39 .def_readonly("stale_type", &gridfire::expectations::StaleEngineError::staleType)
40 .def("__str__", [](const gridfire::expectations::StaleEngineError &e) {
41 return static_cast<std::string>(e);
42 });
43}
register_expectation_bindings
void register_expectation_bindings(py::module &m)
Definition bindings.cpp:11
bindings.h
expectations.h
gridfire::expectations::EngineErrorTypes::FAILURE
@ FAILURE
Definition expected_engine.h:8
gridfire::expectations::EngineErrorTypes::STALE
@ STALE
Definition expected_engine.h:10
gridfire::expectations::EngineErrorTypes::INDEX
@ INDEX
Definition expected_engine.h:9
gridfire::expectations::StaleEngineErrorTypes::SYSTEM_RESIZED
@ SYSTEM_RESIZED
Definition expected_engine.h:14
gridfire::expectations::EngineError
Definition expected_engine.h:18
gridfire::expectations::EngineError::type
const EngineErrorTypes type
Definition expected_engine.h:20
gridfire::expectations::EngineError::m_message
std::string m_message
Definition expected_engine.h:19
gridfire::expectations::EngineIndexError
Definition expected_engine.h:33
gridfire::expectations::EngineIndexError::m_index
int m_index
Definition expected_engine.h:34
gridfire::expectations::StaleEngineError
Definition expected_engine.h:44
gridfire::expectations::StaleEngineError::staleType
StaleEngineErrorTypes staleType
Definition expected_engine.h:45