BasicConfig support for legacy values:

* A legacy value is a config section with a single-line.
* These values may be read from the BasicConfig interface so
  the deprecated Config class does not need to be exposed to
  clients.
* Made Config class more testable.
This commit is contained in:
seelabs
2015-02-03 12:03:39 -08:00
committed by Tom Ritchford
parent b11ad375cd
commit 617d84c0ef
13 changed files with 691 additions and 317 deletions

View File

@@ -106,24 +106,6 @@ BasicConfig::section (std::string const& name) const
return iter->second;
}
void
BasicConfig::remap (std::string const& legacy_section,
std::string const& key, std::string const& new_section)
{
auto const iter = map_.find (legacy_section);
if (iter == map_.end())
return;
if (iter->second.size() != 0)
return;
if (iter->second.lines().size() != 1)
return;
auto result = map_.emplace(std::piecewise_construct,
std::make_tuple(new_section), std::make_tuple(new_section));
auto& s = result.first->second;
s.append (iter->second.lines().front());
s.set (key, iter->second.lines().front());
}
void
BasicConfig::overwrite (std::string const& section, std::string const& key,
std::string const& value)
@@ -133,6 +115,18 @@ BasicConfig::overwrite (std::string const& section, std::string const& key,
result.first->second.set (key, value);
}
void
BasicConfig::legacy(std::string const& section, std::string value)
{
map_[section].legacy(std::move(value));
}
std::string
BasicConfig::legacy(std::string const& sectionName) const
{
return section (sectionName).legacy ();
}
void
BasicConfig::build (IniFileSections const& ifs)
{