52 void ConfDataReader::loadData(
void)
56 std::string sectionName(
"DEFAULT");
68 formattedGetLine(line,
true);
73 ConfigurationException e(
74 "Line too long in configuration file '" +
79 if(line.size()<1)
continue;
85 formattedGetLine(line,
true);
89 std::string::size_type idx(line.find(
'#'));
90 if( !(idx == std::string::npos) )
92 line = line.substr(0, idx);
96 if( !(idx == std::string::npos) )
98 line = line.substr(0, idx);
116 idx = line.find(
'[');
117 if( !(idx == std::string::npos) )
121 std::string::size_type idx2(line.find(
']'));
122 if( !(idx2 == std::string::npos) )
128 if( checkName(line) )
138 ConfigurationException e(
140 line +
"' in configuration file '" +
142 "' does not comply with rules.");
154 ConfigurationException e(
157 "' in configuration file '" +
159 "' was improperly closed" );
169 idx = line.find(
'=');
170 if( idx == std::string::npos )
172 idx = line.find(
':');
177 if( !(idx == std::string::npos) )
187 std::string varComment;
189 idx = variable.find(
',');
190 if( !(idx == std::string::npos) )
197 if( checkName(variable) )
206 ConfigurationException e(
208 variable +
"' in configuration file '" +
210 "' does not comply with rules.");
216 std::string valueComment;
218 idx = value.find(
',');
219 if( !(idx == std::string::npos) )
228 varData.
value = value;
231 confData[sectionName][variable] = varData;
236 catch (ConfigurationException& e)
244 itCurrentSection = confData.begin();
268 string ConfDataReader::getValue(
string variable,
282 bool exceptionState( getIssueException() );
287 if( (section !=
"DEFAULT") && (section !=
"") )
289 if( getFallback2Default() )
291 setIssueException(
false);
297 if( ifExist(variable, section) )
301 setIssueException( exceptionState );
303 return confData[section][variable].value;
310 setIssueException( exceptionState );
313 if ( getFallback2Default() )
316 if( ifExist(variable) )
319 return confData[
"DEFAULT"][variable].value;
340 catch (ConfigurationException& e)
357 bool ConfDataReader::getValueAsBoolean(
string variable,
370 string result( getValue( variable, section ) );
387 if( result ==
"TRUE" )
396 if( result ==
"FALSE" )
406 ConfigurationException e(
408 variable +
"' in configuration file '" +
410 "' is neither TRUE nor FALSE.");
419 catch (ConfigurationException& e)
440 string ConfDataReader::fetchListValue(
string variableList,
453 string origValue( getValue(variableList, section) );
463 return ( (value==
"") ?
string(defaultVal) : value );
466 catch (ConfigurationException& e)
487 bool ConfDataReader::fetchListValueAsBoolean(
string variableList,
500 string result( fetchListValue(variableList,section) );
505 if( result ==
"TRUE" )
514 if( (result ==
"FALSE") ||
525 ConfigurationException e(
527 variableList +
"' in configuration file '" +
529 "' have a value that is neither TRUE " +
539 catch (ConfigurationException& e)
554 string ConfDataReader::getVariableDescription(
string variable,
566 bool exceptionState( getIssueException() );
571 if( (section !=
"DEFAULT") && (section !=
"") )
573 if( getFallback2Default() )
575 setIssueException(
false);
581 if( ifExist(variable, section) )
585 setIssueException( exceptionState );
587 return confData[section][variable].varComment;
594 setIssueException( exceptionState );
597 if ( getFallback2Default() )
600 if( ifExist(variable) )
603 return confData[
"DEFAULT"][variable].varComment;
624 catch (ConfigurationException& e)
639 string ConfDataReader::getValueDescription(
string variable,
651 bool exceptionState( getIssueException() );
656 if( (section !=
"DEFAULT") && (section !=
"") )
658 if( getFallback2Default() )
660 setIssueException(
false);
666 if( ifExist(variable, section) )
670 setIssueException( exceptionState );
672 return confData[section][variable].valueComment;
679 setIssueException( exceptionState );
682 if ( getFallback2Default() )
685 if( ifExist(variable) )
688 return confData[
"DEFAULT"][variable].valueComment;
709 catch (ConfigurationException& e)
724 bool ConfDataReader::ifExist(
string variable,
733 confMap::const_iterator it;
734 it = confData.find(section);
735 if( it != confData.end() )
737 variableMap::const_iterator it2;
738 it2 = (*it).second.find(variable);
739 if( it2 != (*it).second.end() )
753 ConfigurationException e(
754 "Variable '" + variable
755 +
"' in section '" + section
756 +
"' of configuration file '" + filename
757 +
"' does not exist.");
779 if ( section ==
"DEFAULT" )
783 ConfigurationException e(
784 "Section 'DEFAULT' in configuration file '"
786 +
"' does not exist. Does file '"
787 + filename +
"' exist?. Do you have "
788 +
"permission to read it?." );
797 ConfigurationException e(
798 "Section '" + section
799 +
"' in configuration file '" + filename
800 +
"' does not exist.");
821 void ConfDataReader::open(
const char*
fn)
825 FFTextStream::open(
fn, std::ios::in);
836 string ConfDataReader::getEachSection(
void)
839 if ( itCurrentSection != confData.end() )
843 string result( (*itCurrentSection).first );
866 bool ConfDataReader::checkName(
string name)