#ifndef INIFILE_H #define INIFILE_H #include #include #include template std::string ss_conv_from(T value) { std::ostringstream temp_ss; temp_ss << value; return temp_ss.str(); } template T ss_conv_to(std::string value) { std::istringstream temp_ss(value); T tmp; temp_ss >> tmp; return tmp; } struct IniItem { std::string name; std::string value; IniItem(std::string name); IniItem(std::string name, std::string value); void SetValue(std::string value); }; typedef std::list IniItemList; struct IniGroup { std::string name; IniItemList items; IniGroup(std::string name); ~IniGroup(); IniItem *GetItem(std::string name); IniItem *GetItem(std::string name, std::string default_value); std::string GetValue(std::string name, std::string default_value) { IniItem *item = GetItem(name, default_value); return item->value; } void SetValue(std::string name, std::string value) { IniItem *item = GetItem(name); item->value = value; } std::string GetValue(std::string name, const char *default_value) { IniItem *item = GetItem(name, default_value); return item->value; } template T GetValue(std::string name, T default_value) { std::string value = ss_conv_from(default_value); IniItem *item = GetItem(name, value); return ss_conv_to(item->value); } template void SetValue(std::string name, T value) { IniItem *item = GetItem(name); item->value = ss_conv_from(value); } }; typedef std::list IniGroupList; struct IniFile { IniGroupList groups; ~IniFile(); IniGroup *GetGroup(std::string name); void RemoveGroup(std::string name); void LoadFromDisk(std::string filename); void SaveToDisk(std::string filename); }; #endif // INIFILE_H