62 init(filename, argc, argv);
71 void Parser::pre_parsing(
void)
77 std::string Line, NewLine;
81 for (i = 0; i <
size; i++) {
82 Line = SetupStrings(i);
83 if ((Line.length() != 0) && (Line[0] !=
'%')) {
84 SetupStrings(count) = Line;
89 size = SetupStrings.
size();
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;
117 size = SetupStrings.
size();
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;
179 TempSetupStrings.
set_size(size,
false);
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;
276 std::ifstream SetupFile(filename.c_str());
278 "Parser::init(): Could not open `" + filename +
"' file");
280 while (getline(SetupFile, Line,
'\n')) {
282 SetupStrings(SetupStrings.
size() - 1) = Line;
294 for (i = 0; i < argc; i++) {
295 SetupStrings(i) = argv[i];
304 std::ifstream SetupFile(filename.c_str());
306 "Parser::init(): Could not open `" + filename +
"' file");
310 for (i = 0; i < argc; i++) {
311 SetupStrings(i) = argv[i];
315 while (getline(SetupFile, Line,
'\n')) {
317 SetupStrings(SetupStrings.
size() - 1) = Line;
326 SetupStrings = setup;
337 bool error_flag, print_flag;
338 std::string temp = findname(name, error_flag, print_flag);
348 bool Parser::get(std::string &var,
const std::string &name,
int num)
350 bool error_flag, print_flag;
351 std::string str = findname(name, error_flag, print_flag, num);
354 cout << name <<
" = '" << var <<
"';" << endl;
360 cout << name <<
" = '" << var <<
"'" << endl;
363 cout << name <<
" = '" << var <<
"';" << endl;
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;
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;
429 bool error_flag, print_flag;
430 ss = findname(name, error_flag, print_flag, num);
431 it_assert(!error_flag,
"Parser::get_bool(): Can not find variable: " + name);
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; }
448 bool error_flag, print_flag;
449 out = ivec(findname(name, error_flag, print_flag, num));
450 it_assert(!error_flag,
"Parser::get_int(): Can not find variable: " + name);
451 it_assert(out.size() == 1,
"Parser::get_int(): Improper variable string: "
454 cout <<
"Parsing int : " << name <<
" = " << out(0) << endl;
462 bool error_flag, print_flag;
463 std::istringstream ss(findname(name, error_flag, print_flag, num));
465 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
466 if (print_flag) { cout <<
"Parsing double: " << name <<
" = " << out << endl; }
473 bool error_flag, print_flag;
474 out = findname(name, error_flag, print_flag, num);
475 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
476 if (print_flag) { cout <<
"Parsing string: " << name <<
" = " << out << endl; }
483 bool error_flag, print_flag;
484 out = vec(findname(name, error_flag, print_flag, num));
485 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
486 if (print_flag) { cout <<
"Parsing vec : " << name <<
" = " << out << endl; }
493 bool error_flag, print_flag;
494 out = ivec(findname(name, error_flag, print_flag, num));
495 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
496 if (print_flag) { cout <<
"Parsing ivec : " << name <<
" = " << out << endl; }
503 bool error_flag, print_flag;
504 out = svec(findname(name, error_flag, print_flag, num));
505 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
506 if (print_flag) { cout <<
"Parsing svec : " << name <<
" = " << out << endl; }
513 bool error_flag, print_flag;
514 out = bvec(findname(name, error_flag, print_flag, num));
515 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
516 if (print_flag) { cout <<
"Parsing bvec : " << name <<
" = " << out << endl; }
523 bool error_flag, print_flag;
524 out = mat(findname(name, error_flag, print_flag, num));
525 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
526 if (print_flag) { cout <<
"Parsing mat : " << name <<
" = " << out << endl; }
533 bool error_flag, print_flag;
534 out = imat(findname(name, error_flag, print_flag, num));
535 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
536 if (print_flag) { cout <<
"Parsing imat : " << name <<
" = " << out << endl; }
543 bool error_flag, print_flag;
544 out = smat(findname(name, error_flag, print_flag, num));
545 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
546 if (print_flag) { cout <<
"Parsing smat : " << name <<
" = " << out << endl; }
553 bool error_flag, print_flag;
554 out =
bmat(findname(name, error_flag, print_flag, num));
555 if (error_flag) {
it_error(
"Parser: Can not find variable: " + name); }
556 if (print_flag) { cout <<
"Parsing bmat : " << name <<
" = " << out << endl; }
560 std::string Parser::findname(
const std::string &name,
bool &error_flag,
bool &print_flag,
int num,
bool keep_brackets)
562 std::string
Name, Out, Line, Temp;
563 int n, j = 0, i = 0, index = -1;
564 bool found =
false, vec_mat =
false;
568 if (num < 0) { num = 0; }
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;