23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
32 using namespace pybind11::literals;
41 py::class_<FlagDefinition, std::shared_ptr<FlagDefinition>>
cls(mod,
"FlagDefinition");
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);
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());
55 void declareFlagDefinitionList(
py::module &mod) {
56 py::class_<FlagDefinitionList, std::shared_ptr<FlagDefinitionList>>
cls(mod,
"FlagDefinitionList");
58 cls.def(py::init<>());
61 cls.def(
"__getitem__", [](FlagDefinitionList
const &
self,
int i) {
65 }
catch (pex::exceptions::OutOfRangeError &err) {
67 PyErr_SetString(PyExc_IndexError, err.what());
68 throw py::error_already_set();
71 cls.def(
"__len__", &FlagDefinitionList::size);
73 cls.def(
"getEmptyList", &FlagDefinitionList::getEmptyList);
74 cls.def(
"getDefinition",
75 (FlagDefinition(FlagDefinitionList::*)(
std::size_t)
const) & FlagDefinitionList::getDefinition,
77 cls.def(
"getDefinition",
78 (FlagDefinition(FlagDefinitionList::*)(
std::string const &)
const) &
79 FlagDefinitionList::getDefinition,
81 cls.def(
"hasDefinition", &FlagDefinitionList::hasDefinition,
"name"_a);
82 cls.def(
"addFailureFlag", &FlagDefinitionList::addFailureFlag,
"doc"_a =
"General Failure Flag");
83 cls.def(
"add", &FlagDefinitionList::add,
"name"_a,
"doc"_a);
87 py::class_<FlagHandler, std::shared_ptr<FlagHandler>>
cls(mod,
"FlagHandler");
89 cls.def(py::init<>());
90 cls.def(py::init<afw::table::SubSchema const &, FlagDefinitionList const &, FlagDefinitionList const &>(),
91 "s"_a,
"flagDefs"_a,
"exclDefs"_a = FlagDefinitionList::getEmptyList());
93 cls.def_static(
"getFailureFlagName", &FlagHandler::getFailureFlagName);
94 cls.def_static(
"addFields", &FlagHandler::addFields,
"schema"_a,
"prefix"_a,
"flagDefs"_a,
95 "exclDefs"_a = FlagDefinitionList::getEmptyList());
97 cls.def(
"getFlagNumber", &FlagHandler::getFlagNumber,
"flagName"_a);
98 cls.def(
"getFlagName", &FlagHandler::getFlagName,
"i"_a);
100 (
bool (FlagHandler::*)(afw::table::BaseRecord
const &,
std::size_t)
const) &
101 FlagHandler::getValue,
104 (
bool (FlagHandler::*)(afw::table::BaseRecord
const &,
std::string const &)
const) &
105 FlagHandler::getValue,
106 "record"_a,
"flagName"_a);
108 (
void (FlagHandler::*)(afw::table::BaseRecord &,
std::size_t,
bool)
const) &
109 FlagHandler::setValue,
110 "record"_a,
"i"_a,
"value"_a);
112 (
void (FlagHandler::*)(afw::table::BaseRecord &,
std::string const &,
bool)
const) &
113 FlagHandler::setValue,
114 "record"_a,
"flagName"_a,
"value"_a);
115 cls.def(
"getFailureFlagNumber", &FlagHandler::getFailureFlagNumber);
116 cls.def(
"handleFailure", &FlagHandler::handleFailure,
"record"_a,
"error"_a =
nullptr);
122 py::module::import(
"lsst.afw.table");
124 declareFlagDefinition(mod);
125 declareFlagDefinitionList(mod);
126 declareFlagHandler(mod);