23 #ifndef _PARAMETER_TREE_PARSER_HH_
24 #define _PARAMETER_TREE_PARSER_HH_
30 class ParameterTreeParser;
35 static std :: string
ltrim(
const std :: string &s);
36 static std :: string
rtrim(
const std :: string &s);
41 bool overwrite =
true);
45 const std :: string srcname,
53 std :: ifstream in( file.c_str() );
56 std :: cerr <<
"IOError : Could not open configuration file " << file <<
"\n\nCalling exit(1)\n";
60 readINITree(in, pt,
"file '" + file +
"'", overwrite);
65 const std :: string srcname,
68 std :: set< std :: string > keysInFile;
74 switch ( line [ 0 ] ) {
79 std :: string :: size_type comment = line.find(
"#");
80 line = line.substr(0, comment);
81 std :: string :: size_type mid = line.find(
"=");
82 if ( mid != std :: string :: npos ) {
83 std :: string key =
rtrim(
ltrim( line.substr(0, mid) ) );
84 std :: string value =
ltrim( line.substr(mid + 1) );
86 if ( value.length() > 0 ) {
88 if ( ( value [ 0 ] ==
'\'' )or(value [ 0 ] ==
'"') ) {
89 char quote = value [ 0 ];
90 value = value.substr(1);
91 while ( * (
rtrim(value).rbegin() ) != quote ) {
95 value = value +
"\n" + l;
97 value = value + quote;
101 value =
rtrim(value);
102 value = value.substr(0, value.length() - 1);
104 value =
rtrim(value);
108 if ( keysInFile.count(key) != 0 ) {
109 std :: cerr <<
"Exception, " <<
"Key '" << key <<
"' appears twice in " << srcname <<
" !" <<
"\n\nCalling exit(1)\n";
112 if ( overwrite || !pt.
hasKey(key) ) {
116 keysInFile.insert(key);
127 std :: size_t firstNonWS = s.find_first_not_of(
" \t\n\r");
129 if ( firstNonWS != std :: string :: npos ) {
130 return s.substr(firstNonWS);
133 return std :: string();
138 std :: size_t lastNonWS = s.find_last_not_of(
" \t\n\r");
140 if ( lastNonWS != std :: string :: npos ) {
141 return s.substr(0, lastNonWS + 1);
144 return std :: string();