ini: use reference to avoid copies. simplify

This commit is contained in:
Flyinghead 2019-09-30 15:33:19 +02:00
parent 6ab8b185c8
commit 834082519d
2 changed files with 8 additions and 10 deletions

View File

@ -7,7 +7,7 @@ namespace emucfg {
/* ConfigEntry */
string ConfigEntry::get_string()
const string& ConfigEntry::get_string() const
{
return this->value;
}
@ -269,19 +269,17 @@ void ConfigFile::parse(FILE* file)
void ConfigFile::save(FILE* file)
{
for(std::map<string, ConfigSection>::iterator section_it = this->sections.begin();
section_it != this->sections.end(); section_it++)
for (const auto& section_it : this->sections)
{
string section_name = section_it->first;
ConfigSection section = section_it->second;
const string& section_name = section_it.first;
const ConfigSection& section = section_it.second;
fprintf(file, "[%s]\n", section_name.c_str());
for(std::map<string, ConfigEntry>::iterator entry_it = section.entries.begin();
entry_it != section.entries.end(); entry_it++)
for (const auto& entry_it : section.entries)
{
string entry_name = entry_it->first;
ConfigEntry entry = entry_it->second;
const string& entry_name = entry_it.first;
const ConfigEntry& entry = entry_it.second;
fprintf(file, "%s = %s\n", entry_name.c_str(), entry.get_string().c_str());
}

View File

@ -6,7 +6,7 @@ namespace emucfg {
struct ConfigEntry {
std::string value;
std::string get_string();
const std::string& get_string() const;
int get_int();
bool get_bool();
};