LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
propertySet.cc
Go to the documentation of this file.
1#include "pybind11/pybind11.h"
2#include "pybind11/stl.h"
3
4#include <cstddef>
5#include <string>
6#include <typeinfo>
7
10
11namespace py = pybind11;
12using namespace pybind11::literals;
13
14namespace lsst {
15namespace daf {
16namespace base {
17namespace {
18
19template <typename T, typename C>
20void 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
50PYBIND11_MODULE(propertySet, mod) {
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>> 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",
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 declareAccessors<bool>(cls, "Bool");
100 declareAccessors<short>(cls, "Short");
101 declareAccessors<int>(cls, "Int");
102 declareAccessors<long>(cls, "Long");
103 declareAccessors<long long>(cls, "LongLong");
104 declareAccessors<unsigned long long>(cls, "UnsignedLongLong");
105 declareAccessors<float>(cls, "Float");
106 declareAccessors<double>(cls, "Double");
107 declareAccessors<std::nullptr_t>(cls, "Undef");
108 declareAccessors<std::string>(cls, "String");
109 declareAccessors<DateTime>(cls, "DateTime");
110 declareAccessors<std::shared_ptr<PropertySet>>(cls, "PropertySet");
111}
112
113} // base
114} // daf
115} // lsst
table::Key< std::string > name
Definition: Amplifier.cc:116
Interface for DateTime class.
T c_str(T... args)
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.
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).
Persistable::Ptr getAsPersistablePtr(std::string const &name) const
Get the last value for a Persistable 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).
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)
PYBIND11_MODULE(dateTime, mod)
Definition: dateTime.cc:12
A base class for image defects.