Пример #1
0
void SaveIni(INIFile &theINI, const char *filename)
{
	std::fstream file(filename, std::ios::out);
	if(!file.good())
		return;
	
	// just iterate the hashes and values and dump them to a file.
	INIFile::iterator section= theINI.begin();
	while(section != theINI.end())
	{
		if(section->first > "") 
			file << std::endl << "[" << section->first << "]" << std::endl;
		INISection::iterator pair = section->second.begin();
	
		while(pair != section->second.end())
		{
			if(pair->second > "")
				file << pair->first << "=" << pair->second << std::endl;
			else
				file << pair->first << std::endl;
			pair++;
		}
		section++;
	}
	file.close();
}
Пример #2
0
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);
	}
}
Пример #3
0
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;
}
Пример #4
0
void DumpIni(INIFile &ini)
{
	// This is essentially SaveIni() except it just dumps to stdout
	INIFile::iterator section= ini.begin();
	while(section != ini.end())
	{
		cout << std::endl << "[" << section->first << "]" << std::endl;
		INISection sectionvals = section->second;
		INISection::iterator pair = sectionvals.begin();
	
		while(pair != sectionvals.end())
		{
			cout << pair->first ;
			if(pair->second > "")
				cout << "=" << pair->second;
			cout << std::endl;
			pair++;
		}
		section++;
	}
}
Пример #5
0
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)) );
	}
}