1111#ifndef O2_FRAMEWORK_CONFIGPARAMREGISTRY_H_
1212#define O2_FRAMEWORK_CONFIGPARAMREGISTRY_H_
1313
14- #include " Framework/ParamRetriever .h"
14+ #include " Array2D .h"
1515#include " Framework/ConfigParamStore.h"
16+ #include < boost/property_tree/ptree.hpp>
1617#include " Framework/Traits.h"
17- #include " Framework/VariantPropertyTreeHelpers.h"
1818
19- #include < boost/property_tree/ptree_fwd.hpp >
19+ #include < concepts >
2020#include < memory>
2121#include < string>
2222#include < cassert>
2323
24- namespace
25- {
2624template <typename T>
27- constexpr auto isSimpleType ()
28- {
29- return std::is_same_v<T, int > ||
30- std::is_same_v<T, int8_t > ||
31- std::is_same_v<T, int16_t > ||
32- std::is_same_v<T, uint8_t > ||
33- std::is_same_v<T, uint16_t > ||
34- std::is_same_v<T, uint32_t > ||
35- std::is_same_v<T, uint64_t > ||
36- std::is_same_v<T, int64_t > ||
37- std::is_same_v<T, long > ||
38- std::is_same_v<T, float > ||
39- std::is_same_v<T, double > ||
40- std::is_same_v<T, bool >;
41- }
42- } // namespace
25+ concept SimpleConfigValueType = std::same_as<T, int > ||
26+ std::same_as<T, int8_t > ||
27+ std::same_as<T, int16_t > ||
28+ std::same_as<T, uint8_t > ||
29+ std::same_as<T, uint16_t > ||
30+ std::same_as<T, uint32_t > ||
31+ std::same_as<T, uint64_t > ||
32+ std::same_as<T, int64_t > ||
33+ std::same_as<T, long > ||
34+ std::same_as<T, float > ||
35+ std::same_as<T, double > ||
36+ std::same_as<T, bool >;
37+
38+ template <typename T>
39+ concept StringConfigValueType = std::same_as<T, std::string>;
40+
41+ template <typename T>
42+ concept PtreeConfigValueType = std::same_as<T, boost::property_tree::ptree> || std::constructible_from<T, boost::property_tree::ptree>;
43+
44+ template <typename T>
45+ concept ConfigValueType = SimpleConfigValueType<T> || StringConfigValueType<T> || o2::framework::base_of_template<std::vector, T> || o2::framework::base_of_template<o2::framework::Array2D, T> || o2::framework::base_of_template<o2::framework::LabeledArray, T>;
4346
4447namespace o2 ::framework
4548{
@@ -54,87 +57,43 @@ class ConfigParamStore;
5457class ConfigParamRegistry
5558{
5659 public:
57- ConfigParamRegistry (std::unique_ptr<ConfigParamStore> store)
58- : mStore {std::move (store)}
59- {
60- }
60+ ConfigParamRegistry (std::unique_ptr<ConfigParamStore> store);
6161
62- bool isSet (const char * key) const
63- {
64- return mStore ->store ().count (key);
65- }
62+ bool isSet (const char * key) const ;
6663
67- bool hasOption (const char * key) const
68- {
69- return mStore ->store ().get_child_optional (key).is_initialized ();
70- }
64+ bool hasOption (const char * key) const ;
7165
72- bool isDefault (const char * key) const
73- {
74- return mStore ->store ().count (key) > 0 && mStore ->provenance (key) != " default" ;
75- }
66+ bool isDefault (const char * key) const ;
7667
77- [[nodiscard]] std::vector<ConfigParamSpec> const & specs () const
78- {
79- return mStore ->specs ();
80- }
68+ [[nodiscard]] std::vector<ConfigParamSpec> const & specs () const ;
8169
82- template <typename T>
83- T get (const char * key) const
84- {
85- assert (mStore .get ());
86- try {
87- if constexpr (isSimpleType<T>()) {
88- return mStore ->store ().get <T>(key);
89- } else if constexpr (std::is_same_v<T, std::string>) {
90- return mStore ->store ().get <std::string>(key);
91- } else if constexpr (std::is_same_v<T, std::string_view>) {
92- return std::string_view{mStore ->store ().get <std::string>(key)};
93- } else if constexpr (base_of_template<std::vector, T>) {
94- return vectorFromBranch<typename T::value_type>(mStore ->store ().get_child (key));
95- } else if constexpr (base_of_template<o2::framework::Array2D, T>) {
96- return array2DFromBranch<typename T::element_t >(mStore ->store ().get_child (key));
97- } else if constexpr (base_of_template<o2::framework::LabeledArray, T>) {
98- return labeledArrayFromBranch<typename T::element_t >(mStore ->store ().get_child (key));
99- } else if constexpr (std::is_same_v<T, boost::property_tree::ptree>) {
100- return mStore ->store ().get_child (key);
101- } else if constexpr (std::is_constructible_v<T, boost::property_tree::ptree>) {
102- return T{mStore ->store ().get_child (key)};
103- } else if constexpr (std::is_constructible_v<T, boost::property_tree::ptree> == false ) {
104- static_assert (std::is_constructible_v<T, boost::property_tree::ptree> == false ,
105- " Not a basic type and no constructor from ptree provided" );
106- }
107- } catch (std::exception& e) {
108- throw std::invalid_argument (std::string (" missing option: " ) + key + " (" + e.what () + " )" );
109- } catch (...) {
110- throw std::invalid_argument (std::string (" error parsing option: " ) + key);
111- }
112- throw std::invalid_argument (std::string (" bad type for option: " ) + key);
113- }
70+ template <ConfigValueType T>
71+ T get (const char * key) const ;
11472
11573 template <typename T>
116- void override (const char * key, const T& val) const
117- {
118- assert (mStore .get ());
119- try {
120- mStore ->store ().put (key, val);
121- } catch (std::exception& e) {
122- throw std::invalid_argument (std::string (" failed to store an option: " ) + key + " (" + e.what () + " )" );
123- } catch (...) {
124- throw std::invalid_argument (std::string (" failed to store an option: " ) + key);
125- }
126- }
74+ T get (const char * key) const ;
75+
76+ void override (const char * key, ConfigValueType auto const & val) const ;
12777
12878 // Load extra parameters discovered while we process data
129- void loadExtra (std::vector<ConfigParamSpec>& extras)
130- {
131- mStore ->load (extras);
132- }
79+ void loadExtra (std::vector<ConfigParamSpec>& extras);
13380
13481 private:
13582 std::unique_ptr<ConfigParamStore> mStore ;
13683};
13784
85+ template <typename T>
86+ T ConfigParamRegistry::get (const char * key) const
87+ {
88+ try {
89+ return T{mStore ->store ().get_child (key)};
90+ } catch (std::exception& e) {
91+ throw std::invalid_argument (std::string (" missing option: " ) + key + " (" + e.what () + " )" );
92+ } catch (...) {
93+ throw std::invalid_argument (std::string (" error parsing option: " ) + key);
94+ }
95+ }
96+
13897} // namespace o2::framework
13998
14099#endif // O2_FRAMEWORK_CONFIGPARAMREGISTRY_H_
0 commit comments