LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 
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 
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>, Citizen> 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", &PropertySet::valueCount);
75  cls.def("typeOf", &PropertySet::typeOf, py::return_value_policy::reference);
76  cls.def("toString", &PropertySet::toString, "topLevelOnly"_a = false, "indent"_a = "");
77  cls.def("copy", &PropertySet::copy, "dest"_a, "source"_a, "name"_a, "asScalar"_a=false);
78  cls.def("combine", &PropertySet::combine);
79  cls.def("remove", &PropertySet::remove);
80  cls.def("getAsBool", &PropertySet::getAsBool);
81  cls.def("getAsInt", &PropertySet::getAsInt);
82  cls.def("getAsInt64", &PropertySet::getAsInt64);
83  cls.def("getAsDouble", &PropertySet::getAsDouble);
84  cls.def("getAsString", &PropertySet::getAsString);
85  cls.def("getAsPropertySetPtr", &PropertySet::getAsPropertySetPtr);
86  cls.def("getAsPersistablePtr", &PropertySet::getAsPersistablePtr);
87 
88  declareAccessors<bool>(cls, "Bool");
89  declareAccessors<short>(cls, "Short");
90  declareAccessors<int>(cls, "Int");
91  declareAccessors<long>(cls, "Long");
92  declareAccessors<long long>(cls, "LongLong");
93  declareAccessors<float>(cls, "Float");
94  declareAccessors<double>(cls, "Double");
95  declareAccessors<nullptr_t>(cls, "Undef");
96  declareAccessors<std::string>(cls, "String");
97  declareAccessors<DateTime>(cls, "DateTime");
98  declareAccessors<std::shared_ptr<PropertySet>>(cls, "PropertySet");
99 }
100 
101 } // base
102 } // daf
103 } // lsst
T hash_code(T... args)
PYBIND11_MODULE(propertySet, mod)
Definition: propertySet.cc:50
STL class.
A base class for image defects.
Interface for DateTime class.
STL class.
T name(T... args)
T c_str(T... args)
ItemVariant const * other
Definition: Schema.cc:56
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55