31 bool IniFile::load(
const string &filename)
33 m_filename = filename;
36 m_filename.erase( remove(m_filename.begin(), m_filename.end(),
'\"' ), m_filename.end() );
40 ifstream inputStream(m_filename.c_str());
42 if (!inputStream.is_open()) {
43 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Trying to open a non-existent file [%s] \n", __FUNCTION__, m_filename.c_str());
48 while (getline(inputStream, line)) {
49 size_t splitterPos = line.find(
'=');
50 if (splitterPos < line.length()) {
51 string key = line.substr(0, splitterPos);
52 string value = line.substr(splitterPos+1, line.length());
66 string IniFile::value(
const string &key,
const string &defaultValue)
const
68 map<string,string>::const_iterator it = m_dict.find(key);
69 if (it == m_dict.end()) {
76 bool IniFile::setValue(
const string &key,
const string &value)
78 if (m_filename.empty()) {
92 ofstream outputStream(m_filename.c_str());
93 if (!outputStream.is_open()) {
94 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: Will not write, open on file [%s] failed \n", __FUNCTION__, m_filename.c_str());
98 for (map<string,string>::const_iterator it = m_dict.begin(); it != m_dict.end(); ++it) {
99 outputStream << it->first <<
'=' << it->second << endl;
103 outputStream.close();