-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcconfig.cpp
More file actions
70 lines (58 loc) · 1.48 KB
/
cconfig.cpp
File metadata and controls
70 lines (58 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <string>
#include "cconfig.h"
#include "error.h"
cConfig::cConfig(const char *filename) : ok(0)
{
ifile.open(filename, std::fstream::in);
linenum = 0; // number of lines read
if (!ifile.is_open()) {
printf("error: can not open %s\n", filename);
};
ok = 1;
BadPrevRead=0;
}
dReal cConfig::get_dReal()
{
std::string str;
*iss >> str;
if (str == "dInfinity")
return dInfinity;
std::istringstream* iss = new std::istringstream(str.data());
dReal t;
*iss >> t;
delete iss;
return t;
}
void cConfig::read(const char *astring, int optional)
{
//PEXP(BadPrevRead);
// first check if we have a string already (from a bad / non existant previous read)
if (!BadPrevRead) { // no bad previous read
line[0] = '#';
// skip comment lines
while (line[0] == '#') {
ifile.getline(line, sizeof(line));
linenum++; // advance line count
}
iss = new std::istringstream(line);
// read name
*iss >> name;
}
// any way (bad previous read / not bad) test the name
if (name != astring) {
if (optional) {
BadPrevRead = 1;
return;
}
std::cout << "error: line number " << linenum <<
" must begin with *" << astring << "* in param.dat\n";
std::cout << "error: offending line: *" << line << "*\n";
std::cout << "debug: name value: " << name << "\n";
std::cout << "debug: astring size, name size " <<
strlen(astring) << ", " << name.length() << "\n";
exit(-1);
}
BadPrevRead = 0;
//printf("debug: %s\n", name.data());
}