void RemoveIniSetting(INIFile &theINI, const char *section, const char *key) { INIFile::iterator iSection = theINI.find(std::string(section)); if(iSection != theINI.end()) { INISection::iterator apair = iSection->second.find(std::string(key)); if(apair != iSection->second.end()) iSection->second.erase(apair); } }
std::string GetIniSetting(INIFile &theINI, const char *section, const char *key, const char *defaultval) { std::string result(defaultval); INIFile::iterator iSection = theINI.find(std::string(section)); if(iSection != theINI.end()) { INISection::iterator apair = iSection->second.find(std::string(key)); if(apair != iSection->second.end()) result = apair->second; } return result; }
void PutIniSetting(INIFile &theINI, const char *section, const char *key, const char *value) { INIFile::iterator iniSection; INISection::iterator apair; if((iniSection = theINI.find(std::string(section))) == theINI.end()) { // no such section? Then add one.. INISection newsection; if(key) newsection.insert( std::pair<std::string, std::string> (std::string(key), std::string(value)) ); theINI.insert( std::pair<std::string, INISection> (std::string(section), newsection) ); } else if(key) { // found section, make sure key isn't in there already, // if it is, just drop and re-add apair = iniSection->second.find(std::string(key)); if(apair != iniSection->second.end()) iniSection->second.erase(apair); iniSection->second.insert( std::pair<std::string, std::string> (std::string(key), std::string(value)) ); } }