LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
propertyList.cc
Go to the documentation of this file.
1#include <cstddef>
2#include "pybind11/pybind11.h"
3#include "pybind11/stl.h"
5
8
9namespace py = pybind11;
10using namespace pybind11::literals;
11
12namespace lsst {
13namespace daf {
14namespace base {
15namespace {
16
17template <typename T, typename C>
18void declareAccessors(C& cls, std::string const& name) {
19 const std::string getName = "get" + name;
20 cls.def(getName.c_str(), (T (PropertyList::*)(std::string const&) const) & PropertyList::get<T>,
21 "name"_a);
22 cls.def(getName.c_str(), (T (PropertyList::*)(std::string const&, T const&) const) & PropertyList::get<T>,
23 "name"_a, "defaultValue"_a);
24
25 // Warning: __len__ is ambiguous so do not attempt to define it. It could return
26 // the number of unique names or the number of entries (e.g. as returned by toList,
27 // a pure Python method). C++ begin and end iterate over unique names, but users often
28 // view PropertyList as a representation of a FITS header. When in doubt, refuse to guess.
29
30 const std::string getArrayName = "getArray" + name;
31 cls.def(getArrayName.c_str(),
32 (std::vector<T> (PropertyList::*)(std::string const&) const) & PropertyList::getArray<T>,
33 "name"_a);
34
35 const std::string setName = "set" + name;
36 cls.def(setName.c_str(), (void (PropertyList::*)(std::string const&, T const&)) & PropertyList::set<T>);
37 cls.def(setName.c_str(),
38 (void (PropertyList::*)(std::string const&, std::vector<T> const&)) & PropertyList::set<T>);
39 cls.def(setName.c_str(), (void (PropertyList::*)(std::string const&, T const&, std::string const&)) &
40 PropertyList::set<T>);
41 cls.def(setName.c_str(),
42 (void (PropertyList::*)(std::string const&, std::vector<T> const&, std::string const&)) &
43 PropertyList::set<T>);
44
45 const std::string addName = "add" + name;
46 cls.def(addName.c_str(), (void (PropertyList::*)(std::string const&, T const&)) & PropertyList::add<T>);
47 cls.def(addName.c_str(),
48 (void (PropertyList::*)(std::string const&, std::vector<T> const&)) & PropertyList::add<T>);
49 cls.def(addName.c_str(), (void (PropertyList::*)(std::string const&, T const&, std::string const&)) &
50 PropertyList::add<T>);
51 cls.def(addName.c_str(),
52 (void (PropertyList::*)(std::string const&, std::vector<T> const&, std::string const&)) &
53 PropertyList::add<T>);
54
55 const std::string typeName = "TYPE_" + name;
56 cls.attr(typeName.c_str()) = py::cast(typeid(T), py::return_value_policy::reference);
57}
58
59} // namespace
60
62 using PyPropertyList = py::class_<PropertyList, std::shared_ptr<PropertyList>, PropertySet>;
63 wrappers.wrapType(PyPropertyList(wrappers.module, "PropertyList"), [](auto &mod, auto &cls) {
64 cls.def(py::init<>());
65
66 cls.def("getComment", &PropertyList::getComment);
67 cls.def("getOrderedNames", &PropertyList::getOrderedNames);
68 cls.def("deepCopy",
69 [](PropertyList const &self) { return std::static_pointer_cast<PropertySet>(self.deepCopy()); });
70 declareAccessors<bool>(cls, "Bool");
71 declareAccessors<short>(cls, "Short");
72 declareAccessors<int>(cls, "Int");
73 declareAccessors<long>(cls, "Long");
74 declareAccessors<long long>(cls, "LongLong");
75 declareAccessors<float>(cls, "Float");
76 declareAccessors<double>(cls, "Double");
77 declareAccessors<std::nullptr_t>(cls, "Undef");
78 declareAccessors<std::string>(cls, "String");
79 declareAccessors<DateTime>(cls, "DateTime");
80
81 cls.def("setPropertySet",
82 (void (PropertyList::*)(std::string const &, PropertySet::Ptr const &)) &PropertyList::set);
83 });
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)
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
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...
Definition python.h:391
Class for storing ordered metadata with comments.
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.
Class for storing generic metadata.
Definition PropertySet.h:66
daf::base::PropertySet * set
Definition fits.cc:931
void wrapPropertyList(WrapperCollection &wrappers)
STL namespace.