LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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.