21 ChimeraTK::DataType dt,
const std::string& path, std::optional<UserTypeVariantNoVoid> defaultValue) {
22 std::optional<UserTypeVariantNoVoid> rv;
23 ChimeraTK::callForTypeNoVoid(dt.getAsTypeInfo(), [&](
auto t) {
24 using UserType = decltype(t);
27 UserType valAsUserType;
29 [&](auto value) { valAsUserType = ChimeraTK::userTypeToUserType<UserType>(value); }, defaultValue.value());
30 rv.emplace(_reader.get().get<UserType>(path, valAsUserType));
33 rv.emplace(_reader.get().get<UserType>(path));
37 return std::move(rv.value());
42 UserTypeTemplateVariantNoVoid<PyConfigReader::Vector> PyConfigReader::getArray(ChimeraTK::DataType dt,
43 const std::string& path, std::optional<UserTypeTemplateVariantNoVoid<Vector>> defaultValue) {
44 std::optional<UserTypeTemplateVariantNoVoid<Vector>> rv;
45 ChimeraTK::callForTypeNoVoid(dt.getAsTypeInfo(), [&](
auto t) {
46 using UserType = decltype(t);
49 std::vector<UserType> valAsUserType = std::visit(
51 return value | std::views::transform([](auto& v) { return ChimeraTK::userTypeToUserType<UserType>(v); }) |
52 cppext::ranges::to<std::vector>();
54 defaultValue.value());
55 rv.emplace(_reader.get().get<std::vector<UserType>>(path, valAsUserType));
58 rv.emplace(_reader.get().get<std::vector<UserType>>(path));
62 return std::move(rv.value());
69 m.def(
"appConfig", []() {
return PyConfigReader(PyApplicationModule::appConfig()); });
70 py::class_<PyConfigReader>(m,
"ConfigReader")
71 .def(
"get", &PyConfigReader::get,
72 "Get value for given configuration variable.\n\nThis is already accessible right after construction of "
73 "this object. Throws ChimeraTK::logic_error if variable doesn't exist. To obtain the value of an array, "
74 "use an std::vector<T> as template argument.",
75 py::arg(), py::arg(
"variableName"), py::arg(
"defaultValue") = std::nullopt)
76 .def(
"getArray", &PyConfigReader::getArray,
77 "Get value for given configuration variable.\n\nThis is already accessible right after construction of "
78 "this object. Throws ChimeraTK::logic_error if variable doesn't exist. ",
79 py::arg(), py::arg(
"variableName"), py::arg(
"defaultValue") = std::nullopt)
80 .def(
"getModules", &PyConfigReader::getModules, py::arg(
"path") =
"");