diff --git a/alib2data/src/XmlApi.hpp b/alib2data/src/XmlApi.hpp index dd5f0155d868957d36b6d42da9186bd2ede895f3..b595073bec4d8c0ec4264da3df04386239f1887e 100644 --- a/alib2data/src/XmlApi.hpp +++ b/alib2data/src/XmlApi.hpp @@ -20,75 +20,78 @@ namespace alib { -template<typename T, typename Enable = void> -struct xmlApi {}; +template < typename T, typename Enable = void > +struct xmlApi { }; -template<typename Group> -struct xmlApi<Group, typename std::enable_if< std::is_base_of<WrapperBase, Group>::value >::type> { +template < typename Group > +struct xmlApi < Group, typename std::enable_if < std::is_base_of < WrapperBase, Group >::value >::type > { class ParserRegisterBase { public: - virtual Group parse(std::deque<sax::Token>::iterator& input) = 0; - + virtual Group parse ( std::deque < sax::Token >::iterator & input ) = 0; }; private: - // INFO: Function exist to handle static order of initialisation - static std::map<std::string, typename xmlApi<Group>::ParserRegisterBase*>& parseFunctions() { - static std::map<std::string, typename xmlApi<Group>::ParserRegisterBase*> res; + // INFO: Function exist to handle static order of initialisation + static std::map < std::string, typename xmlApi < Group >::ParserRegisterBase * > & parseFunctions ( ) { + static std::map < std::string, typename xmlApi < Group >::ParserRegisterBase * > res; + return res; } public: - template<class Type> + template < class Type > class ParserRegister : public ParserRegisterBase { - std::function<Type(std::deque<sax::Token>::iterator&)> parseFunction; + std::function < Type ( std::deque < sax::Token >::iterator & ) > parseFunction; public: - ParserRegister(std::string tagName, std::function<Type(std::deque<sax::Token>::iterator&)> parseFunction) : parseFunction(parseFunction) { - parseFunctions().insert(std::make_pair(std::move(tagName), this)); + ParserRegister ( std::string tagName, std::function < Type ( std::deque < sax::Token >::iterator & ) > parseFunction ) : parseFunction ( parseFunction ) { + parseFunctions ( ).insert ( std::make_pair ( std::move ( tagName ), this ) ); } - virtual Group parse(std::deque<sax::Token>::iterator& input) { - return Group(parseFunction(input)); + virtual Group parse ( std::deque < sax::Token >::iterator & input ) { + return Group ( parseFunction ( input ) ); } }; - static Group parse(std::deque<sax::Token>::iterator& input) { - const std::string& tagName = sax::FromXMLParserHelper::getTokenData(input, sax::Token::TokenType::START_ELEMENT); - typename std::map<std::string, ParserRegisterBase*>::iterator callback = parseFunctions().find(tagName); - if(callback == parseFunctions().end()) throw std::bad_function_call(); - return callback->second->parse(input); + static Group parse ( std::deque < sax::Token >::iterator & input ) { + const std::string & tagName = sax::FromXMLParserHelper::getTokenData ( input, sax::Token::TokenType::START_ELEMENT ); + + typename std::map < std::string, ParserRegisterBase * >::iterator callback = parseFunctions ( ).find ( tagName ); + + if ( callback == parseFunctions ( ).end ( ) ) throw std::bad_function_call ( ); + + return callback->second->parse ( input ); } - static bool first(const std::deque<sax::Token>::const_iterator& input) { - const std::string& tagName = sax::FromXMLParserHelper::getTokenData(input, sax::Token::TokenType::START_ELEMENT); - typename std::map<std::string, ParserRegisterBase*>::iterator callback = parseFunctions().find(tagName); - if(callback == parseFunctions().end()) return false; + static bool first ( const std::deque < sax::Token >::const_iterator & input ) { + const std::string & tagName = sax::FromXMLParserHelper::getTokenData ( input, sax::Token::TokenType::START_ELEMENT ); + + typename std::map < std::string, ParserRegisterBase * >::iterator callback = parseFunctions ( ).find ( tagName ); + + if ( callback == parseFunctions ( ).end ( ) ) return false; + return true; } - static void compose(std::deque<sax::Token>& output, const Group& data) { - data.getData().compose(output); + static void compose ( std::deque < sax::Token > & output, const Group & data ) { + data.getData ( ).compose ( output ); } }; -/*template<typename Group> -std::map<std::string, typename xmlApi<Group>::ParserRegisterBase*> xmlApi<Group, typename std::enable_if< std::is_base_of<WrapperBase, Group>::value >::type>::parseFunctions;*/ - -template<typename Type> -struct xmlApi<Type, typename std::enable_if< std::is_base_of<ObjectBase, Type>::value >::type> { - static Type parse(std::deque<sax::Token>::iterator& input) { - return Type::parse(input); +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < ObjectBase, Type >::value >::type > { + static Type parse ( std::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); } - static bool first(const std::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, Type::XML_TAG_NAME); + static bool first ( const std::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, Type::XML_TAG_NAME ); } - static void compose(std::deque<sax::Token>& output, const Type& data) { - data.compose(output); + static void compose ( std::deque < sax::Token > & output, const Type & data ) { + data.compose ( output ); } };