Skip to content
Snippets Groups Projects
Commit b2e6929b authored by Jan Trávníček's avatar Jan Trávníček
Browse files

cleanup

parent 162c22a8
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
}
 
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment