1 #include "pybind11/pybind11.h" 2 #include "pybind11/stl.h" 8 namespace py = pybind11;
16 template <
typename T,
typename C>
17 void declareAccessors(C& cls, std::string
const& name) {
18 const std::string getName =
"get" + name;
19 cls.def(getName.c_str(), (T (PropertyList::*)(std::string
const&)
const) & PropertyList::get<T>,
21 cls.def(getName.c_str(), (T (PropertyList::*)(std::string
const&, T
const&)
const) & PropertyList::get<T>,
22 "name"_a,
"defaultValue"_a);
29 const std::string getArrayName =
"getArray" + name;
30 cls.def(getArrayName.c_str(),
31 (std::vector<T> (PropertyList::*)(std::string
const&)
const) & PropertyList::getArray<T>,
34 const std::string setName =
"set" + name;
35 cls.def(setName.c_str(), (void (PropertyList::*)(std::string
const&, T
const&)) & PropertyList::set<T>);
36 cls.def(setName.c_str(),
37 (void (PropertyList::*)(std::string
const&, std::vector<T>
const&)) & PropertyList::set<T>);
38 cls.def(setName.c_str(), (void (PropertyList::*)(std::string
const&, T
const&, std::string
const&)) &
39 PropertyList::set<T>);
40 cls.def(setName.c_str(),
41 (void (PropertyList::*)(std::string
const&, std::vector<T>
const&, std::string
const&)) &
42 PropertyList::set<T>);
44 const std::string addName =
"add" + name;
45 cls.def(addName.c_str(), (void (PropertyList::*)(std::string
const&, T
const&)) & PropertyList::add<T>);
46 cls.def(addName.c_str(),
47 (void (PropertyList::*)(std::string
const&, std::vector<T>
const&)) & PropertyList::add<T>);
48 cls.def(addName.c_str(), (void (PropertyList::*)(std::string
const&, T
const&, std::string
const&)) &
49 PropertyList::add<T>);
50 cls.def(addName.c_str(),
51 (void (PropertyList::*)(std::string
const&, std::vector<T>
const&, std::string
const&)) &
52 PropertyList::add<T>);
54 const std::string typeName =
"TYPE_" + name;
55 cls.attr(typeName.c_str()) = py::cast(
typeid(T), py::return_value_policy::reference);
61 py::module::import(
"lsst.daf.base.persistable");
63 py::module mod(
"propertyList");
65 py::class_<PropertyList, std::shared_ptr<PropertyList>,
PropertySet,
Citizen> cls(mod,
"PropertyList");
67 cls.def(py::init<>());
69 cls.def(
"getComment", &PropertyList::getComment);
70 cls.def(
"getOrderedNames", &PropertyList::getOrderedNames);
72 [](
PropertyList const&
self) {
return std::static_pointer_cast<PropertySet>(
self.deepCopy()); });
83 cls.def(
"__getstate__", [](
PropertyList const&
self) -> py::object {
85 py::reinterpret_borrow<py::object>(PyImport_ImportModule(
"lsst.daf.base.propertyContainer"));
87 throw py::error_already_set();
89 auto func = py::reinterpret_borrow<py::object>(PyObject_GetAttrString(module.ptr(),
"getstate"));
91 throw py::error_already_set();
93 auto pySelf = py::cast(
self);
94 auto result = py::reinterpret_steal<py::object>(
95 PyObject_CallFunctionObjArgs(func.ptr(), pySelf.ptr(), NULL));
101 cls.def(
"__setstate__", [](
PropertyList&
self, py::object state) {
107 py::reinterpret_borrow<py::object>(PyImport_ImportModule(
"lsst.daf.base.propertyContainer"));
109 throw py::error_already_set();
111 auto func = py::reinterpret_borrow<py::object>(PyObject_GetAttrString(module.ptr(),
"setstate"));
113 throw py::error_already_set();
115 auto pySelf = py::cast(
self);
116 auto result = py::reinterpret_steal<py::object>(
117 PyObject_CallFunctionObjArgs(func.ptr(), pySelf.ptr(), state.ptr(), NULL));
122 declareAccessors<bool>(cls,
"Bool");
123 declareAccessors<short>(cls,
"Short");
124 declareAccessors<int>(cls,
"Int");
125 declareAccessors<long>(cls,
"Long");
126 declareAccessors<long long>(cls,
"LongLong");
127 declareAccessors<float>(cls,
"Float");
128 declareAccessors<double>(cls,
"Double");
129 declareAccessors<std::string>(cls,
"String");
130 declareAccessors<DateTime>(cls,
"DateTime");
132 cls.def(
"setPropertySet",
std::shared_ptr< PropertySet > Ptr
Class for storing ordered metadata with comments.
Interface for PropertyList class.
PYBIND11_PLUGIN(propertyList)
Interface for DateTime class.
Class for storing generic metadata.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...