- fixed global preferences serialization

- global_preferences.??
- fixed key=value configuration class
  - key_file.??
 


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@767 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
paolo 2006-07-15 11:25:57 +00:00
parent 8a43216527
commit 2b31d6d2eb
4 changed files with 331 additions and 12 deletions

View file

@ -23,6 +23,9 @@
#include <fstream>
#include <string.h>
#include <iostream>
using namespace std;
namespace sgpem
{
@ -70,14 +73,23 @@ namespace sgpem
{
std::ifstream ifs(filename.c_str());
if(ifs)
{
file_read(ifs);
} // end - if(ifs)
}
void
KeyFile::file_read(std::istream& is)
{
if(is)
{
_elements.clear(); // erase all elements
char buff[KEY_FILE_BUF_LEN]; //
while(ifs)
while(is)
{
ifs.getline(buff, sizeof(buff));
is.getline(buff, (KEY_FILE_BUF_LEN), '\n');
// if not a comment line...
if(*buff!='\0' && *buff!='#')
{
char* pos = strchr(buff, '=');
@ -89,7 +101,8 @@ namespace sgpem
insert_key_value(key, value);
}
} // end - if not a comment line...
} // end - while(ifs)
} // end - while(ifs))
} // end - if(ifs)
}
@ -98,11 +111,21 @@ namespace sgpem
{
std::ofstream ofs(filename.c_str());
if(ofs)
{
file_write(ofs);
} // end - if(ofs)
}
void
KeyFile::file_write(std::ostream& os)
{
if(os)
{
elements_iterator iter;
for(iter = elements_begin(); iter != elements_end(); iter++){
ofs << (*iter).first << "=" << (*iter).second << std::endl;
os << (*iter).first << "=" << (*iter).second << std::endl;
}
} // end - if(ofs)
}
}