Mercurial > code
changeset 209:706f861c4c6d
Little cleanup and rename getValue -> getOption
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 24 Jan 2014 09:17:06 +0100 |
parents | 1ffe6d4937b7 |
children | 3b0e276f0866 |
files | C++/Parser.cpp C++/Parser.h |
diffstat | 2 files changed, 15 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/C++/Parser.cpp Thu Jan 23 14:56:50 2014 +0100 +++ b/C++/Parser.cpp Fri Jan 24 09:17:06 2014 +0100 @@ -32,9 +32,9 @@ { } -Section::Section(const std::string &name) +Section::Section(const std::string &name, bool allowed) : m_name(name) - , m_allowed(true) + , m_allowed(allowed) { } @@ -227,11 +227,7 @@ , m_tuning(tuning) , m_commentChar(commentToken) { - Section s(""); - - s.m_allowed = (tuning & DisableRootSection) ? false : true; - - m_sections.push_back(s); + m_sections.push_back(Section("", (tuning & DisableRootSection) ? false : true)); open(); }
--- a/C++/Parser.h Thu Jan 23 14:56:50 2014 +0100 +++ b/C++/Parser.h Fri Jan 24 09:17:06 2014 +0100 @@ -37,9 +37,14 @@ */ class Section { public: + friend class Parser; + using Map = std::unordered_map<std::string, std::string>; - friend class Parser; + template <typename T> + struct Converter { + static const bool supported = false; + }; private: std::string m_name; /*! name of section */ @@ -47,12 +52,8 @@ bool m_allowed; /*! is authorized to push */ const std::string findOption(const std::string &name) const; + public: - template <typename T> - struct Converter { - static const bool supported = false; - }; - /** * Default constructor. */ @@ -62,8 +63,9 @@ * Named constructor. * * @param name the section name + * @param allowed is allowed to push */ - Section(const std::string &name); + Section(const std::string &name, bool allowed = true); /** * Tells if that section has the specified option name. @@ -115,10 +117,10 @@ * @return the value if found */ template <typename T> - T getValue(const std::string &name) const + T getOption(const std::string &name) const { try { - return requireValue<T>(name); + return requireOption<T>(name); } catch (...) { // Catch any conversion error. } @@ -137,7 +139,7 @@ * @throw std::invalid_argument on conversion failures */ template <typename T> - T requireValue(const std::string &name) const + T requireOption(const std::string &name) const { static_assert(Converter<T>::supported, "invalid type requested");