LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
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
8namespace py = pybind11;
9using namespace pybind11::literals;
10
11namespace lsst {
12namespace daf {
13namespace base {
14namespace {
15
16template <typename T, typename C>
17void 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
60PYBIND11_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
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.
std::string const & getComment(std::string const &name) const
Get the comment for a string property name (possibly hierarchical).
Definition: PropertyList.cc:78
std::vector< std::string > getOrderedNames() const
Get the list of property names, in the order they were added.
Definition: PropertyList.cc:82
Class for storing generic metadata.
Definition: PropertySet.h:66
PYBIND11_MODULE(dateTime, mod)
Definition: dateTime.cc:12
A base class for image defects.