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
propertySet.cc
Go to the documentation of this file.
1 #include "pybind11/pybind11.h"
2 #include "pybind11/stl.h"
3 
4 #include <cstddef>
5 #include <string>
6 #include <typeinfo>
7 
10 
11 namespace py = pybind11;
12 using namespace pybind11::literals;
13 
14 namespace lsst {
15 namespace daf {
16 namespace base {
17 namespace {
18 
19 template <typename T, typename C>
20 void declareAccessors(C& cls, std::string const& name) {
21  const std::string getName = "get" + name;
22  cls.def(getName.c_str(), (T (PropertySet::*)(std::string const&) const) & PropertySet::get<T>, "name"_a);
23  cls.def(getName.c_str(), (T (PropertySet::*)(std::string const&, T const&) const) & PropertySet::get<T>,
24  "name"_a, "defaultValue"_a);
25 
26  const std::string getArrayName = "getArray" + name;
27  cls.def(getArrayName.c_str(),
28  (std::vector<T> (PropertySet::*)(std::string const&) const) & PropertySet::getArray<T>, "name"_a);
29 
30  const std::string setName = "set" + name;
31  cls.def(setName.c_str(), (void (PropertySet::*)(std::string const&, T const&)) & PropertySet::set<T>,
32  "name"_a, "value"_a);
33  cls.def(setName.c_str(),
34  (void (PropertySet::*)(std::string const&, std::vector<T> const&)) & PropertySet::set<T>,
35  "name"_a, "value"_a);
36 
37  const std::string addName = "add" + name;
38  cls.def(addName.c_str(), (void (PropertySet::*)(std::string const&, T const&)) & PropertySet::add<T>,
39  "name"_a, "value"_a);
40  cls.def(addName.c_str(),
41  (void (PropertySet::*)(std::string const&, std::vector<T> const&)) & PropertySet::add<T>,
42  "name"_a, "value"_a);
43 
44  const std::string typeName = "TYPE_" + name;
45  cls.attr(typeName.c_str()) = py::cast(PropertySet::typeOfT<T>(), py::return_value_policy::reference);
46 }
47 
48 } // <anonymous>
49 
50 PYBIND11_MODULE(propertySet, mod) {
51  py::module::import("lsst.daf.base.persistable");
52 
53  py::class_<std::type_info>(mod, "TypeInfo")
54  .def("__eq__",
55  [](std::type_info const& self, std::type_info const& other) { return self == other; })
56  .def("__ne__",
57  [](std::type_info const& self, std::type_info const& other) { return self != other; })
58  .def("name", &std::type_info::name)
59  .def("__hash__", &std::type_info::hash_code);
60 
61  py::class_<PropertySet, std::shared_ptr<PropertySet>> cls(mod, "PropertySet");
62 
63  cls.def(py::init<bool>(), "flat"_a = false);
64 
65  cls.def("deepCopy", &PropertySet::deepCopy);
66  cls.def("nameCount", &PropertySet::nameCount, "topLevelOnly"_a = true);
67  cls.def("names", &PropertySet::names, "topLevelOnly"_a = true);
68  cls.def("paramNames", &PropertySet::paramNames, "topLevelOnly"_a = true);
69  cls.def("propertySetNames", &PropertySet::propertySetNames, "topLevelOnly"_a = true);
70  cls.def("exists", &PropertySet::exists);
71  cls.def("isArray", &PropertySet::isArray);
72  cls.def("isUndefined", &PropertySet::isUndefined);
73  cls.def("isPropertySetPtr", &PropertySet::isPropertySetPtr);
74  cls.def("valueCount",
75  py::overload_cast<>(&PropertySet::valueCount, py::const_));
76  cls.def("valueCount",
77  py::overload_cast<std::string const&>(&PropertySet::valueCount,
78  py::const_));
79  cls.def("typeOf", &PropertySet::typeOf, py::return_value_policy::reference);
80  cls.def("toString", &PropertySet::toString, "topLevelOnly"_a = false, "indent"_a = "");
81  cls.def("copy", &PropertySet::copy, "dest"_a, "source"_a, "name"_a, "asScalar"_a=false);
82  cls.def("combine", &PropertySet::combine);
83  cls.def("remove", &PropertySet::remove);
84  cls.def("getAsBool", &PropertySet::getAsBool);
85  cls.def("getAsInt", &PropertySet::getAsInt);
86  cls.def("getAsInt64", &PropertySet::getAsInt64);
87  cls.def("getAsUInt64", &PropertySet::getAsUInt64);
88  cls.def("getAsDouble", &PropertySet::getAsDouble);
89  cls.def("getAsString", &PropertySet::getAsString);
90  cls.def("getAsPropertySetPtr", &PropertySet::getAsPropertySetPtr);
91  cls.def("getAsPersistablePtr", &PropertySet::getAsPersistablePtr);
92 
93  declareAccessors<bool>(cls, "Bool");
94  declareAccessors<short>(cls, "Short");
95  declareAccessors<int>(cls, "Int");
96  declareAccessors<long>(cls, "Long");
97  declareAccessors<long long>(cls, "LongLong");
98  declareAccessors<unsigned long long>(cls, "UnsignedLongLong");
99  declareAccessors<float>(cls, "Float");
100  declareAccessors<double>(cls, "Double");
101  declareAccessors<std::nullptr_t>(cls, "Undef");
102  declareAccessors<std::string>(cls, "String");
103  declareAccessors<DateTime>(cls, "DateTime");
104  declareAccessors<std::shared_ptr<PropertySet>>(cls, "PropertySet");
105 }
106 
107 } // base
108 } // daf
109 } // lsst
table::Key< std::string > name
Definition: Amplifier.cc:116
Interface for DateTime class.
T c_str(T... args)
T hash_code(T... args)
T name(T... args)
std::string const & getName() const noexcept
Return a filter's name.
Definition: Filter.h:78
PYBIND11_MODULE(propertySet, mod)
Definition: propertySet.cc:50
A base class for image defects.