mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Cleanup: Combine Section and BasicConfig, move to basics
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user