LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
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 
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", &PropertySet::valueCount);
74  cls.def("typeOf", &PropertySet::typeOf, py::return_value_policy::reference);
75  cls.def("toString", &PropertySet::toString, "topLevelOnly"_a = false, "indent"_a = "");
76  cls.def("copy", &PropertySet::copy, "dest"_a, "source"_a, "name"_a, "asScalar"_a=false);
77  cls.def("combine", &PropertySet::combine);
78  cls.def("remove", &PropertySet::remove);
79  cls.def("getAsBool", &PropertySet::getAsBool);
80  cls.def("getAsInt", &PropertySet::getAsInt);
81  cls.def("getAsInt64", &PropertySet::getAsInt64);
82  cls.def("getAsUInt64", &PropertySet::getAsUInt64);
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<unsigned long long>(cls, "UnsignedLongLong");
94  declareAccessors<float>(cls, "Float");
95  declareAccessors<double>(cls, "Double");
96  declareAccessors<nullptr_t>(cls, "Undef");
97  declareAccessors<std::string>(cls, "String");
98  declareAccessors<DateTime>(cls, "DateTime");
99  declareAccessors<std::shared_ptr<PropertySet>>(cls, "PropertySet");
100 }
101 
102 } // base
103 } // daf
104 } // lsst
T hash_code(T... args)
PYBIND11_MODULE(propertySet, mod)
Definition: propertySet.cc:49
ItemVariant const * other
Definition: Schema.cc:56
STL class.
A base class for image defects.
Interface for DateTime class.
Definition: __init__.py:1
STL class.
T name(T... args)
T c_str(T... args)