1818#include < cassert>
1919#include < map>
2020#include < unordered_map>
21- #include < boost/property_tree/ptree .hpp>
21+ #include < boost/property_tree/ptree_fwd .hpp>
2222#include < typeinfo>
2323#include < iostream>
2424
@@ -181,9 +181,6 @@ class ConfigurableParam
181181 static void setInputDir (const std::string& d) { sInputDir = d; }
182182 static void setOutputDir (const std::string& d) { sOutputDir = d; }
183183
184- static boost::property_tree::ptree readINI (std::string const & filepath);
185- static boost::property_tree::ptree readJSON (std::string const & filepath);
186- static boost::property_tree::ptree readConfigFile (std::string const & filepath);
187184 static bool configFileExists (std::string const & filepath);
188185
189186 // writes a human readable JSON file of all parameters
@@ -195,10 +192,12 @@ class ConfigurableParam
195192 template <typename T>
196193 static T getValueAs (std::string key)
197194 {
198- if (!sIsFullyInitialized ) {
199- initialize ();
200- }
201- return sPtree ->get <T>(key);
195+ return [](auto * tree, const std::string& key) -> T {
196+ if (!sIsFullyInitialized ) {
197+ initialize ();
198+ }
199+ return tree->template get <T>(key);
200+ }(sPtree , key);
202201 }
203202
204203 template <typename T>
@@ -207,19 +206,21 @@ class ConfigurableParam
207206 if (!sIsFullyInitialized ) {
208207 initialize ();
209208 }
210- assert (sPtree );
211- try {
212- auto key = mainkey + " ." + subkey;
213- if (sPtree ->get_optional <std::string>(key).is_initialized ()) {
214- sPtree ->put (key, x);
215- auto changed = updateThroughStorageMap (mainkey, subkey, typeid (T), (void *)&x);
216- if (changed != EParamUpdateStatus::Failed) {
217- sValueProvenanceMap ->find (key)->second = kRT ; // set to runtime
209+ return [&subkey, &x, &mainkey](auto * tree) -> void {
210+ assert (tree);
211+ try {
212+ auto key = mainkey + " ." + subkey;
213+ if (tree->template get_optional <std::string>(key).is_initialized ()) {
214+ tree->put (key, x);
215+ auto changed = updateThroughStorageMap (mainkey, subkey, typeid (T), (void *)&x);
216+ if (changed != EParamUpdateStatus::Failed) {
217+ sValueProvenanceMap ->find (key)->second = kRT ; // set to runtime
218+ }
218219 }
220+ } catch (std::exception const & e) {
221+ std::cerr << " Error in setValue (T) " << e.what () << " \n " ;
219222 }
220- } catch (std::exception const & e) {
221- std::cerr << " Error in setValue (T) " << e.what () << " \n " ;
222- }
223+ }(sPtree );
223224 }
224225
225226 static void setProvenance (std::string const & mainkey, std::string const & subkey, EParamProvenance p)
@@ -241,25 +242,7 @@ class ConfigurableParam
241242
242243 // specialized for std::string
243244 // which means that the type will be converted internally
244- static void setValue (std::string const & key, std::string const & valuestring)
245- {
246- if (!sIsFullyInitialized ) {
247- initialize ();
248- }
249- assert (sPtree );
250- try {
251- if (sPtree ->get_optional <std::string>(key).is_initialized ()) {
252- sPtree ->put (key, valuestring);
253- auto changed = updateThroughStorageMapWithConversion (key, valuestring);
254- if (changed != EParamUpdateStatus::Failed) {
255- sValueProvenanceMap ->find (key)->second = kRT ; // set to runtime
256- }
257- }
258- } catch (std::exception const & e) {
259- std::cerr << " Error in setValue (string) " << e.what () << " \n " ;
260- }
261- }
262-
245+ static void setValue (std::string const & key, std::string const & valuestring);
263246 static void setEnumValue (const std::string&, const std::string&);
264247 static void setArrayValue (const std::string&, const std::string&);
265248
0 commit comments