//---------------------------------------------------------------------------
CONFIGFILE::~CONFIGFILE()
{
+Flush();
}
//---------------------------------------------------------------------------
const string & CONFIGFILE::GetFileName() const
return fileName;
}
//---------------------------------------------------------------------------
-int CONFIGFILE::Error()
+int CONFIGFILE::Error() const
{
int e = error;
error = 0;
return e;
}
//---------------------------------------------------------------------------
-int CONFIGFILE::Flush()
+int CONFIGFILE::Flush() const
{
ofstream f(fileName.c_str());
if (!f.is_open())
while (it != param_val.end())
{
f << it->first << "=" << it->second << "\n";
- it++;
+ ++it;
}
f.close();
*val = defaultVal;
return -1;
}
-/*//---------------------------------------------------------------------------
-int CONFIGFILE::WriteString(const string & param, const char * val)
-{
-WriteString(param, string(val));
-return 0;
-}*/
//---------------------------------------------------------------------------
-int CONFIGFILE::WriteString(const string & param, const string &val)
+void CONFIGFILE::WriteString(const string & param, const string &val)
{
param_val[param] = val;
-Flush();
-return 0;
}
//---------------------------------------------------------------------------
int CONFIGFILE::ReadTime(const string & param, time_t * val, time_t defaultVal) const
return -1;
}
//---------------------------------------------------------------------------
-int CONFIGFILE::WriteInt(const string & param, int64_t val)
+void CONFIGFILE::WriteInt(const string & param, int64_t val)
{
string s;
-//sprintf(s, "%lld", val);
x2str(val, s);
param_val[param] = s;
-Flush();
-return 0;
}
//---------------------------------------------------------------------------
int CONFIGFILE::ReadDouble(const string & param, double * val, double defaultVal) const
return -1;
}
//---------------------------------------------------------------------------
-int CONFIGFILE::WriteDouble(const string & param, double val)
+void CONFIGFILE::WriteDouble(const string & param, double val)
{
char s[30];
-sprintf(s, "%f", val);
+snprintf(s, 30, "%f", val);
param_val[param] = s;
-Flush();
-return 0;
}
//---------------------------------------------------------------------------
int ReadULongLongInt(const string & param, uint64_t *, uint64_t) const;
int ReadDouble(const string & param, double * val, double defaultVal) const;
- int WriteString(const string & param, const char * val) { return WriteString(param, std::string(val)); }
- int WriteString(const string & param, const string & val);
- int WriteInt(const string & param, int64_t val);
- int WriteDouble(const string & param, double val);
+ void WriteString(const string & param, const char * val) { return WriteString(param, std::string(val)); }
+ void WriteString(const string & param, const string & val);
+ void WriteInt(const string & param, int64_t val);
+ void WriteDouble(const string & param, double val);
- int Error();
+ int Error() const;
+ int Flush() const;
private:
- int Flush();
-
map<string, string, StringCaseCmp_t> param_val;
string fileName;
- int error;
+ mutable int error;
};
//---------------------------------------------------------------------------
#endif