12 #ifndef SPROCKIT_COMMON_SIM_PARAMETERS_H_INCLUDED 13 #define SPROCKIT_COMMON_SIM_PARAMETERS_H_INCLUDED 32 param_assign(std::string& p,
const std::string& k) :
37 void operator=(
int a);
38 void operator=(
double x);
39 void operator=(
const std::string& str){
43 const std::string& setByteLength(
long x,
const char* units);
44 const std::string& setBandwidth(
double x,
const char* units);
45 const std::string& setFrequency(
double x,
const char* units);
46 const std::string& setTime(
double x,
const char* units);
47 const std::string& setValue(
double x,
const char* units);
48 const std::string&
set(
const char* str);
49 const std::string&
set(
const std::string& str);
51 long getByteLength()
const;
52 double getBandwidth()
const;
53 double getTime()
const;
54 double getFrequency()
const;
58 operator double()
const;
60 operator std::string()
const {
66 const std::string& key_;
73 bcast(
void* buf,
int size,
int me,
int root) = 0;
76 bcast_string(std::string& str,
int me,
int root);
79 class sim_parameters {
82 struct parameter_entry
84 parameter_entry() : read(
false) {}
89 typedef spkt_unordered_map<std::string, parameter_entry> key_value_map;
93 sim_parameters(
const key_value_map& p);
95 sim_parameters(
const std::string& filename);
107 parallel_build_params(sprockit::sim_parameters* params,
int me,
int nproc,
const std::string& filename,
param_bcaster* bcaster);
109 virtual ~sim_parameters();
112 remove_param(
const std::string &key);
115 get_param(
const std::string& key,
bool throw_on_error =
true);
118 get_scoped_param(
const std::string& key,
bool throw_on_error =
true);
121 reread_param(
const std::string& key) {
126 reread_optional_param(
const std::string& key,
const std::string& def) {
139 deprecated_optional_param(
const std::string &key,
const std::string &def);
142 deprecated_param(
const std::string& key);
145 add_param(
const std::string& key,
const std::string& val);
148 copy_param(
const std::string& oldname,
const std::string& newname);
151 copy_optional_param(
const std::string& oldname,
const std::string& newname);
154 add_param_override(
const std::string& key,
const std::string& val);
157 add_param_override(
const std::string &key,
double val);
160 add_param_override(
const std::string& key,
double val,
const char* units);
163 add_param_override(
const std::string& key,
int val);
166 combine_into(sim_parameters* sp,
167 bool fail_on_existing =
false,
168 bool override_existing =
true,
169 bool mark_as_read =
true);
172 print_params(std::ostream& os,
bool pretty_print, std::list<std::string>& namespaces)
const;
175 print_params(std::ostream& os = std::cerr)
const {
176 std::list<std::string> ns;
177 print_params(os,
false, ns);
181 pretty_print_params(std::ostream& os = std::cerr)
const {
182 std::list<std::string> ns;
183 print_params(os,
true, ns);
187 print_unread_params(std::ostream& os = std::cerr)
const;
190 has_param(
const std::string& key)
const;
193 has_scoped_param(
const std::string& key)
const;
199 deprecated_int_param(
const std::string& key);
202 deprecated_optional_int_param(
const std::string &key,
int def);
205 reread_int_param(
const std::string& key);
208 reread_optional_int_param(
const std::string& key,
int def);
223 reread_bool_param(
const std::string& key);
226 deprecated_bool_param(
const std::string& key);
229 deprecated_optional_bool_param(
const std::string& key,
bool def);
232 reread_optional_bool_param(
const std::string& key,
bool def);
243 get_bandwidth_param(
const std::string& key);
252 get_quantity(
const std::string& key);
255 get_optional_quantity(
const std::string& key,
double def);
258 deprecated_bandwidth_param(
const std::string& key);
261 reread_bandwidth_param(
const std::string& key);
264 reread_optional_bandwidth_param(
const std::string& key,
double def);
267 deprecated_optional_bandwidth_param(
const std::string& key,
double def);
270 get_optional_bandwidth_param(
const std::string &key,
double def);
273 get_optional_bandwidth_param(
274 const std::string& key,
275 const std::string& def);
278 get_byte_length_param(
const std::string& key);
281 get_optional_byte_length_param(
const std::string& key,
long def);
284 deprecated_byte_length_param(
const std::string& key);
287 deprecated_optional_byte_length_param(
const std::string& key,
long def);
290 get_optional_freq_param(
const std::string& key,
double def);
293 get_freq_param(
const std::string& key);
296 deprecated_freq_param(
const std::string& key);
299 deprecated_optional_freq_param(
const std::string& key,
double def);
313 deprecated_long_param(
const std::string& key);
316 deprecated_optional_long_param(
const std::string& key,
long def);
319 reread_long_param(
const std::string& key);
322 reread_optional_long_param(
const std::string& key);
336 reread_double_param(
const std::string& key);
339 reread_optional_double_param(
const std::string &key,
double def);
342 deprecated_double_param(
const std::string& key);
345 deprecated_optional_double_param(
const std::string& key,
double def);
348 get_time_param(
const std::string& key);
351 get_optional_time_param(
const std::string &key,
double def);
354 deprecated_optional_time_param(
const std::string &key,
double def);
357 deprecated_time_param(
const std::string& key);
360 get_vector_param(
const std::string& key, std::vector<int>& vals);
363 get_vector_param(
const std::string& key, std::vector<double>& vals);
366 get_vector_param(
const std::string& key, std::vector<std::string>& vals);
369 get_namespace(
const std::string& ns);
372 get_optional_namespace(
const std::string& ns);
374 typedef std::set<int>::const_iterator id_iterator;
377 has_namespace(
const std::string& ns)
const;
380 parse_file(
const std::string& fname,
bool fail_on_existing,
bool override_existing);
383 parse_stream(std::istream& in,
bool fail_on_existing,
bool override_existing);
386 parse_line(
const std::string& line,
bool fail_on_existing,
bool override_existing);
394 parse_keyval(
const std::string& key,
395 const std::string& value,
396 bool fail_on_existing,
397 bool override_existing,
401 operator[](
const std::string& key);
403 sim_parameters* top_parent();
405 key_value_map::iterator begin() {
return params_.begin(); }
406 key_value_map::const_iterator begin()
const {
return params_.begin(); }
408 key_value_map::iterator end() {
return params_.end(); }
409 key_value_map::const_iterator end()
const {
return params_.end(); }
411 typedef std::map<std::string, sim_parameters*>::iterator namespace_iterator;
412 typedef std::map<std::string, sim_parameters*>::const_iterator const_namespace_iterator;
413 namespace_iterator ns_begin() {
return subspaces_.begin(); }
414 const_namespace_iterator ns_begin()
const {
return subspaces_.begin(); }
415 namespace_iterator ns_end() {
return subspaces_.end(); }
416 const_namespace_iterator ns_end()
const {
return subspaces_.end(); }
419 std::map<std::string, sim_parameters*> subspaces_;
420 std::map<std::string, std::string> variables_;
422 sim_parameters* parent_;
424 static sim_parameters* empty_ns_params_;
426 std::string namespace_;
428 key_value_map params_;
431 throw_key_error(
const std::string& key)
const;
434 set_parent(sim_parameters* p) {
439 set_namespace(
const std::string& str) {
444 local_has_namespace(
const std::string& ns)
const {
445 return subspaces_.find(ns) != subspaces_.end();
449 split_line(
const std::string& line, std::pair<std::string, std::string>& p);
452 try_to_parse(
const std::string& fname,
bool fail_on_existing,
bool override_existing);
455 print_params(
const key_value_map& pmap, std::ostream& os,
bool pretty_print, std::list<std::string>& ns)
const;
458 do_add_param(
const std::string& key,
459 const std::string& val,
460 bool fail_on_existing,
461 bool override_existing,
466 get_scope_and_key(
const std::string& key, std::string& final_key);
469 get_param(std::string& inout,
const std::string& key);
472 get_scoped_param(std::string& inout,
const std::string& key);
DeclareDebugSlot(params) DeclareDebugSlot(read_params) DeclareDebugSlot(write_params) namespace sprockit
const char * get_param(char *str)
double get_double_param(char *str)
bool get_bool_param(char *str)
int get_optional_int_param(char *str, int val)
int get_int_param(char *str)
long get_long_param(char *str)
long get_optional_long_param(char *str, long val)
const char * get_optional_param(char *str, char *val)
bool get_optional_bool_param(char *str, bool val)
double get_optional_double_param(char *str, double val)