71void Parser::pre_parsing(
void)
82 Line = SetupStrings(
i);
84 SetupStrings(count) =
Line;
94 for (i = 0; i < SetupStrings.
size(); i++) {
95 Line = SetupStrings(i);
98 for (k = 0; k < (n - 2); k++) {
99 if ((Line[k] ==
'.') && (Line[k+1] ==
'.') && (Line[k+2] ==
'.')) {
105 for (j = 0; j < k; j++) { NewLine += Line[j]; }
109 SetupStrings(count) = NewLine;
118 for (i = 0; i <
size; i++) {
120 Line = SetupStrings(i);
121 n = int(Line.length());
139 while ((j < n) && (Line[j] !=
']')) { NewLine += Line[j]; j++; }
140 if (j < n) { NewLine += Line[j]; j++; }
144 while ((j < n) && (Line[j] !=
'}')) { NewLine += Line[j]; j++; }
145 if (j < n) { NewLine += Line[j]; j++; }
151 while ((j < n) && (Line[j] !=
'"')) { NewLine += Line[j]; j++; }
159 while ((j < n) && (Line[j] !=
'\'')) { NewLine += Line[j]; j++; }
174 SetupStrings(i) = NewLine;
181 for (i = 0; i <
size; i++) {
184 Line = SetupStrings(i);
185 n = int(Line.length());
194 while ((j < n) && (Line[j] !=
']')) { NewLine += Line[j]; j++; }
195 if (Line[j] ==
']') { NewLine += Line[j]; j++; }
197 if (count >= TempSetupStrings.
size()) { TempSetupStrings.
set_size(2*count,
true); }
198 TempSetupStrings(count) = NewLine;
208 while ((j < n) && (Line[j] !=
'"')) { NewLine += Line[j]; j++; }
209 if (Line[j] ==
'"') { NewLine += Line[j]; j++; }
211 if (count >= TempSetupStrings.
size()) { TempSetupStrings.
set_size(2*count,
true); }
212 TempSetupStrings(count) = NewLine;
223 while ((j < n) && (Line[j] !=
'\'')) { NewLine += Line[j]; j++; }
224 if (Line[j] ==
'\'') { NewLine += Line[j]; j++; }
226 if (count >= TempSetupStrings.
size()) { TempSetupStrings.
set_size(2*count,
true); }
227 TempSetupStrings(count) = NewLine;
235 if (count >= TempSetupStrings.
size()) { TempSetupStrings.
set_size(2*count,
true); }
236 TempSetupStrings(count) = NewLine;
244 if (count >= TempSetupStrings.
size()) { TempSetupStrings.
set_size(2*count,
true); }
245 TempSetupStrings(count) = NewLine +
';';
256 if (count >= TempSetupStrings.
size()) { TempSetupStrings.
set_size(2*count,
true); }
257 TempSetupStrings(count) = NewLine;
268 TempSetupStrings.
set_size(count,
true);
269 SetupStrings = TempSetupStrings;
278 "Parser::init(): Could not open `" +
filename +
"' file");
282 SetupStrings(SetupStrings.
size() - 1) =
Line;
295 SetupStrings(
i) =
argv[
i];
306 "Parser::init(): Could not open `" +
filename +
"' file");
311 SetupStrings(
i) =
argv[
i];
317 SetupStrings(SetupStrings.
size() - 1) =
Line;
326 SetupStrings = setup;
348bool Parser::get(std::string &var,
const std::string &name,
int num)
354 cout << name <<
" = '" << var <<
"';" << endl;
360 cout << name <<
" = '" << var <<
"'" << endl;
363 cout << name <<
" = '" << var <<
"';" << endl;
370bool Parser::get(
int &var,
const std::string &name,
int num)
373 bool error_flag, print_flag;
374 out = ivec(findname(name, error_flag, print_flag, num));
377 cout << name <<
" = " << var <<
";" << endl;
381 it_assert(out.size() == 1,
"Parser::get(int): Improper variable string: "
385 cout << name <<
" = " << var << endl;
388 cout << name <<
" = " << var <<
";" << endl;
395bool Parser::get(
bool &var,
const std::string &name,
int num)
398 bool error_flag, print_flag;
399 ss = findname(name, error_flag, print_flag, num);
402 cout << name <<
" = " << var <<
";" << endl;
406 if ((ss ==
"true") || (ss ==
"1")) {
409 else if ((ss ==
"false") || (ss ==
"0")) {
413 it_error(
"Parser::get(bool): Improper variable string: " + name);
416 cout << name <<
" = " << var << endl;
419 cout << name <<
" = " << var <<
";" << endl;
432 if ((
ss ==
"true") || (
ss ==
"1")) {
435 else if ((
ss ==
"false") || (
ss ==
"0")) {
439 it_error(
"Parser::get_bool(): Improper variable string: " + name);
441 if (
print_flag) { cout <<
"Parsing bool : " << name <<
" = " <<
out << endl; }
454 cout <<
"Parsing int : " << name <<
" = " <<
out(0) << endl;
466 if (
print_flag) { cout <<
"Parsing double: " << name <<
" = " <<
out << endl; }
476 if (
print_flag) { cout <<
"Parsing string: " << name <<
" = " <<
out << endl; }
486 if (
print_flag) { cout <<
"Parsing vec : " << name <<
" = " <<
out << endl; }
496 if (
print_flag) { cout <<
"Parsing ivec : " << name <<
" = " <<
out << endl; }
506 if (
print_flag) { cout <<
"Parsing svec : " << name <<
" = " <<
out << endl; }
516 if (
print_flag) { cout <<
"Parsing bvec : " << name <<
" = " <<
out << endl; }
526 if (
print_flag) { cout <<
"Parsing mat : " << name <<
" = " <<
out << endl; }
536 if (
print_flag) { cout <<
"Parsing imat : " << name <<
" = " <<
out << endl; }
546 if (
print_flag) { cout <<
"Parsing smat : " << name <<
" = " <<
out << endl; }
556 if (
print_flag) { cout <<
"Parsing bmat : " << name <<
" = " <<
out << endl; }
563 int n,
j = 0,
i = 0, index = -1;
572 while (i < SetupStrings.
size()) {
573 Line = SetupStrings(i);
577 if (Line.find_first_of(
"=") != std::string::npos) {
578 Name = Line.substr(0, Line.find_first_of(
"="));
595 if ((found) && (index + num <= SetupStrings.
size())) {
596 Line = SetupStrings(index + num);
601 Temp = Line.substr(Line.find_first_of(
"=") + 1);
610 n = int(Temp.size());
612 for (i = 0; i < n; i++) {
616 if (keep_brackets) { Out += Temp[i]; }
617 if (i == (n - 1)) { print_flag =
true; }
620 if (keep_brackets) { Out += Temp[i]; }
621 if (i == (n - 1)) { print_flag =
true; }
624 if (i == (n - 1)) { print_flag =
true; }
627 if (i == (n - 1)) { print_flag =
true; }
630 if (i == (n - 1)) { print_flag =
false; }
631 else { Out += Temp[i]; }
635 if (i == (n - 1)) { print_flag =
true; }
645 n = int(Temp.size());
648 while ((Temp[j] ==
' ') || (Temp[j] ==
'\t') || (Temp[j] ==
'\n')) { j++; }
649 while ((Temp[n-1] ==
' ') || (Temp[n-1] ==
'\t') || (Temp[n-1] ==
'\n')) { n--; }
654 while ((j < n) && (Temp[j] !=
' ') && (Temp[j] !=
'\t') && (Temp[j] !=
'\n') && (Temp[j] !=
',') && (Temp[j] !=
';')) {
662 while ((j < n) && ((Temp[j] ==
' ') || (Temp[j] ==
'\t') || (Temp[j] ==
'\n'))) { j++; }
665 if (Temp[j] ==
';') { Out +=
';'; j++; }
666 else if (Temp[j] ==
',') { Out +=
' '; j++; }
667 else if (Temp[j] ==
'+') { Out +=
' '; Out += Temp[j]; j++; }
668 else if (Temp[j] ==
'-') { Out +=
' '; Out += Temp[j]; j++; }
672 while ((j < n) && ((Temp[j] ==
' ') || (Temp[j] ==
'\t') || (Temp[j] ==
'\n'))) { j++; }
678 if (!VERBOSE) print_flag =
false;
int size() const
Returns the number of data elements in the array object.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
int length() const
Returns the number of data elements in the array object.
Automatic naming when saving.
double get_double(const std::string &name, int num=-1)
Interpret variable name as a double.
void set_silentmode(bool v=true)
Sets silent mode if true, or verbose mode if false.
svec get_svec(const std::string &name, int num=-1)
Interpret variable name as a svec.
mat get_mat(const std::string &name, int num=-1)
Interpret variable name as a mat.
int get_int(const std::string &name, int num=-1)
Interpret variable name as an integer.
ivec get_ivec(const std::string &name, int num=-1)
Interpret variable name as a ivec.
bvec get_bvec(const std::string &name, int num=-1)
Interpret variable name as a bvec.
imat get_imat(const std::string &name, int num=-1)
Interpret variable name as a imat.
bool get_bool(const std::string &name, int num=-1)
Interpret variable name as a bool.
void init(const std::string &filename)
Initialization function. Sets input file name.
Parser()
Default Constructor.
smat get_smat(const std::string &name, int num=-1)
Interpret variable name as a smat.
std::string get_string(const std::string &name, int num=-1)
Interpret variable name as a string.
bool get(T &var, const std::string &name, int num=-1)
Get variable value if name can be found (and return true), otherwise keep old value (and return false...
bool exist(const std::string &name)
Check is name exists in the file. Returns true if the name is found and false otherwise.
vec get_vec(const std::string &name, int num=-1)
Interpret variable name as a vec.
bmat get_bmat(const std::string &name, int num=-1)
Interpret variable name as a bmat.
#define it_error(s)
Abort unconditionally.
#define it_assert(t, s)
Abort if t is not true.
int size(const Vec< T > &v)
Length of vector.
Mat< bin > bmat
bin matrix
Definition of an argument parser class.