# HG changeset patch # User David Demelier # Date 1444136282 -7200 # Node ID 0d004aba3ff6879bc24d7ef38aed01653e635387 # Parent f083259de5e69cab8e253040b323d3d8fe0d5f65 Ini: put in ini namespace and remove class prefixes diff -r f083259de5e6 -r 0d004aba3ff6 C++/modules/Ini/Ini.cpp --- a/C++/modules/Ini/Ini.cpp Tue Oct 06 14:48:36 2015 +0200 +++ b/C++/modules/Ini/Ini.cpp Tue Oct 06 14:58:02 2015 +0200 @@ -33,6 +33,8 @@ #include "Ini.h" +namespace ini { + namespace { /* -------------------------------------------------------- @@ -148,14 +150,14 @@ using TokenStack = std::vector; /* -------------------------------------------------------- - * IniBuilder + * Builder * -------------------------------------------------------- */ -class IniBuilder { +class Builder { private: std::string m_path; std::string m_base; - Ini &m_ini; + Document &m_ini; private: inline bool isReserved(char c) const noexcept @@ -263,16 +265,16 @@ } } - IniSection readSection(TokenStack::iterator &it, TokenStack::iterator end) + Section readSection(TokenStack::iterator &it, TokenStack::iterator end) { if (++it == end || it->type() != TokenType::Word) { - throw IniError(it->line(), it->position(), "word expected after [, got " + it->toString()); + throw Error(it->line(), it->position(), "word expected after [, got " + it->toString()); } - IniSection section(it->value()); + Section section(it->value()); if (++it == end || it->type() != TokenType::SectionEnd) { - throw IniError(it->line(), it->position(), "] expected, got " + it->toString()); + throw Error(it->line(), it->position(), "] expected, got " + it->toString()); } // Remove ] @@ -292,25 +294,25 @@ } else if (it->type() == TokenType::Word) { section.push_back(readOption(it, end)); } else { - throw IniError(it->line(), it->position(), "unexpected token " + it->toString()); + throw Error(it->line(), it->position(), "unexpected token " + it->toString()); } } return section; } - IniOption readOption(TokenStack::iterator &it, TokenStack::iterator end) + Option readOption(TokenStack::iterator &it, TokenStack::iterator end) { std::string key = it->value(); if (++it == end) { - throw IniError(it->line(), it->position(), "expected '=' after option declaration, got "); + throw Error(it->line(), it->position(), "expected '=' after option declaration, got "); } readSpace(it, end); if (it == end || it->type() != TokenType::Assign) { - throw IniError(it->line(), it->position(), "expected '=' after option declaration, got " + it++->toString()); + throw Error(it->line(), it->position(), "expected '=' after option declaration, got " + it++->toString()); } readSpace(++it, end); @@ -325,24 +327,24 @@ } if (it == end) - throw IniError(save->line(), save->position(), "undisclosed quote: " + save->toString() + " expected"); + throw Error(save->line(), save->position(), "undisclosed quote: " + save->toString() + " expected"); ++ it; } else if (it->type() == TokenType::Word) { oss << it++->value(); } else if (it->type() != TokenType::NewLine && it->type() != TokenType::Comment) { // No value requested, must be NewLine or comment - throw IniError(it->line(), it->position(), "expected option value after '=', got " + it->toString()); + throw Error(it->line(), it->position(), "expected option value after '=', got " + it->toString()); } - return IniOption(std::move(key), oss.str()); + return Option(std::move(key), oss.str()); } void readInclude(TokenStack::iterator &it, TokenStack::iterator end) { if (++it == end || (it->type() != TokenType::Word || it->value() != "include")) { - throw IniError(it->line(), it->position(), "expected `include' after '@' token, got " + it->toString()); + throw Error(it->line(), it->position(), "expected `include' after '@' token, got " + it->toString()); } readSpace(++it, end); @@ -351,12 +353,12 @@ TokenStack::iterator save = it; if (it == end || (it->type() != TokenType::QuoteSimple && it->type() != TokenType::QuoteDouble)) { - throw IniError(it->line(), it->position(), "expected filename after @include statement"); + throw Error(it->line(), it->position(), "expected filename after @include statement"); } // Filename if (++it == end || it->type() != TokenType::Word) { - throw IniError(it->line(), it->position(), "expected filename after @include statement"); + throw Error(it->line(), it->position(), "expected filename after @include statement"); } std::string value = it->value(); @@ -370,17 +372,17 @@ // Must be closed with the same quote if (++it == end || it->type() != save->type()) { - throw IniError(save->line(), save->position(), "undiclosed quote: " + save->toString() + " expected"); + throw Error(save->line(), save->position(), "undiclosed quote: " + save->toString() + " expected"); } // Remove quote ++ it; - IniBuilder(m_ini, fullpath); + Builder(m_ini, fullpath); } public: - IniBuilder(Ini &ini, std::string path) + Builder(Document &ini, std::string path) : m_path(path) , m_base(base(std::move(path))) , m_ini(ini) @@ -407,7 +409,7 @@ } else if (it->type() == TokenType::SectionBegin) { m_ini.push_back(readSection(it, end)); } else { - throw IniError(it->line(), it->position(), "unexpected " + it->toString() + " on root document"); + throw Error(it->line(), it->position(), "unexpected " + it->toString() + " on root document"); } } } @@ -416,10 +418,12 @@ } // !namespace /* -------------------------------------------------------- - * Ini + * Document * -------------------------------------------------------- */ -Ini::Ini(const std::string &path) +Document::Document(const std::string &path) { - IniBuilder(*this, path); + Builder(*this, path); } + +} // !ini \ No newline at end of file diff -r f083259de5e6 -r 0d004aba3ff6 C++/modules/Ini/Ini.h --- a/C++/modules/Ini/Ini.h Tue Oct 06 14:48:36 2015 +0200 +++ b/C++/modules/Ini/Ini.h Tue Oct 06 14:58:02 2015 +0200 @@ -29,11 +29,13 @@ #include #include +namespace ini { + /** - * @class IniError + * @class Error * @brief Error in a file */ -class IniError : public std::exception { +class Error : public std::exception { private: int m_line; int m_position; @@ -47,7 +49,7 @@ * @param position the position * @param error the error */ - inline IniError(int line, int position, std::string error) + inline Error(int line, int position, std::string error) : m_line(line) , m_position(position) , m_error(std::move(error)) @@ -86,10 +88,10 @@ }; /** - * @class IniOption + * @class Option * @brief Option definition */ -class IniOption { +class Option { private: std::string m_key; std::string m_value; @@ -101,7 +103,7 @@ * @param key the key * @param value the value */ - inline IniOption(std::string key, std::string value) + inline Option(std::string key, std::string value) : m_key(std::move(key)) , m_value(std::move(value)) { @@ -129,18 +131,18 @@ }; /** - * @class IniSection + * @class Section * @brief Section that contains one or more options */ -class IniSection { +class Section { private: std::string m_key; - std::deque m_options; + std::deque