@@ -64,7 +64,7 @@ namespace
64
64
// make uppercase PREFIX_NAMESPACE_KEY string
65
65
66
66
string str = string (" CALI_" ) + name + string (" _" ) + key;
67
-
67
+
68
68
transform (str.begin (), str.end (), str.begin (), ::toupper);
69
69
70
70
return str;
@@ -84,46 +84,41 @@ struct ConfigSetImpl
84
84
{
85
85
// --- data
86
86
87
- struct ConfigValue {
88
- ConfigSet::Entry entry;
89
- std::string value;
90
- };
91
-
92
- unordered_map<string, ConfigValue> m_dict;
87
+ std::unordered_map<string, StringConverter> m_dict;
93
88
94
89
// --- interface
95
90
96
91
StringConverter get (const char * key) const {
97
92
auto it = m_dict.find (key);
98
- return (it == m_dict.end () ? StringConverter () : StringConverter ( it->second . value ) );
93
+ return (it == m_dict.end () ? StringConverter () : it->second );
99
94
}
100
95
101
- void init (const char * name, const ConfigSet::Entry* list, bool read_env, const ::config_profile_t & profile, const ::config_profile_t & top_profile)
96
+ void init (const char * name, const RuntimeConfig:: config_entry_list_t & list, bool read_env, const ::config_profile_t & profile, const ::config_profile_t & top_profile)
102
97
{
103
- for (const ConfigSet::Entry* e = list; e && e-> key ; ++e ) {
104
- ConfigValue newent { *e, string (e-> value ) };
105
- string varname { :: config_var_name (name, e-> key ) };
98
+ for (const auto &e : list) {
99
+ std::string varname { :: config_var_name (name, e. first ) };
100
+ std:: string value { e. second };
106
101
107
102
// See if there is an entry in the top config profile
108
103
auto topit = top_profile.find (varname);
109
104
110
105
if (topit != top_profile.end ()) {
111
- newent. value = topit->second ;
106
+ value = topit->second ;
112
107
} else {
113
108
// See if there is an entry in the base config profile
114
109
auto it = profile.find (varname);
115
110
if (it != profile.end ())
116
- newent. value = it->second ;
111
+ value = it->second ;
117
112
118
113
if (read_env) {
119
114
// See if there is a config variable set
120
- char * val = getenv (::config_var_name (name, e-> key ).c_str ());
115
+ char * val = getenv (::config_var_name (name, e. first ).c_str ());
121
116
if (val)
122
- newent. value = val;
117
+ value = val;
123
118
}
124
119
}
125
120
126
- m_dict.emplace (make_pair (string (e-> key ), newent ));
121
+ m_dict.emplace (make_pair (e. first , StringConverter (value) ));
127
122
}
128
123
}
129
124
};
@@ -136,7 +131,6 @@ struct ConfigSetImpl
136
131
struct RuntimeConfig ::RuntimeConfigImpl
137
132
{
138
133
// --- data
139
- static const ConfigSet::Entry s_configdata[];
140
134
141
135
bool m_allow_read_env = true ;
142
136
@@ -215,9 +209,14 @@ struct RuntimeConfig::RuntimeConfigImpl
215
209
}
216
210
217
211
void init_config_database () {
212
+ const config_entry_list_t configdata {
213
+ { " profile" , " default" },
214
+ { " file" , " caliper.config" }
215
+ };
216
+
218
217
// read pre-init config set to get config file name from env var
219
218
ConfigSetImpl init_config_cfg;
220
- init_config_cfg.init (" config" , s_configdata , m_allow_read_env, m_combined_profile, m_top_profile);
219
+ init_config_cfg.init (" config" , configdata , m_allow_read_env, m_combined_profile, m_top_profile);
221
220
222
221
// read config files
223
222
read_config_files (init_config_cfg.get (" file" ).to_stringlist ());
@@ -230,7 +229,7 @@ struct RuntimeConfig::RuntimeConfigImpl
230
229
231
230
// read "config" config again: profile may have been set in the file
232
231
shared_ptr<ConfigSetImpl> config_cfg { new ConfigSetImpl };
233
- config_cfg->init (" config" , s_configdata , m_allow_read_env, m_combined_profile, m_top_profile);
232
+ config_cfg->init (" config" , configdata , m_allow_read_env, m_combined_profile, m_top_profile);
234
233
235
234
m_database.insert (make_pair (" config" , config_cfg));
236
235
@@ -275,7 +274,7 @@ struct RuntimeConfig::RuntimeConfigImpl
275
274
m_top_profile[p.first ] = p.second ;
276
275
}
277
276
278
- shared_ptr<ConfigSetImpl> init_configset (const char * name, const ConfigSet::Entry* list) {
277
+ shared_ptr<ConfigSetImpl> init_configset (const char * name, const config_entry_list_t & list) {
279
278
if (m_database.empty ())
280
279
init_config_database ();
281
280
@@ -295,25 +294,11 @@ struct RuntimeConfig::RuntimeConfigImpl
295
294
void print (std::ostream& os) const {
296
295
for ( auto set : m_database )
297
296
for ( auto entry : set.second ->m_dict )
298
- os << " # " << entry.second .entry .descr
299
- << " (" << cali_type2string (entry.second .entry .type ) << " )\n "
300
- << ::config_var_name (set.first , entry.first )
301
- << ' =' << entry.second .value << std::endl;
297
+ os << ::config_var_name (set.first , entry.first )
298
+ << ' =' << entry.second .to_string () << std::endl;
302
299
}
303
300
};
304
301
305
- const ConfigSet::Entry RuntimeConfig::RuntimeConfigImpl::s_configdata[] = {
306
- { " profile" , CALI_TYPE_STRING, " default" ,
307
- " Configuration profile" ,
308
- " Configuration profile"
309
- },
310
- { " file" , CALI_TYPE_STRING, " caliper.config" ,
311
- " List of configuration files" ,
312
- " Comma-separated list of configuration files"
313
- },
314
- ConfigSet::Terminator
315
- };
316
-
317
302
} // namespace cali
318
303
319
304
@@ -329,7 +314,7 @@ StringConverter
329
314
ConfigSet::get (const char * key) const
330
315
{
331
316
if (!mP )
332
- return std::string ();
317
+ return StringConverter ();
333
318
334
319
return mP ->get (key);
335
320
}
@@ -351,6 +336,17 @@ RuntimeConfig::get(const char* set, const char* key)
351
336
352
337
ConfigSet
353
338
RuntimeConfig::init (const char * name, const ConfigSet::Entry* list)
339
+ {
340
+ config_entry_list_t converted_list;
341
+
342
+ for (const ConfigSet::Entry* e = list; e && e->key ; ++e)
343
+ converted_list.emplace_back ( std::make_pair<std::string, std::string>(e->key , e->value ) );
344
+
345
+ return ConfigSet (mP ->init_configset (name, converted_list));
346
+ }
347
+
348
+ ConfigSet
349
+ RuntimeConfig::init (const char * name, const config_entry_list_t & list)
354
350
{
355
351
return ConfigSet (mP ->init_configset (name, list));
356
352
}
0 commit comments