LSSTApplications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
propertySet.cc
Go to the documentation of this file.
1 #include "pybind11/pybind11.h"
2 #include "pybind11/stl.h"
3 
4 #include <string>
5 #include <typeinfo>
6 
9 
10 namespace py = pybind11;
11 using namespace pybind11::literals;
12 
13 namespace lsst {
14 namespace daf {
15 namespace base {
16 namespace {
17 
18 template <typename T, typename C>
19 void declareAccessors(C& cls, std::string const& name) {
20  const std::string getName = "get" + name;
21  cls.def(getName.c_str(), (T (PropertySet::*)(std::string const&) const) & PropertySet::get<T>, "name"_a);
22  cls.def(getName.c_str(), (T (PropertySet::*)(std::string const&, T const&) const) & PropertySet::get<T>,
23  "name"_a, "defaultValue"_a);
24 
25  const std::string getArrayName = "getArray" + name;
26  cls.def(getArrayName.c_str(),
27  (std::vector<T> (PropertySet::*)(std::string const&) const) & PropertySet::getArray<T>, "name"_a);
28 
29  const std::string setName = "set" + name;
30  cls.def(setName.c_str(), (void (PropertySet::*)(std::string const&, T const&)) & PropertySet::set<T>,
31  "name"_a, "value"_a);
32  cls.def(setName.c_str(),
33  (void (PropertySet::*)(std::string const&, std::vector<T> const&)) & PropertySet::set<T>,
34  "name"_a, "value"_a);
35 
36  const std::string addName = "add" + name;
37  cls.def(addName.c_str(), (void (PropertySet::*)(std::string const&, T const&)) & PropertySet::add<T>,
38  "name"_a, "value"_a);
39  cls.def(addName.c_str(),
40  (void (PropertySet::*)(std::string const&, std::vector<T> const&)) & PropertySet::add<T>,
41  "name"_a, "value"_a);
42 
43  const std::string typeName = "TYPE_" + name;
44  cls.attr(typeName.c_str()) = py::cast(PropertySet::typeOfT<T>(), py::return_value_policy::reference);
45 }
46 
47 } // <anonymous>
48 
49 PYBIND11_MODULE(propertySet, mod) {
50  py::module::import("lsst.daf.base.persistable");
51 
52  py::class_<std::type_info>(mod, "TypeInfo")
53  .def("__eq__",
54  [](std::type_info const& self, std::type_info const& other) { return self == other; })
55  .def("__ne__",
56  [](std::type_info const& self, std::type_info const& other) { return self != other; })
57  .def("name", &std::type_info::name)
58  .def("__hash__", &std::type_info::hash_code);
59 
60  py::class_<PropertySet, std::shared_ptr<PropertySet>> cls(mod, "PropertySet");
61 
62  cls.def(py::init<bool>(), "flat"_a = false);
63 
64  cls.def("deepCopy", &PropertySet::deepCopy);
65  cls.def("nameCount", &PropertySet::nameCount, "topLevelOnly"_a = true);
66  cls.def("names", &PropertySet::names, "topLevelOnly"_a = true);
67  cls.def("paramNames", &PropertySet::paramNames, "topLevelOnly"_a = true);
68  cls.def("propertySetNames", &PropertySet::propertySetNames, "topLevelOnly"_a = true);
69  cls.def("exists", &PropertySet::exists);
70  cls.def("isArray", &PropertySet::isArray);
71  cls.def("isUndefined", &PropertySet::isUndefined);
72  cls.def("isPropertySetPtr", &PropertySet::isPropertySetPtr);
73  cls.def("valueCount",
74  py::overload_cast<>(&PropertySet::valueCount, py::const_));
75  cls.def("valueCount",
76  py::overload_cast<std::string const&>(&PropertySet::valueCount,
77  py::const_));
78  cls.def("typeOf", &PropertySet::typeOf, py::return_value_policy::reference);
79  cls.def("toString", &PropertySet::toString, "topLevelOnly"_a = false, "indent"_a = "");
80  cls.def("copy", &PropertySet::copy, "dest"_a, "source"_a, "name"_a, "asScalar"_a=false);
81  cls.def("combine", &PropertySet::combine);
82  cls.def("remove", &PropertySet::remove);
83  cls.def("getAsBool", &PropertySet::getAsBool);
84  cls.def("getAsInt", &PropertySet::getAsInt);
85  cls.def("getAsInt64", &PropertySet::getAsInt64);
86  cls.def("getAsUInt64", &PropertySet::getAsUInt64);
87  cls.def("getAsDouble", &PropertySet::getAsDouble);
88  cls.def("getAsString", &PropertySet::getAsString);
89  cls.def("getAsPropertySetPtr", &PropertySet::getAsPropertySetPtr);
90  cls.def("getAsPersistablePtr", &PropertySet::getAsPersistablePtr);
91 
92  declareAccessors<bool>(cls, "Bool");
93  declareAccessors<short>(cls, "Short");
94  declareAccessors<int>(cls, "Int");
95  declareAccessors<long>(cls, "Long");
96  declareAccessors<long long>(cls, "LongLong");
97  declareAccessors<unsigned long long>(cls, "UnsignedLongLong");
98  declareAccessors<float>(cls, "Float");
99  declareAccessors<double>(cls, "Double");
100  declareAccessors<nullptr_t>(cls, "Undef");
101  declareAccessors<std::string>(cls, "String");
102  declareAccessors<DateTime>(cls, "DateTime");
103  declareAccessors<std::shared_ptr<PropertySet>>(cls, "PropertySet");
104 }
105 
106 } // base
107 } // daf
108 } // lsst
std::string
STL class.
lsst::daf::base::PYBIND11_MODULE
PYBIND11_MODULE(propertySet, mod)
Definition: propertySet.cc:49
std::vector
STL class.
std::type_info
DateTime.h
Interface for DateTime class.
std::type_info::name
T name(T... args)
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
std::type_info::hash_code
T hash_code(T... args)
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
std::string::c_str
T c_str(T... args)
other
ItemVariant const * other
Definition: Schema.cc:56
PropertySet.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
pybind11
Definition: _GenericMap.cc:40