58 static const char rcsid[] =
"$Id: config.cpp,v 1.20 2006/05/16 19:24:26 gourdeau Exp $";
69 bPrintErrorMessages = bPrintErrorMessages_;
97 getline(inconffile, temp);
99 while( !inconffile.eof() )
102 if(temp.substr(0,1) !=
"#")
105 if(temp.substr(0,1) ==
"[")
108 tmpPos = temp.find(
"]");
109 if (tmpPos != string::npos)
111 data.
section = temp.substr(1, tmpPos-1);
113 getline(inconffile, temp);
115 while( (temp.substr(0,1) !=
"[") &&
116 (!inconffile.eof()) )
118 if(temp.substr(0,1) !=
"#")
120 if(temp.find(
":") != string::npos)
122 istringstream inputString(temp);
125 while(inputString >> tmp_value)
127 data.
value.append(
" ");
128 data.
value.append(tmp_value);
132 if (tmpPos != string::npos)
137 inputString >> data.
value;
139 while(inputString >> tmp_value)
141 data.
value.append(
" ");
142 data.
value.append(tmp_value);
147 conf.push_back(data);
151 getline(inconffile, temp);
156 getline(inconffile, temp);
162 if(temp.substr(0,1) !=
"[") {
163 getline(inconffile, temp);
169 if (bPrintErrorMessages)
171 cerr <<
"Config::read_conf: invalid input ifstream " << endl;
188 for(Conf_data::iterator iter = conf.begin(); iter != conf.end(); ++iter)
190 if (tmpSection != iter->section)
193 tmpSection = iter->section;
194 cout <<
"\n[" << tmpSection <<
"]" << endl;
195 cout << iter->parameter+
":" <<
" " << iter->value << endl;
198 cout << iter->parameter+
":" <<
" " << iter->value << endl;
208 for(Conf_data::const_iterator iter = conf.begin(); iter != conf.end(); ++iter)
209 if(iter->section == section)
220 for(Conf_data::const_iterator iter = conf.begin(); iter != conf.end(); ++iter)
221 if( (iter->section == section) && (iter->parameter == parameter) )
227 const int space_between_column)
237 outconffile <<
"# ---------------------------------------------------" << endl;
238 outconffile <<
"# " << file_title << endl;
239 outconffile <<
"# ---------------------------------------------------" << endl;
244 for(Conf_data::iterator iterConf = conf.begin(); iterConf != conf.end(); ++iterConf)
246 if(section != iterConf->section)
248 section = iterConf->section;
249 outconffile <<
"\n[" << section <<
"]\n" << endl;
251 outconffile << setw(space_between_column-iterConf->parameter.size())
252 << iterConf->parameter +
":" <<
" " << iterConf->value << endl;
258 if (bPrintErrorMessages)
260 cerr <<
"Config::write_conf: invalid input ofstream " << endl;
bool section_exists(const std::string §ion) const
Test to see if a section exists.
short read_conf(std::ifstream &inconffile)
Read a configuration file.
Basic data element used in Config class.
void print()
Print the configuration data.
Header file for Config class definitions.
#define CAN_NOT_OPEN_FILE
Return when can not open file.
Config(const bool bPrintErrorMessages=true)
Constructor.
static const char rcsid[]
RCS/CVS version.
short write_conf(std::ofstream &outconffile, const std::string &file_title, const int space_between_column)
Write the configuration information, contained in conf, on disk.
void clear()
Clear the data buffer.
#define CAN_NOT_CREATE_FILE
Return when can not create a file.
bool parameter_exists(const std::string §ion, const std::string ¶meter) const
Test to see if a parameter exists within a section.