Cleanup: Combine Section and BasicConfig, move to basics

This commit is contained in:
Vinnie Falco
2014-10-09 12:25:24 -07:00
parent 9a0a434dd8
commit 4ab427d315
15 changed files with 157 additions and 148 deletions

View File

@@ -217,70 +217,6 @@ parseAddresses (OutputSequence& out, InputIterator first, InputIterator last,
}
}
//------------------------------------------------------------------------------
//
// BasicConfig
//
//------------------------------------------------------------------------------
bool
BasicConfig::exists (std::string const& name) const
{
return map_.find (name) != map_.end();
}
Section const&
BasicConfig::section (std::string const& name) const
{
static Section none;
auto const iter = map_.find (name);
if (iter == map_.end())
return none;
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.keys() != 0)
return;
if (iter->second.lines().size() != 1)
return;
auto& s = map_[new_section];
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)
{
auto const result = map_.emplace (section, Section{});
result.first->second.set (key, value);
}
void
BasicConfig::build (IniFileSections const& ifs)
{
for (auto const& entry : ifs)
{
auto const result = map_.emplace (entry.first, Section{});
result.first->second.append (entry.second);
}
}
std::ostream&
operator<< (std::ostream& ss, BasicConfig const& c)
{
for (auto const& s : c.map_)
ss << "[" << s.first << "]\n" << s.second;
return ss;
}
//------------------------------------------------------------------------------
//
// Config (DEPRECATED)