Loading [MathJax]/extensions/tex2jax.js
LSST Applications g0fba68d861+aa97b6e50c,g1ec0fe41b4+f536777771,g1fd858c14a+a9301854fb,g35bb328faa+fcb1d3bbc8,g4af146b050+a5c07d5b1d,g4d2262a081+78f4f01b60,g53246c7159+fcb1d3bbc8,g56a49b3a55+9c12191793,g5a012ec0e7+3632fc3ff3,g60b5630c4e+ded28b650d,g67b6fd64d1+ed4b5058f4,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8352419a5c+fcb1d3bbc8,g87b7deb4dc+7b42cf88bf,g8852436030+e5453db6e6,g89139ef638+ed4b5058f4,g8e3bb8577d+d38d73bdbd,g9125e01d80+fcb1d3bbc8,g94187f82dc+ded28b650d,g989de1cb63+ed4b5058f4,g9d31334357+ded28b650d,g9f33ca652e+50a8019d8c,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+d9fb1f8026,gb58c049af0+f03b321e39,gb89ab40317+ed4b5058f4,gcf25f946ba+e5453db6e6,gcf6002c91b+2a0c9e9e84,gd6cbbdb0b4+bb83cc51f8,gdd1046aedd+ded28b650d,gde0f65d7ad+66b3a48cb7,ge278dab8ac+d65b3c2b70,ge410e46f29+ed4b5058f4,gf23fb2af72+b7cae620c0,gf5e32f922b+fcb1d3bbc8,gf67bdafdda+ed4b5058f4,w.2025.16
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
propertySet.cc
Go to the documentation of this file.
1#include "pybind11/pybind11.h"
2#include "pybind11/stl.h"
3
5
6#include <string>
7#include <typeinfo>
8
11
12namespace py = pybind11;
13using namespace pybind11::literals;
14
15namespace lsst {
16namespace daf {
17namespace base {
18namespace {
19
20template <typename T, typename C>
21void declareAccessors(C& cls, std::string const& name) {
22 const std::string getName = "get" + name;
23 cls.def(getName.c_str(), (T (PropertySet::*)(std::string const&) const) & PropertySet::get<T>, "name"_a);
24 cls.def(getName.c_str(), (T (PropertySet::*)(std::string const&, T const&) const) & PropertySet::get<T>,
25 "name"_a, "defaultValue"_a);
26
27 const std::string getArrayName = "getArray" + name;
28 cls.def(getArrayName.c_str(),
29 (std::vector<T> (PropertySet::*)(std::string const&) const) & PropertySet::getArray<T>, "name"_a);
30
31 const std::string setName = "set" + name;
32 cls.def(setName.c_str(), (void (PropertySet::*)(std::string const&, T const&)) & PropertySet::set<T>,
33 "name"_a, "value"_a);
34 cls.def(setName.c_str(),
35 (void (PropertySet::*)(std::string const&, std::vector<T> const&)) & PropertySet::set<T>,
36 "name"_a, "value"_a);
37
38 const std::string addName = "add" + name;
39 cls.def(addName.c_str(), (void (PropertySet::*)(std::string const&, T const&)) & PropertySet::add<T>,
40 "name"_a, "value"_a);
41 cls.def(addName.c_str(),
42 (void (PropertySet::*)(std::string const&, std::vector<T> const&)) & PropertySet::add<T>,
43 "name"_a, "value"_a);
44
45 const std::string typeName = "TYPE_" + name;
46 cls.attr(typeName.c_str()) = py::cast(PropertySet::typeOfT<T>(), py::return_value_policy::reference);
47}
48
49} // <anonymous>
50
52 wrappers.wrapType(py::class_<std::type_info>(wrappers.module, "TypeInfo"), [](auto &mod, auto &cls) {
53 cls.def("__eq__",
54 [](std::type_info const &self, std::type_info const &other) { return self == other; });
55 cls.def("__ne__",
56 [](std::type_info const &self, std::type_info const &other) { return self != other; });
57 cls.def("name", &std::type_info::name);
58 cls.def("__hash__", &std::type_info::hash_code);
59 });
60
61 using PyPropertySet = py::class_<PropertySet, std::shared_ptr<PropertySet>>;
62 wrappers.wrapType(PyPropertySet(wrappers.module, "PropertySet"), [](auto &mod, auto &cls) {
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(
82 "copy",
83 py::overload_cast<std::string const &, PropertySet const &, std::string const &, bool>(
85 ),
86 "dest"_a, "source"_a, "name"_a, "asScalar"_a = false
87 );
88 cls.def("combine", py::overload_cast<PropertySet const &>(&PropertySet::combine));
89 cls.def("remove", &PropertySet::remove);
90 cls.def("getAsBool", &PropertySet::getAsBool);
91 cls.def("getAsInt", &PropertySet::getAsInt);
92 cls.def("getAsInt64", &PropertySet::getAsInt64);
93 cls.def("getAsUInt64", &PropertySet::getAsUInt64);
94 cls.def("getAsDouble", &PropertySet::getAsDouble);
95 cls.def("getAsString", &PropertySet::getAsString);
96 cls.def("getAsPropertySetPtr", &PropertySet::getAsPropertySetPtr);
97 cls.def("getAsPersistablePtr", &PropertySet::getAsPersistablePtr);
98
99 cpputils::python::addOutputOp(cls, "__repr__");
100 cpputils::python::addOutputOp(cls, "__str__");
101
102 declareAccessors<bool>(cls, "Bool");
103 declareAccessors<short>(cls, "Short");
104 declareAccessors<int>(cls, "Int");
105 declareAccessors<long>(cls, "Long");
106 declareAccessors<long long>(cls, "LongLong");
107 declareAccessors<unsigned long long>(cls, "UnsignedLongLong");
108 declareAccessors<float>(cls, "Float");
109 declareAccessors<double>(cls, "Double");
110 declareAccessors<std::nullptr_t>(cls, "Undef");
111 declareAccessors<std::string>(cls, "String");
112 declareAccessors<DateTime>(cls, "DateTime");
113 declareAccessors<std::shared_ptr<PropertySet>>(cls, "PropertySet");
114 });
115}
116
117} // base
118} // daf
119} // lsst
Interface for DateTime class.
T c_str(T... args)
A helper class for subdividing pybind11 module across multiple translation units (i....
Definition python.h:242
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
Definition python.h:391
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition python.h:448
Class for storing generic metadata.
Definition PropertySet.h:67
std::string getAsString(std::string const &name) const
Get the last value for a string property name (possibly hierarchical).
size_t nameCount(bool topLevelOnly=true) const
Get the number of names in the PropertySet, optionally including those in subproperties.
int getAsInt(std::string const &name) const
Get the last value for a bool/char/short/int property name (possibly hierarchical).
virtual void remove(std::string const &name)
Remove all values for a property name (possibly hierarchical).
bool isArray(std::string const &name) const
Determine if a name (possibly hierarchical) has multiple values.
int64_t getAsInt64(std::string const &name) const
Get the last value for a bool/char/short/int/int64_t property name (possibly hierarchical).
bool isUndefined(std::string const &name) const
Determine if a name (possibly hierarchical) has a defined value.
bool exists(std::string const &name) const
Determine if a name (possibly hierarchical) exists.
std::vector< std::string > names(bool topLevelOnly=true) const
Get the names in the PropertySet, optionally including those in subproperties.
void set(std::string const &name, T const &value)
Replace all values for a property name (possibly hierarchical) with a new scalar value.
std::vector< T > getArray(std::string const &name) const
Get the vector of values for a property name (possibly hierarchical).
size_t valueCount() const
Get the number of values in the entire PropertySet, counting each element of a vector.
bool isPropertySetPtr(std::string const &name) const
Determine if a name (possibly hierarchical) is a subproperty.
virtual void copy(std::string const &dest, PropertySet const &source, std::string const &name, bool asScalar=false)
Replace a single value vector in the destination with one from the source.
virtual void combine(PropertySet const &source)
Append all value vectors from the source to their corresponding properties.
std::shared_ptr< PropertySet > getAsPropertySetPtr(std::string const &name) const
Get the last value for a subproperty name (possibly hierarchical).
std::type_info const & typeOf(std::string const &name) const
Get the type of values for a property name (possibly hierarchical).
double getAsDouble(std::string const &name) const
Get the last value for any arithmetic property name (possibly hierarchical).
static std::type_info const & typeOfT()
Get type info for the specified class.
Persistable::Ptr getAsPersistablePtr(std::string const &name) const
Get the last value for a Persistable name (possibly hierarchical).
T get(std::string const &name) const
Get the last value for a property name (possibly hierarchical).
uint64_t getAsUInt64(std::string const &name) const
Get the last value for an bool/char/short/int/int64_t property name (possibly hierarchical).
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
virtual std::shared_ptr< PropertySet > deepCopy() const
Make a deep copy of the PropertySet and all of its contents.
std::vector< std::string > propertySetNames(bool topLevelOnly=true) const
A variant of names that only returns the names of subproperties.
virtual std::string toString(bool topLevelOnly=false, std::string const &indent="") const
Generate a string representation of the PropertySet.
std::vector< std::string > paramNames(bool topLevelOnly=true) const
A variant of names that excludes the names of subproperties.
bool getAsBool(std::string const &name) const
Get the last value for a bool property name (possibly hierarchical).
T hash_code(T... args)
T name(T... args)
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
Definition python.h:87
void wrapPropertySet(WrapperCollection &wrappers)