23#include "pybind11/pybind11.h"
24#include "pybind11/stl.h"
32using namespace pybind11::literals;
41 using PyFlagDefinition = py::class_<FlagDefinition, std::shared_ptr<FlagDefinition>>;
42 wrappers.
wrapType(PyFlagDefinition(wrappers.module,
"FlagDefinition"), [](
auto &mod,
auto &cls) {
43 cls.def(py::init<>());
44 cls.def(py::init<std::string, std::string, std::size_t>(),
"name"_a,
"doc"_a,
45 "number"_a = FlagDefinition::number_undefined);
47 cls.def_readwrite(
"name", &FlagDefinition::name);
48 cls.def_readwrite(
"doc", &FlagDefinition::doc);
49 cls.def_readwrite(
"number", &FlagDefinition::number);
51 cls.def(
"__eq__", &FlagDefinition::operator==, py::is_operator());
52 cls.def(
"__ne__", &FlagDefinition::operator!=, py::is_operator());
57 using PyFlagDefinitionList = py::class_<FlagDefinitionList, std::shared_ptr<FlagDefinitionList>>;
58 wrappers.
wrapType(PyFlagDefinitionList(wrappers.module,
"FlagDefinitionList"), [](
auto &mod,
auto &cls) {
59 cls.def(py::init<>());
60 cls.def(py::init<std::initializer_list<FlagDefinition> const &>());
62 cls.def(
"__getitem__", [](FlagDefinitionList const &self, int i) {
64 auto cind = cpputils::python::cppIndex(self.size(), i);
66 } catch (pex::exceptions::OutOfRangeError &err) {
68 PyErr_SetString(PyExc_IndexError, err.what());
69 throw py::error_already_set();
75 cls.def(
"getDefinition",
76 (FlagDefinition(FlagDefinitionList::*)(
std::
size_t) const) &FlagDefinitionList::getDefinition,
78 cls.def(
"getDefinition",
79 (FlagDefinition(FlagDefinitionList::*)(
std::string const &) const) &
80 FlagDefinitionList::getDefinition,
89 using PyFlagHandler = py::class_<FlagHandler, std::shared_ptr<FlagHandler>>;
90 wrappers.
wrapType(PyFlagHandler(wrappers.module,
"FlagHandler"), [](
auto &mod,
auto &cls) {
91 cls.def(py::init<>());
92 cls.def(py::init<afw::table::SubSchema const &, FlagDefinitionList const &, FlagDefinitionList const &>(),
93 "s"_a,
"flagDefs"_a,
"exclDefs"_a = FlagDefinitionList::getEmptyList());
95 cls.def_static(
"getFailureFlagName", &FlagHandler::getFailureFlagName);
96 cls.def_static(
"addFields", &FlagHandler::addFields,
"schema"_a,
"prefix"_a,
"flagDefs"_a,
97 "exclDefs"_a = FlagDefinitionList::getEmptyList());
99 cls.def(
"getFlagNumber", &FlagHandler::getFlagNumber,
"flagName"_a);
100 cls.def(
"getFlagName", &FlagHandler::getFlagName,
"i"_a);
102 (bool (FlagHandler::*)(afw::table::BaseRecord const &, std::size_t) const) &
103 FlagHandler::getValue,
106 (bool (FlagHandler::*)(afw::table::BaseRecord const &, std::string const &) const) &
107 FlagHandler::getValue,
108 "record"_a,
"flagName"_a);
110 (void (FlagHandler::*)(afw::table::BaseRecord &, std::size_t, bool) const) &
111 FlagHandler::setValue,
112 "record"_a,
"i"_a,
"value"_a);
114 (void (FlagHandler::*)(afw::table::BaseRecord &, std::string const &, bool) const) &
115 FlagHandler::setValue,
116 "record"_a,
"flagName"_a,
"value"_a);
117 cls.def(
"getFailureFlagNumber", &FlagHandler::getFailureFlagNumber);
118 cls.def(
"handleFailure", &FlagHandler::handleFailure,
"record"_a,
"error"_a = nullptr);
125 declareFlagDefinition(wrappers);
126 declareFlagDefinitionList(wrappers);
127 declareFlagHandler(wrappers);
A helper class for subdividing pybind11 module across multiple translation units (i....
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
FlagDefinition add(std::string const &name, std::string const &doc)
Add a new FlagDefinition to this list.
static FlagDefinitionList const & getEmptyList()
std::size_t size() const
return the current size (number of defined elements) of the collection
FlagDefinition addFailureFlag(std::string const &doc="General Failure Flag")
Add a Flag Defintion to act as a "General" failure flag This flag will be set if a Measurement error ...
bool hasDefinition(std::string const &name) const
See if there is a FlagDefinition with specified name.
void wrapFlagHandler(WrapperCollection &)
decltype(sizeof(void *)) size_t