Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
itpp
base
parser.h
Go to the documentation of this file.
1
31
#ifndef PARSER_H
32
#define PARSER_H
33
34
// #define MAX_STR_LEN 4096
35
36
#include <
itpp/base/vec.h
>
37
#include <
itpp/base/mat.h
>
38
#include <
itpp/base/array.h
>
39
#include <iostream>
40
#include <itpp/itexports.h>
41
42
namespace
itpp
43
{
45
46
#if (defined(_MSC_VER) && defined(ITPP_SHARED_LIB))
47
//MSVC explicitely instantiate required template while building the shared library
48
template
class
ITPP_EXPORT Array<std::string>;
49
#endif
50
52
111
class ITPP_EXPORT
Parser
112
{
113
public
:
114
116
Parser
();
117
119
Parser
(
const
std::string &filename);
120
122
Parser
(
int
argc,
char
*argv[]);
123
125
Parser
(
const
std::string &filename,
int
argc,
char
*argv[]);
126
128
Parser
(
const
Array<std::string>
&setup);
129
131
void
init(
const
std::string &filename);
132
134
void
init(
int
argc,
char
*argv[]);
135
137
void
init(
const
std::string &filename,
int
argc,
char
*argv[]);
138
140
void
init(
const
Array<std::string>
&setup);
141
143
void
set_silentmode(
bool
v =
true
);
144
146
bool
exist
(
const
std::string &name);
147
149
template
<
class
T>
150
bool
get
(T &var,
const
std::string &name,
int
num = -1);
151
153
bool
get_bool(
const
std::string &name,
int
num = -1);
154
156
int
get_int(
const
std::string &name,
int
num = -1);
157
159
double
get_double(
const
std::string &name,
int
num = -1);
160
162
std::string get_string(
const
std::string &name,
int
num = -1);
163
165
vec get_vec(
const
std::string &name,
int
num = -1);
166
168
ivec get_ivec(
const
std::string &name,
int
num = -1);
169
171
svec get_svec(
const
std::string &name,
int
num = -1);
172
174
bvec get_bvec(
const
std::string &name,
int
num = -1);
175
177
mat get_mat(
const
std::string &name,
int
num = -1);
178
180
imat get_imat(
const
std::string &name,
int
num = -1);
181
183
smat get_smat(
const
std::string &name,
int
num = -1);
184
186
bmat
get_bmat(
const
std::string &name,
int
num = -1);
187
188
protected
:
189
190
private
:
191
193
std::string findname(
const
std::string &name,
194
bool
&error_flag,
195
bool
&print_flag,
196
int
num = 0,
197
bool
keep_brackets =
false
);
198
199
void
pre_parsing(
void
);
200
201
Array<std::string>
SetupStrings;
202
203
bool
VERBOSE;
204
};
205
206
// ----------------------- Implementation starts here -----------------------
207
208
template
<
class
T>
209
bool
Parser::get
(T &var,
const
std::string &name,
int
num)
210
{
211
bool
error_flag, print_flag;
212
std::string str = findname(name, error_flag, print_flag, num,
true
);
213
std::istringstream buffer(str);
214
if
(error_flag) {
215
if
(VERBOSE) {
216
std::cout << name <<
" = "
<< var <<
";"
<< std::endl;
217
}
218
}
219
else
{
220
buffer >> var;
221
if
(print_flag) {
222
std::cout << name <<
" = "
<< var << std::endl;
223
}
224
else
if
(VERBOSE) {
225
std::cout << name <<
" = "
<< var <<
";"
<< std::endl;
226
}
227
}
228
return
!error_flag;
229
}
230
232
template
<>
233
ITPP_EXPORT
bool
Parser::get
(std::string &var,
const
std::string &name,
int
num);
235
template
<>
236
ITPP_EXPORT
bool
Parser::get
(
int
&var,
const
std::string &name,
int
num);
238
template
<>
239
ITPP_EXPORT
bool
Parser::get
(
bool
&var,
const
std::string &name,
int
num);
240
241
}
// namespace itpp
242
243
#endif // #ifndef PARSER_H
Generated on Sat May 25 2013 16:32:19 for IT++ by
Doxygen
1.8.2