# HG changeset patch # User David Demelier # Date 1390485410 -3600 # Node ID 1ffe6d4937b796f786f296867a767477449c9321 # Parent 99d0887395cc00419be9167b70c449f6281263db Update parser for more convenience and types security #224 diff -r 99d0887395cc -r 1ffe6d4937b7 C++/Parser.cpp --- a/C++/Parser.cpp Sat Jan 04 18:02:06 2014 +0100 +++ b/C++/Parser.cpp Thu Jan 23 14:56:50 2014 +0100 @@ -16,22 +16,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#include #include #include #include "Parser.h" /* -------------------------------------------------------- - * Option public members - * -------------------------------------------------------- */ - -bool operator==(const Option &o1, const Option &o2) -{ - return o1.m_key == o2.m_key && - o1.m_value == o2.m_value; -} - -/* -------------------------------------------------------- * Section public members * -------------------------------------------------------- */ @@ -40,108 +32,50 @@ { } +Section::Section(const std::string &name) + : m_name(name) + , m_allowed(true) +{ + +} + const std::string &Section::getName() const { return m_name; } -const std::string Section::findOption(const std::string &name) const +bool Section::hasOption(const std::string &name) const { - std::string ret; - - for (const Option &o : m_options) - if (o.m_key == name) { - ret = o.m_value; - break; - } - - return ret; + return m_options.count(name) >= 1; } -template <> -bool Section::getValue(const std::string &name) const +Section::Map::iterator Section::begin() { - bool result = false; - - if (hasOption(name)) { - std::string value = findOption(name); - - if (value == "yes" || value == "true"|| value == "1") - result = true; - else if (value == "no" || value == "false" || value == "0") - result = false; - } - - return result; + return m_options.begin(); } -template <> -int Section::getValue(const std::string &name) const +Section::Map::const_iterator Section::cbegin() const { - int result = -1; - - if (hasOption(name)) - result = atoi(findOption(name).c_str()); - - return result; + return m_options.cbegin(); } -template <> -std::string Section::getValue(const std::string &name) const +Section::Map::iterator Section::end() { - std::string result; - - if (hasOption(name)) - result = findOption(name); - - return result; -} - -const std::vector