27#include "configuration_config.hpp"
47 : m_multiSections(multiSections),
48 m_options(std::unique_ptr<Options>(new Options())),
49 m_sections(std::unique_ptr<Sections>(new Sections()))
59 : m_multiSections(other.m_multiSections),
60 m_options(std::unique_ptr<Options>(new Options(*(other.m_options)))),
61 m_sections(std::unique_ptr<Sections>(new Sections()))
63 for (
const auto &entry : *(other.m_sections)) {
64 std::unique_ptr<Config> config = std::unique_ptr<Config>(
new Config(*(entry.second)));
65 m_sections->insert(std::make_pair(entry.first, std::move(config)));
89 std::swap(m_multiSections, other.m_multiSections);
90 std::swap(m_options, other.m_options);
91 std::swap(m_sections, other.m_sections);
102 return m_multiSections;
112 return m_options->size();
122 return const_cast<Options &
>(
static_cast<const Config &
>(*this).
getOptions());
143 return (m_options->count(key) > 0);
156 return m_options->at(key);
170std::string
Config::get(
const std::string &key,
const std::string &fallback)
const
187 (*m_options)[key] = value;
198 return (m_options->erase(key) != 0);
208 return m_sections->size();
219 return m_sections->count(key);
250 MultiSection sections;
253 auto range = m_sections->equal_range(key);
254 for (
auto itr = range.first; itr != range.second; ++itr) {
255 sections.push_back(itr->second.get());
269 ConstMultiSection sections;
272 auto range = m_sections->equal_range(key);
273 for (
auto itr = range.first; itr != range.second; ++itr) {
274 sections.push_back(
const_cast<const Section *
>(itr->second.get()));
314 auto sectionItr = m_sections->find(key);
315 if (sectionItr == m_sections->end()) {
316 throw std::runtime_error(
"The section named \"" + key +
"\" does not esists");
319 return *(sectionItr->second);
333 throw std::runtime_error(
"A section named \"" + key +
"\" already esists");
336 std::unique_ptr<Section> section = std::unique_ptr<Section>(
new Section(m_multiSections));
337 auto sectionItr = m_sections->insert(std::make_pair(key, std::move(section)));
339 return *(sectionItr->second);
350 return (m_sections->erase(key) != 0);
396 const int INDENT_SIZE = 2;
398 std::string padding(INDENT_SIZE,
' ');
399 std::string indent(INDENT_SIZE * indentLevel,
' ');
402 out << indent <<
"Options..." << std::endl;
405 out << indent << padding << entry.first <<
" = " << entry.second << std::endl;
408 out << indent << padding <<
"No options." << std::endl;
414 out << indent << padding <<
"::: Section " << entry.first <<
" :::" << std::endl;
415 entry.second->dump(out, indentLevel);
void dump(std::ostream &out, int indentLevel=0) const
const std::string & get(const std::string &key) const
Section & addSection(const std::string &key)
Config & operator=(Config other)
Section & operator[](const std::string &key)
Section & getSection(const std::string &key)
bool hasOption(const std::string &key) const
bool isMultiSectionsEnabled() const
int getOptionCount() const
int getSectionCount() const
bool hasSection(const std::string &key) const
void set(const std::string &key, const std::string &value)
bool removeSection(const std::string &key)
bool removeOption(const std::string &key)
Config(bool multiSections=false)