1 #include "pybind11/pybind11.h" 2 #include "pybind11/stl.h" 11 namespace py = pybind11;
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);
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);
30 const std::string setName =
"set" + name;
31 cls.def(setName.c_str(), (void (PropertySet::*)(std::string
const&, T
const&)) & PropertySet::set<T>,
33 cls.def(setName.c_str(),
34 (void (PropertySet::*)(std::string
const&, std::vector<T>
const&)) & PropertySet::set<T>,
37 const std::string addName =
"add" + name;
38 cls.def(addName.c_str(), (void (PropertySet::*)(std::string
const&, T
const&)) & PropertySet::add<T>,
40 cls.def(addName.c_str(),
41 (void (PropertySet::*)(std::string
const&, std::vector<T>
const&)) & PropertySet::add<T>,
44 const std::string typeName =
"TYPE_" + name;
45 cls.attr(typeName.c_str()) = py::cast(
typeid(T), py::return_value_policy::reference);
51 py::module::import(
"lsst.daf.base.persistable");
53 py::module mod(
"propertySet");
55 py::class_<std::type_info>(mod,
"TypeInfo")
57 [](std::type_info
const&
self, std::type_info
const& other) {
return self == other; })
59 [](std::type_info
const&
self, std::type_info
const& other) {
return self != other; });
61 py::class_<PropertySet, std::shared_ptr<PropertySet>,
Persistable,
Citizen> cls(mod,
"PropertySet");
63 cls.def(py::init<bool>(),
"flat"_a =
false);
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(
"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);
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(
"getAsDouble", &PropertySet::getAsDouble);
83 cls.def(
"getAsString", &PropertySet::getAsString);
84 cls.def(
"getAsPropertySetPtr", &PropertySet::getAsPropertySetPtr);
85 cls.def(
"getAsPersistablePtr", &PropertySet::getAsPersistablePtr);
87 declareAccessors<bool>(cls,
"Bool");
88 declareAccessors<short>(cls,
"Short");
89 declareAccessors<int>(cls,
"Int");
90 declareAccessors<long>(cls,
"Long");
91 declareAccessors<long long>(cls,
"LongLong");
92 declareAccessors<float>(cls,
"Float");
93 declareAccessors<double>(cls,
"Double");
94 declareAccessors<std::string>(cls,
"String");
95 declareAccessors<DateTime>(cls,
"DateTime");
96 declareAccessors<std::shared_ptr<PropertySet>>(cls,
"PropertySet");
Interface for DateTime class.
PYBIND11_PLUGIN(propertySet)
Interface for PropertySet class.
Base class for all persistable classes.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...