LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
propertyList.cc
Go to the documentation of this file.
1 #include <cstddef>
2 #include "pybind11/pybind11.h"
3 #include "pybind11/stl.h"
4 
7 
8 namespace py = pybind11;
9 using namespace pybind11::literals;
10 
11 namespace lsst {
12 namespace daf {
13 namespace base {
14 namespace {
15 
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>,
20  "name"_a);
21  cls.def(getName.c_str(), (T (PropertyList::*)(std::string const&, T const&) const) & PropertyList::get<T>,
22  "name"_a, "defaultValue"_a);
23 
24  // Warning: __len__ is ambiguous so do not attempt to define it. It could return
25  // the number of unique names or the number of entries (e.g. as returned by toList,
26  // a pure Python method). C++ begin and end iterate over unique names, but users often
27  // view PropertyList as a representation of a FITS header. When in doubt, refuse to guess.
28 
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>,
32  "name"_a);
33 
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>);
43 
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>);
53 
54  const std::string typeName = "TYPE_" + name;
55  cls.attr(typeName.c_str()) = py::cast(typeid(T), py::return_value_policy::reference);
56 }
57 
58 } // namespace
59 
60 PYBIND11_MODULE(propertyList, mod) {
61  py::module::import("lsst.daf.base.persistable");
62 
63  py::class_<PropertyList, std::shared_ptr<PropertyList>, PropertySet> cls(mod, "PropertyList");
64 
65  cls.def(py::init<>());
66 
67  cls.def("getComment", &PropertyList::getComment);
68  cls.def("getOrderedNames", &PropertyList::getOrderedNames);
69  cls.def("deepCopy",
70  [](PropertyList const& self) { return std::static_pointer_cast<PropertySet>(self.deepCopy()); });
71  declareAccessors<bool>(cls, "Bool");
72  declareAccessors<short>(cls, "Short");
73  declareAccessors<int>(cls, "Int");
74  declareAccessors<long>(cls, "Long");
75  declareAccessors<long long>(cls, "LongLong");
76  declareAccessors<float>(cls, "Float");
77  declareAccessors<double>(cls, "Double");
78  declareAccessors<std::nullptr_t>(cls, "Undef");
79  declareAccessors<std::string>(cls, "String");
80  declareAccessors<DateTime>(cls, "DateTime");
81 
82  cls.def("setPropertySet",
83  (void (PropertyList::*)(std::string const&, PropertySet::Ptr const&)) & PropertyList::set);
84 }
85 
86 } // base
87 } // daf
88 } // lsst
table::Key< std::string > name
Definition: Amplifier.cc:116
Interface for DateTime class.
T c_str(T... args)
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68
Class for storing generic metadata.
Definition: PropertySet.h:66
daf::base::PropertySet * set
Definition: fits.cc:912
std::string const & getName() const noexcept
Return a filter's name.
Definition: Filter.h:78
PYBIND11_MODULE(propertyList, mod)
Definition: propertyList.cc:60
A base class for image defects.