1 #ifndef QNANO_NEW_PARAMETER_LIST_DEFINED_H 2 #define QNANO_NEW_PARAMETER_LIST_DEFINED_H 4 #include "tools/Reader.h" 5 #include "tools/Debug_Logger.h" 6 #include "tools/Vec3d.h" 10 typedef std::vector<std::vector<std::string> > Parameter_Values;
15 int *p_args;
char ***p_argv;
21 std::map<std::string, Parameter_Values >
map;
26 bool use_check_requested_on_destruction;
32 typedef std::map<std::string, std::vector<std::vector<std::string> > >::iterator map_iter;
33 typedef std::map<std::string, std::vector<std::vector<std::string> > >::const_iterator map_const_iter;
34 std::vector<std::vector<std::string> > empty_stringvecvec;
38 void add(
const std::string &key,
const std::vector<std::string> & stringvec);
39 void add(
const std::string &key,
const std::string &str);
41 void set_requested(
const std::string &key);
43 bool is_specified(
const std::string &key,
size_t row=0,
size_t col=0);
44 bool is_double(
const std::string &key);
45 bool is_bool(
const std::string &key);
46 bool is_Vec3d(
const std::string &key,
size_t row=0,
size_t col=0);
47 bool is_VecXd(
const std::string &key,
size_t X,
size_t row=0,
size_t col=0);
48 void complain_if_not_specified(
const std::string &key, std::ostream &ofs=std::cerr);
49 void quit_if_not_specified(
const std::string &key,
size_t row=0,
size_t col=0);
50 void override_parameter(
const std::string &key,
const std::vector<std::string> & stringvec);
51 void override_parameter(
const std::string &key,
const std::string &value){
52 override_parameter(key,std::vector<std::string>(1,value));
54 void override_parameter(
const std::string &key,
double value){
55 override_parameter(key,Reader::toString(value));
58 const Parameter_Values &
get(
const std::string &key);
60 size_t get_rows(
const std::string &key);
61 size_t get_cols(
const std::string &key,
size_t row);
64 std::vector<std::string> get_all_strings(
const std::string &key);
66 std::string get_as_string(
const std::string &key,
const std::string default_=
"",
size_t row=0,
size_t col=0);
70 std::string get_as_string_check(
const std::string &key,
const std::string default_=
"",
size_t row=0,
size_t col=0){
71 quit_if_not_specified(key,row,col);
72 return get_as_string(key,default_, row, col);
75 double get_as_double(
const std::string &key,
double default_=0.,
size_t row=0,
size_t col=0);
76 double get_as_double_check(
const std::string &key,
double default_=0.,
size_t row=0,
size_t col=0){
77 quit_if_not_specified(key, row, col);
78 return get_as_double(key,default_,row,col);
80 size_t get_as_sizet(
const std::string &key,
size_t default_=0.,
size_t row=0,
size_t col=0){
81 int i=get_as_double(key,default_,row,col);
82 if(i<0){ std::cerr<<
"Parameter_Map::get_as_sizet: value less than zero!"<<std::endl; exit(1);}
85 double get_as_sizet_check(
const std::string &key,
size_t default_=0.,
size_t row=0,
size_t col=0){
86 quit_if_not_specified(key, row, col);
87 return get_as_sizet(key,default_,row,col);
90 bool get_as_bool(
const std::string &key,
bool default_=
false,
size_t row=0,
size_t col=0);
94 std::vector<double> get_as_VecXd(
const std::string &key,
size_t X, std::vector<double> default_=std::vector<double>(),
size_t row=0,
size_t col=0);
96 Vec3d get_as_Vec3d(
const std::string &key,
Vec3d default_=
Vec3d(),
size_t row=0,
size_t col=0){
97 std::vector<double> default_vec(3);
98 default_vec[0]=default_[0];
99 default_vec[1]=default_[1];
100 default_vec[2]=default_[2];
101 std::vector<double> v=get_as_VecXd(key, 3, default_vec, row, col);
102 return Vec3d(v[0],v[1],v[2]);
104 inline Vec3d get_as_Vec3d(
const char* key,
Vec3d default_=
Vec3d(),
size_t row=0,
size_t col=0){
105 return get_as_Vec3d(std::string(key),default_,row,col);
107 inline Vec3d get_as_Vec3d_check(
const std::string &key,
Vec3d default_=
Vec3d(),
size_t row=0,
size_t col=0){
108 quit_if_not_specified(key);
109 return get_as_Vec3d(key, default_, row, col);
113 void add_from_file(
const std::string &filename);
114 void add_from_command_line(
int args,
char** argv);
115 void add_from_command_line_or_driver(
int args,
char** argv);
118 void print(std::ostream &ofs)
const;
119 void print(
const std::string filename)
const;
120 void print(
const char* filename)
const;
122 void check_requested()
const;
125 logger.setup(get_as_string(
"debug_log"));
131 use_check_requested_on_destruction=
false;
141 Parameter_Map(
const std::string &filename,
bool use_check_requested=
false){
142 use_check_requested_on_destruction=use_check_requested;
143 add_from_file(filename);
146 Parameter_Map(
const char* filename,
bool use_check_requested=
false){
147 use_check_requested_on_destruction=use_check_requested;
148 add_from_file(std::string(filename));
151 Parameter_Map(
int &args,
char** &argv,
bool use_check_requested=
false){
152 p_args=&args; p_argv=&argv;
153 use_check_requested_on_destruction=use_check_requested;
154 add_from_command_line_or_driver(args,argv);
159 if(use_check_requested_on_destruction)check_requested();
Debug_Logger logger
It is very convenient to pass along a log file for debugging purposes with the Parameter_Map: ...
Definition: Parameter_Map.h:30
Definition: Parameter_Map.h:12
std::map< std::string, Parameter_Values > map
Definition: Parameter_Map.h:21
Class to store positions and to handle operations on 3d vectors.
Definition: Vec3d.h:9
Definition: Debug_Logger.h:7
std::vector< std::string > requested
Track which parameters have been requested to point out unused paramters:
Definition: Parameter_Map.h:25