diff --git a/alib2common/src/container/ObjectsDeque.h b/alib2common/src/container/ObjectsDeque.h index 118d51d7506bc4c11358c2cad1318f8b202f2344..7a2ae3acc1e77d31578cab9764ddeb306ead7707 100644 --- a/alib2common/src/container/ObjectsDeque.h +++ b/alib2common/src/container/ObjectsDeque.h @@ -49,18 +49,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Deque"; - - return xmlTagName; - } - - static ObjectsDeque < ElementType > parse ( ext::deque < sax::Token >::iterator & input ); - static ext::deque < ElementType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const ext::deque < ElementType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsDeque < ElementType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsDeque < > normalized_type; @@ -104,73 +92,83 @@ ObjectsDeque < ElementType >::operator std::string ( ) const { } template < class ElementType > -ObjectsDeque < ElementType > ObjectsDeque < ElementType >::parse ( ext::deque < sax::Token >::iterator & input ) { - return ObjectsDeque < ElementType > ( parseRaw ( input ) ); +alib::ObjectBase* ObjectsDeque < ElementType >::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } -template < class ElementType > -ext::deque < ElementType > ObjectsDeque < ElementType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsDeque < >::getXmlTagName() ); +} /* namespace container */ - ext::deque < ElementType > deque; +namespace alib { - while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) - deque.push_back ( alib::xmlApi < ElementType >::parse ( input ) ); +template < typename T > +struct xmlApi < ext::deque < T > > { + static ext::deque < T > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const ext::deque < T > & data ); +}; - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsDeque < >::getXmlTagName() ); - return deque; -} +template < typename T > +ext::deque < T > xmlApi < ext::deque < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); -template < class ElementType > -void ObjectsDeque < ElementType >::compose ( ext::deque < sax::Token > & out, const ext::deque < ElementType > & input ) { - out.emplace_back ( ObjectsDeque < >::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); + ext::deque < T > set; - for ( const ElementType & item : input ) - alib::xmlApi < ElementType >::compose ( out, item ); + while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) + set.push_back ( alib::xmlApi < T >::parse ( input ) ); - out.emplace_back ( ObjectsDeque < >::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return set; } -template < class ElementType > -void ObjectsDeque < ElementType >::compose ( ext::deque < sax::Token > & out, const ObjectsDeque < ElementType > & input ) { - compose ( out, static_cast < const ext::deque < ElementType > & > ( input ) ); +template < typename T > +bool xmlApi < ext::deque < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -template < class ElementType > -alib::ObjectBase* ObjectsDeque < ElementType >::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +template < typename T > +const std::string & xmlApi < ext::deque < T > >::xmlTagName ( ) { + static std::string xmlTagName = "Deque"; + + return xmlTagName; } -} /* namespace container */ +template < typename T > +void xmlApi < ext::deque < T > >::compose ( ext::deque < sax::Token > & output, const ext::deque < T > & input ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); -namespace alib { + for ( const T & item : input ) + alib::xmlApi < T >::compose ( output, item ); + + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} template < typename T > -struct xmlApi < ext::deque < T > > { - static ext::deque < T > parse ( ext::deque < sax::Token >::iterator & input ); +struct xmlApi < container::ObjectsDeque < T > > { + static container::ObjectsDeque < T > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const ext::deque < T > & data ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsDeque < T > & data ); }; template < typename T > -ext::deque < T > xmlApi < ext::deque < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsDeque < T >::parseRaw ( input ); +container::ObjectsDeque < T > xmlApi < container::ObjectsDeque < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsDeque < T > ( xmlApi < ext::deque < T > >::parse ( input ) ); } template < typename T > -bool xmlApi < ext::deque < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); +bool xmlApi < container::ObjectsDeque < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return xmlApi < ext::deque < T > >::first ( input ); } template < typename T > -std::string xmlApi < ext::deque < T > >::xmlTagName ( ) { - return container::ObjectsDeque < >::getXmlTagName(); +const std::string & xmlApi < container::ObjectsDeque < T > >::xmlTagName ( ) { + return xmlApi < ext::deque < T > >::xmlTagName ( ); } template < typename T > -void xmlApi < ext::deque < T > >::compose ( ext::deque < sax::Token > & output, const ext::deque < T > & input ) { - return container::ObjectsDeque < T >::compose ( output, input ); +void xmlApi < container::ObjectsDeque < T > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsDeque < T > & input ) { + return xmlApi < ext::deque < T > >::compose ( output, input ); } template < > diff --git a/alib2common/src/container/ObjectsList.h b/alib2common/src/container/ObjectsList.h index 305809801106ec6aad7178b7aa22002654427635..a80fc01d9db5e0f24cd09351da1e39c3886ab79f 100644 --- a/alib2common/src/container/ObjectsList.h +++ b/alib2common/src/container/ObjectsList.h @@ -49,18 +49,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "List"; - - return xmlTagName; - } - - static ObjectsList parse ( ext::deque < sax::Token >::iterator & input ); - static ext::list < ElementType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const ext::list < ElementType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsList < ElementType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsList < > normalized_type; @@ -104,73 +92,83 @@ ObjectsList < ElementType >::operator std::string ( ) const { } template < class ElementType > -ObjectsList < ElementType > ObjectsList < ElementType >::parse ( ext::deque < sax::Token >::iterator & input ) { - return ObjectsList < ElementType > ( parseRaw ( input ) ); +alib::ObjectBase* ObjectsList < ElementType >::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } -template < class ElementType > -ext::list < ElementType > ObjectsList < ElementType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsList < >::getXmlTagName() ); +} /* namespace container */ - ext::list < ElementType > list; +namespace alib { - while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) - list.push_back ( alib::xmlApi < ElementType >::parse ( input ) ); +template < typename T > +struct xmlApi < ext::list < T > > { + static ext::list < T > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const ext::list < T > & data ); +}; - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsList < >::getXmlTagName() ); - return list; -} +template < typename T > +ext::list < T > xmlApi < ext::list < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); -template < class ElementType > -void ObjectsList < ElementType >::compose ( ext::deque < sax::Token > & out, const ext::list < ElementType > & input ) { - out.emplace_back ( ObjectsList < >::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); + ext::list < T > set; - for ( const ElementType & item : input ) - alib::xmlApi < ElementType >::compose ( out, item ); + while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) + set.push_back ( alib::xmlApi < T >::parse ( input ) ); - out.emplace_back ( ObjectsList < >::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return set; } -template < class ElementType > -void ObjectsList < ElementType >::compose ( ext::deque < sax::Token > & out, const ObjectsList < ElementType > & input ) { - compose ( out, static_cast < const ext::list < ElementType > & > ( input ) ); +template < typename T > +bool xmlApi < ext::list < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -template < class ElementType > -alib::ObjectBase* ObjectsList < ElementType >::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +template < typename T > +const std::string & xmlApi < ext::list < T > >::xmlTagName ( ) { + static std::string xmlTagName = "List"; + + return xmlTagName; } -} /* namespace container */ +template < typename T > +void xmlApi < ext::list < T > >::compose ( ext::deque < sax::Token > & output, const ext::list < T > & input ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); -namespace alib { + for ( const T & item : input ) + alib::xmlApi < T >::compose ( output, item ); + + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} template < typename T > -struct xmlApi < ext::list < T > > { - static ext::list < T > parse ( ext::deque < sax::Token >::iterator & input ); +struct xmlApi < container::ObjectsList < T > > { + static container::ObjectsList < T > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const ext::list < T > & data ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsList < T > & data ); }; template < typename T > -ext::list < T > xmlApi < ext::list < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsList < T >::parseRaw ( input ); +container::ObjectsList < T > xmlApi < container::ObjectsList < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsList < T > ( xmlApi < ext::list < T > >::parse ( input ) ); } template < typename T > -bool xmlApi < ext::list < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); +bool xmlApi < container::ObjectsList < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return xmlApi < ext::list < T > >::first ( input ); } template < typename T > -std::string xmlApi < ext::list < T > >::xmlTagName ( ) { - return container::ObjectsList < >::getXmlTagName(); +const std::string & xmlApi < container::ObjectsList < T > >::xmlTagName ( ) { + return xmlApi < ext::list < T > >::xmlTagName ( ); } template < typename T > -void xmlApi < ext::list < T > >::compose ( ext::deque < sax::Token > & output, const ext::list < T > & input ) { - return container::ObjectsList < T >::compose ( output, input ); +void xmlApi < container::ObjectsList < T > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsList < T > & input ) { + return xmlApi < ext::list < T > >::compose ( output, input ); } template < > diff --git a/alib2common/src/container/ObjectsMap.h b/alib2common/src/container/ObjectsMap.h index 87c9a06d9331914acd1e7b9af5cb716148b90575..eade458d38f2a880e8630593138cee6e1784b505 100644 --- a/alib2common/src/container/ObjectsMap.h +++ b/alib2common/src/container/ObjectsMap.h @@ -51,18 +51,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Map"; - - return xmlTagName; - } - - static ObjectsMap parse ( ext::deque < sax::Token >::iterator & input ); - static ext::map < KeyType, ValueType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const ext::map < KeyType, ValueType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsMap < KeyType, ValueType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsMap < > normalized_type; @@ -107,73 +95,83 @@ ObjectsMap<KeyType, ValueType>::operator std::string() const { } template < class KeyType, class ValueType > -ObjectsMap<KeyType, ValueType> ObjectsMap<KeyType, ValueType>::parse(ext::deque<sax::Token>::iterator& input) { - return ObjectsMap<KeyType, ValueType>(parseRaw(input)); +alib::ObjectBase* ObjectsMap < KeyType, ValueType >::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } -template < class KeyType, class ValueType > -ext::map < KeyType, ValueType > ObjectsMap < KeyType, ValueType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsMap < >::getXmlTagName() ); +} /* namespace container */ - ext::map < KeyType, ValueType > map; +namespace alib { - while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) - map.insert ( alib::xmlApi < ext::pair < KeyType, ValueType > >::parse ( input ) ); +template < typename T, typename R > +struct xmlApi < ext::map < T, R > > { + static ext::map < T, R > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const ext::map < T, R > & data ); +}; - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsMap < >::getXmlTagName() ); - return map; -} +template < typename T, typename R > +ext::map < T, R > xmlApi < ext::map < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); -template < class KeyType, class ValueType > -void ObjectsMap < KeyType, ValueType >::compose ( ext::deque < sax::Token > & out, const ext::map < KeyType, ValueType > & input ) { - out.emplace_back ( ObjectsMap < >::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); + ext::map < T, R > map; - for ( const std::pair < const KeyType, ValueType > & item : input ) - alib::xmlApi < ext::pair < const KeyType, ValueType > >::compose ( out, item ); + while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) + map.insert ( alib::xmlApi < ext::pair < T, R > >::parse ( input ) ); - out.emplace_back ( ObjectsMap < >::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return map; } -template < class KeyType, class ValueType > -void ObjectsMap < KeyType, ValueType >::compose ( ext::deque < sax::Token > & out, const ObjectsMap < KeyType, ValueType > & input ) { - compose ( out, static_cast < const ext::map < KeyType, ValueType > & > ( input ) ); +template < typename T, typename R > +bool xmlApi < ext::map < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -template < class KeyType, class ValueType > -alib::ObjectBase* ObjectsMap < KeyType, ValueType >::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +template < typename T, typename R > +const std::string & xmlApi < ext::map < T, R > >::xmlTagName ( ) { + static std::string xmlTagName = "Map"; + + return xmlTagName; } -} /* namespace container */ +template < typename T, typename R > +void xmlApi < ext::map < T, R > >::compose ( ext::deque < sax::Token > & output, const ext::map < T, R > & input ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); -namespace alib { + for ( const std::pair < const T, R > & item : input ) + alib::xmlApi < ext::pair < const T, R > >::compose ( output, item ); + + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} template < typename T, typename R > -struct xmlApi < ext::map < T, R > > { - static ext::map < T, R > parse ( ext::deque < sax::Token >::iterator & input ); +struct xmlApi < container::ObjectsMap < T, R > > { + static container::ObjectsMap < T, R > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const ext::map < T, R > & data ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsMap < T, R > & data ); }; template < typename T, typename R > -ext::map < T, R > xmlApi < ext::map < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsMap < T, R >::parseRaw ( input ); +container::ObjectsMap < T, R > xmlApi < container::ObjectsMap < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsMap < T, R > ( xmlApi < ext::map < T, R > >::parse ( input ) ); } template < typename T, typename R > -bool xmlApi < ext::map < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); +bool xmlApi < container::ObjectsMap < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } template < typename T, typename R > -std::string xmlApi < ext::map < T, R > >::xmlTagName ( ) { - return container::ObjectsMap < >::getXmlTagName(); +const std::string & xmlApi < container::ObjectsMap < T, R > >::xmlTagName ( ) { + return xmlApi < ext::map < T, R > >::xmlTagName ( ); } template < typename T, typename R > -void xmlApi < ext::map < T, R > >::compose ( ext::deque < sax::Token > & output, const ext::map < T, R > & input ) { - return container::ObjectsMap < T, R >::compose ( output, input ); +void xmlApi < container::ObjectsMap < T, R > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsMap < T, R > & input ) { + xmlApi < ext::map < T, R > >::compose ( output, input ); } template < > diff --git a/alib2common/src/container/ObjectsPair.h b/alib2common/src/container/ObjectsPair.h index 90e28735750fcfa069038915bbc0f6247adba881..ff7ac257bfdd0fa04eda223864c5a5cef19ef4c8 100644 --- a/alib2common/src/container/ObjectsPair.h +++ b/alib2common/src/container/ObjectsPair.h @@ -49,19 +49,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Pair"; - - return xmlTagName; - } - - static ObjectsPair parse ( ext::deque < sax::Token >::iterator & input ); - static ext::pair < FirstType, SecondType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const std::pair < FirstType, SecondType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ext::pair < FirstType, SecondType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsPair < FirstType, SecondType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsPair < > normalized_type; @@ -105,43 +92,6 @@ ObjectsPair < FirstType, SecondType >::operator std::string() const { return std::move(ss).str(); } -template < class FirstType, class SecondType > -ObjectsPair < FirstType, SecondType > ObjectsPair < FirstType, SecondType >::parse(ext::deque<sax::Token>::iterator& input) { - return ObjectsPair < FirstType, SecondType > ( parseRaw ( input ) ); -} - -template < class FirstType, class SecondType > -ext::pair < FirstType, SecondType > ObjectsPair < FirstType, SecondType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsPair::getXmlTagName() ); - - FirstType first = alib::xmlApi < FirstType >::parse ( input ); - SecondType second = alib::xmlApi < SecondType >::parse ( input ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsPair::getXmlTagName() ); - - return ext::make_pair ( std::move ( first ), std::move ( second ) ); -} - -template < class FirstType, class SecondType > -void ObjectsPair < FirstType, SecondType >::compose ( ext::deque < sax::Token > & out, const std::pair < FirstType, SecondType > & input ) { - out.emplace_back ( ObjectsPair::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - - alib::xmlApi < typename std::decay < FirstType >::type >::compose ( out, input.first ); - alib::xmlApi < SecondType >::compose ( out, input.second ); - - out.emplace_back ( ObjectsPair::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - -template < class FirstType, class SecondType > -void ObjectsPair < FirstType, SecondType >::compose ( ext::deque < sax::Token > & out, const ext::pair < FirstType, SecondType > & input ) { - compose ( out, static_cast < const std::pair < FirstType, SecondType > & > ( input ) ); -} - -template < class FirstType, class SecondType > -void ObjectsPair < FirstType, SecondType >::compose ( ext::deque < sax::Token > & out, const ObjectsPair < FirstType, SecondType > & input ) { - compose ( out, static_cast < const ext::pair < FirstType, SecondType > & > ( input ) ); -} - template < class FirstType, class SecondType > alib::ObjectBase* ObjectsPair < FirstType, SecondType >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); @@ -155,34 +105,76 @@ template < typename T, typename R > struct xmlApi < ext::pair < T, R > > { static ext::pair < T, R > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, const ext::pair < T, R > & data ); static void compose ( ext::deque < sax::Token > & output, const std::pair < T, R > & data ); }; template < typename T, typename R > ext::pair < T, R > xmlApi < ext::pair < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsPair < T, R >::parseRaw ( input ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + + T first = alib::xmlApi < T >::parse ( input ); + R second = alib::xmlApi < R >::parse ( input ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + + return ext::make_pair ( std::move ( first ), std::move ( second ) ); } template < typename T, typename R > bool xmlApi < ext::pair < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } template < typename T, typename R > -std::string xmlApi < ext::pair < T, R > >::xmlTagName ( ) { - return container::ObjectsPair < >::getXmlTagName(); +const std::string & xmlApi < ext::pair < T, R > >::xmlTagName ( ) { + static std::string xmlTagName = "Pair"; + + return xmlTagName; } template < typename T, typename R > void xmlApi < ext::pair < T, R > >::compose ( ext::deque < sax::Token > & output, const ext::pair < T, R > & input ) { - return container::ObjectsPair < T, R >::compose ( output, input ); + compose ( output, static_cast < const std::pair < T, R > > ( input ) ); } template < typename T, typename R > void xmlApi < ext::pair < T, R > >::compose ( ext::deque < sax::Token > & output, const std::pair < T, R > & input ) { - return container::ObjectsPair < T, R >::compose ( output, input ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + + alib::xmlApi < typename std::decay < T >::type >::compose ( output, input.first ); + alib::xmlApi < R >::compose ( output, input.second ); + + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + +template < typename T, typename R > +struct xmlApi < container::ObjectsPair < T, R > > { + static container::ObjectsPair < T, R > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsPair < T, R > & data ); +}; + +template < typename T, typename R > +container::ObjectsPair < T, R > xmlApi < container::ObjectsPair < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsPair < T, R > ( xmlApi < ext::pair < T, R > >::parse ( input ) ); +} + +template < typename T, typename R > +bool xmlApi < container::ObjectsPair < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return xmlApi < ext::pair < T, R > >::first ( input ); +} + +template < typename T, typename R > +const std::string & xmlApi < container::ObjectsPair < T, R > >::xmlTagName ( ) { + return xmlApi < ext::pair < T, R > >::xmlTagName ( ); +} + +template < typename T, typename R > +void xmlApi < container::ObjectsPair < T, R > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsPair < T, R > & input ) { + xmlApi < ext::pair < T, R > >::compose ( output, input ); } template < > diff --git a/alib2common/src/container/ObjectsSet.h b/alib2common/src/container/ObjectsSet.h index a62054a91c35c845094ac95f22d6490e58dd5cda..5eefd37f57463394c1aa3ebae149b997c87475ae 100644 --- a/alib2common/src/container/ObjectsSet.h +++ b/alib2common/src/container/ObjectsSet.h @@ -49,18 +49,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Set"; - - return xmlTagName; - } - - static ObjectsSet parse ( ext::deque < sax::Token >::iterator & input ); - static ext::set < ElementType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const ext::set < ElementType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsSet < ElementType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsSet < > normalized_type; @@ -105,73 +93,83 @@ ObjectsSet < ElementType >::operator std::string() const { } template < class ElementType > -ObjectsSet < ElementType > ObjectsSet < ElementType >::parse(ext::deque<sax::Token>::iterator& input) { - return ObjectsSet < ElementType >(parseRaw(input)); +alib::ObjectBase* ObjectsSet < ElementType >::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } -template < class ElementType > -ext::set < ElementType > ObjectsSet < ElementType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsSet < >::getXmlTagName() ); +} /* namespace container */ - ext::set < ElementType > set; +namespace alib { - while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) - set.insert ( alib::xmlApi < ElementType >::parse ( input ) ); +template < typename T > +struct xmlApi < ext::set < T > > { + static ext::set < T > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const ext::set < T > & data ); +}; - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsSet < >::getXmlTagName() ); - return set; -} +template < typename T > +ext::set < T > xmlApi < ext::set < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); -template < class ElementType > -void ObjectsSet < ElementType >::compose ( ext::deque < sax::Token > & out, const ext::set < ElementType > & input ) { - out.emplace_back ( ObjectsSet < >::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); + ext::set < T > set; - for ( const ElementType & item : input ) - alib::xmlApi < ElementType >::compose ( out, item ); + while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) + set.insert ( alib::xmlApi < T >::parse ( input ) ); - out.emplace_back ( ObjectsSet < >::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return set; } -template < class ElementType > -void ObjectsSet < ElementType >::compose ( ext::deque < sax::Token > & out, const ObjectsSet < ElementType > & input ) { - compose ( out, static_cast < const ext::set < ElementType > & > ( input ) ); +template < typename T > +bool xmlApi < ext::set < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -template < class ElementType > -alib::ObjectBase* ObjectsSet < ElementType >::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +template < typename T > +const std::string & xmlApi < ext::set < T > >::xmlTagName ( ) { + static std::string xmlTagName = "Set"; + + return xmlTagName; } -} /* namespace container */ +template < typename T > +void xmlApi < ext::set < T > >::compose ( ext::deque < sax::Token > & output, const ext::set < T > & input ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); -namespace alib { + for ( const T & item : input ) + alib::xmlApi < T >::compose ( output, item ); + + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} template < typename T > -struct xmlApi < ext::set < T > > { - static ext::set < T > parse ( ext::deque < sax::Token >::iterator & input ); +struct xmlApi < container::ObjectsSet < T > > { + static container::ObjectsSet < T > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const ext::set < T > & data ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsSet < T > & data ); }; template < typename T > -ext::set < T > xmlApi < ext::set < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsSet < T >::parseRaw ( input ); +container::ObjectsSet < T > xmlApi < container::ObjectsSet < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsSet < T > ( xmlApi < ext::set < T > >::parse ( input ) ); } template < typename T > -bool xmlApi < ext::set < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); +bool xmlApi < container::ObjectsSet < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return xmlApi < ext::set < T > >::first ( input ); } template < typename T > -std::string xmlApi < ext::set < T > >::xmlTagName ( ) { - return container::ObjectsSet < >::getXmlTagName(); +const std::string & xmlApi < container::ObjectsSet < T > >::xmlTagName ( ) { + return xmlApi < ext::set < T > >::xmlTagName ( ); } template < typename T > -void xmlApi < ext::set < T > >::compose ( ext::deque < sax::Token > & output, const ext::set < T > & input ) { - return container::ObjectsSet < T >::compose ( output, input ); +void xmlApi < container::ObjectsSet < T > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsSet < T > & input ) { + return xmlApi < ext::set < T > >::compose ( output, input ); } template < > diff --git a/alib2common/src/container/ObjectsTree.h b/alib2common/src/container/ObjectsTree.h index ab4a29102085e1820a17500b7f06ae793e2b5104..1fc52342c2626dfa973dcbc7c6699b3822a410b0 100644 --- a/alib2common/src/container/ObjectsTree.h +++ b/alib2common/src/container/ObjectsTree.h @@ -48,18 +48,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName ( ) { - static std::string xmlTagName = "Tree"; - - return xmlTagName; - } - - static ObjectsTree parse ( ext::deque < sax::Token >::iterator & input ); - static ext::tree < ElementType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const ext::tree < ElementType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsTree < ElementType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsTree < > normalized_type; @@ -99,18 +87,30 @@ ObjectsTree < ElementType >::operator std::string ( ) const { } template < class ElementType > -ObjectsTree <ElementType > ObjectsTree < ElementType >::parse ( ext::deque < sax::Token >::iterator & input ) { - return ObjectsTree < ElementType > ( parseRaw ( input ) ); +alib::ObjectBase* ObjectsTree < ElementType >::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } -template < class ElementType > -ext::tree < ElementType > ObjectsTree < ElementType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsTree < >::getXmlTagName ( ) ); +} /* namespace container */ + +namespace alib { + +template < typename T > +struct xmlApi < ext::tree < T > > { + static ext::tree < T > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const ext::tree < T > & data ); +}; + +template < typename T > +ext::tree < T > xmlApi < ext::tree < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, "Root" ); - ext::tree < ElementType > tree ( alib::xmlApi < ElementType >::parse ( input ) ); + ext::tree < T > tree ( alib::xmlApi < T >::parse ( input ) ); - typename ext::tree < ElementType >::const_children_iterator under = tree.root ( ); + typename ext::tree < T >::const_children_iterator under = tree.root ( ); unsigned level = 0; @@ -124,7 +124,7 @@ ext::tree < ElementType > ObjectsTree < ElementType >::parseRaw ( ext::deque < s ++level; } - tree.push_back ( under, alib::xmlApi < ElementType >::parse ( input ) ); + tree.push_back ( under, alib::xmlApi < T >::parse ( input ) ); while ( sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::END_ELEMENT, "Children" ) ) { sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, "Children" ); @@ -135,76 +135,74 @@ ext::tree < ElementType > ObjectsTree < ElementType >::parseRaw ( ext::deque < s } sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, "Root" ); - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsTree < >::getXmlTagName ( ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return tree; } -template < class ElementType > -void ObjectsTree < ElementType >::compose ( ext::deque < sax::Token > & out, const ext::tree < ElementType > & input ) { - out.emplace_back ( ObjectsTree < >::getXmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); - out.emplace_back ( "Root", sax::Token::TokenType::START_ELEMENT ); +template < typename T > +bool xmlApi < ext::tree < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < typename T > +const std::string & xmlApi < ext::tree < T > >::xmlTagName ( ) { + static std::string xmlTagName = "Tree"; + + return xmlTagName; +} + +template < typename T > +void xmlApi < ext::tree < T > >::compose ( ext::deque < sax::Token > & output, const ext::tree < T > & input ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( "Root", sax::Token::TokenType::START_ELEMENT ); unsigned level = 0; - for ( typename ext::tree < ElementType >::const_prefix_iterator iter = input.prefix_begin ( ); iter != input.prefix_end ( ); ) { + for ( typename ext::tree < T >::const_prefix_iterator iter = input.prefix_begin ( ); iter != input.prefix_end ( ); ) { while ( iter.getLevel ( ) > level ) { - out.emplace_back ( "Children", sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( "Children", sax::Token::TokenType::START_ELEMENT ); ++level; } - alib::xmlApi < ElementType >::compose ( out, * iter ); + alib::xmlApi < T >::compose ( output, * iter ); ++iter; while ( iter.getLevel ( ) < level ) { - out.emplace_back ( "Children", sax::Token::TokenType::END_ELEMENT ); + output.emplace_back ( "Children", sax::Token::TokenType::END_ELEMENT ); --level; } } - out.emplace_back ( "Root", sax::Token::TokenType::END_ELEMENT ); - out.emplace_back ( ObjectsTree < >::getXmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); -} - -template < class ElementType > -void ObjectsTree < ElementType >::compose ( ext::deque < sax::Token > & out, const ObjectsTree < ElementType > & input ) { - compose ( out, static_cast < const ext::tree < ElementType > & > ( input ) ); -} - -template < class ElementType > -alib::ObjectBase* ObjectsTree < ElementType >::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); + output.emplace_back ( "Root", sax::Token::TokenType::END_ELEMENT ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); } -} /* namespace container */ - -namespace alib { - template < typename T > -struct xmlApi < ext::tree < T > > { - static ext::tree < T > parse ( ext::deque < sax::Token >::iterator & input ); +struct xmlApi < container::ObjectsTree < T > > { + static container::ObjectsTree < T > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const ext::tree < T > & data ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsTree < T > & data ); }; template < typename T > -ext::tree < T > xmlApi < ext::tree < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsTree < T >::parseRaw ( input ); +container::ObjectsTree < T > xmlApi < container::ObjectsTree < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsTree < T > ( xmlApi < ext::tree < T > >::parse ( input ) ); } template < typename T > -bool xmlApi < ext::tree < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +bool xmlApi < container::ObjectsTree < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return xmlApi < ext::tree < T > >::first ( input ); } template < typename T > -std::string xmlApi < ext::tree < T > >::xmlTagName ( ) { - return container::ObjectsTree < >::getXmlTagName ( ); +const std::string & xmlApi < container::ObjectsTree < T > >::xmlTagName ( ) { + return xmlApi < ext::tree < T > >::xmlTagName ( ); } template < typename T > -void xmlApi < ext::tree < T > >::compose ( ext::deque < sax::Token > & output, const ext::tree < T > & input ) { - return container::ObjectsTree < T >::compose ( output, input ); +void xmlApi < container::ObjectsTree < T > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsTree < T > & input ) { + return xmlApi < ext::tree < T > >::compose ( output, input ); } template < > diff --git a/alib2common/src/container/ObjectsTrie.h b/alib2common/src/container/ObjectsTrie.h index 5f8e4890689f39f58bd5449027734c2a440d18ce..545476729348ad9a12d1c181a3d5910c553adfe2 100644 --- a/alib2common/src/container/ObjectsTrie.h +++ b/alib2common/src/container/ObjectsTrie.h @@ -48,20 +48,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName ( ) { - static std::string xmlTagName = "Trie"; - - return xmlTagName; - } - - static ObjectsTrie parse ( ext::deque < sax::Token >::iterator & input ); - static ext::map < KeyType, ext::trie < KeyType, ValueType > > parseChildren ( ext::deque < sax::Token >::iterator & input ); - static ext::trie < KeyType, ValueType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void composeChildren ( ext::deque < sax::Token > & out, const ext::map < KeyType, ext::trie < KeyType, ValueType > > & children ); - static void compose ( ext::deque < sax::Token > & out, const ext::trie < KeyType, ValueType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsTrie < KeyType, ValueType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsTrie < > normalized_type; @@ -101,22 +87,38 @@ ObjectsTrie < KeyType, ValueType >::operator std::string ( ) const { } template < class KeyType, class ValueType > -ObjectsTrie <KeyType, ValueType > ObjectsTrie < KeyType, ValueType >::parse ( ext::deque < sax::Token >::iterator & input ) { - return ObjectsTrie < KeyType, ValueType > ( parseRaw ( input ) ); +alib::ObjectBase* ObjectsTrie < KeyType, ValueType >::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } -template < class KeyType, class ValueType > -ext::map < KeyType, ext::trie < KeyType, ValueType > > ObjectsTrie < KeyType, ValueType >::parseChildren ( ext::deque < sax::Token >::iterator & input ) { - ext::map < KeyType, ext::trie < KeyType, ValueType > > children; +} /* namespace container */ + +namespace alib { + +template < typename T, typename R > +struct xmlApi < ext::trie < T, R > > { + static ext::trie < T, R > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const ext::trie < T, R > & data ); + +private: + static ext::map < T, ext::trie < T, R > > parseChildren ( ext::deque < sax::Token >::iterator & input ); + static void composeChildren ( ext::deque < sax::Token > & out, const ext::map < T, ext::trie < T, R > > & children ); +}; + +template < typename T, typename R > +ext::map < T, ext::trie < T, R > > xmlApi < ext::trie < T, R > >::parseChildren ( ext::deque < sax::Token >::iterator & input ) { + ext::map < T, ext::trie < T, R > > children; while ( sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, "Child" ) ) { sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, "Child" ); - KeyType key = alib::xmlApi < KeyType >::parse ( input ); - ValueType value = alib::xmlApi < ValueType >::parse ( input ); - ext::map < KeyType, ext::trie < KeyType, ValueType > > innerChildren = parseChildren ( input ); + T key = alib::xmlApi < T >::parse ( input ); + R value = alib::xmlApi < R >::parse ( input ); + ext::map < T, ext::trie < T, R > > innerChildren = parseChildren ( input ); - children.insert ( std::make_pair ( std::move ( key ), ext::trie < KeyType, ValueType > ( std::move ( value ), std::move ( innerChildren ) ) ) ); + children.insert ( std::make_pair ( std::move ( key ), ext::trie < T, R > ( std::move ( value ), std::move ( innerChildren ) ) ) ); sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, "Child" ); } @@ -124,79 +126,77 @@ ext::map < KeyType, ext::trie < KeyType, ValueType > > ObjectsTrie < KeyType, Va return children; } -template < class KeyType, class ValueType > -ext::trie < KeyType, ValueType > ObjectsTrie < KeyType, ValueType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsTrie < >::getXmlTagName ( ) ); - ValueType value = alib::xmlApi < ValueType >::parse ( input ); - ext::map < KeyType, ext::trie < KeyType, ValueType > > children = parseChildren ( input ); +template < typename T, typename R > +ext::trie < T, R > xmlApi < ext::trie < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + R value = alib::xmlApi < R >::parse ( input ); + ext::map < T, ext::trie < T, R > > children = parseChildren ( input ); - ext::trie < KeyType, ValueType > trie ( std::move ( value ), std::move ( children ) ); + ext::trie < T, R > trie ( std::move ( value ), std::move ( children ) ); - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsTrie < >::getXmlTagName ( ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return trie; } -template < class KeyType, class ValueType > -void ObjectsTrie < KeyType, ValueType >::composeChildren ( ext::deque < sax::Token > & out, const ext::map < KeyType, ext::trie < KeyType, ValueType > > & children ) { - for ( const std::pair < const KeyType, ext::trie < KeyType, ValueType > > & child : children ) { +template < typename T, typename R > +bool xmlApi < ext::trie < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < typename T, typename R > +const std::string & xmlApi < ext::trie < T, R > >::xmlTagName ( ) { + static std::string xmlTagName = "Trie"; + + return xmlTagName; +} + +template < typename T, typename R > +void xmlApi < ext::trie < T, R > >::composeChildren ( ext::deque < sax::Token > & out, const ext::map < T, ext::trie < T, R > > & children ) { + for ( const std::pair < const T, ext::trie < T, R > > & child : children ) { out.emplace_back ( "Child", sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < KeyType >::compose ( out, child.first ); - alib::xmlApi < ValueType >::compose ( out, child.second.getData ( ) ); + alib::xmlApi < T >::compose ( out, child.first ); + alib::xmlApi < R >::compose ( out, child.second.getData ( ) ); composeChildren ( out, child.second.getChildren ( ) ); out.emplace_back ( "Child", sax::Token::TokenType::END_ELEMENT ); } } -template < class KeyType, class ValueType > -void ObjectsTrie < KeyType, ValueType >::compose ( ext::deque < sax::Token > & out, const ext::trie < KeyType, ValueType > & input ) { - out.emplace_back ( ObjectsTrie < >::getXmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ValueType >::compose ( out, input.getData ( ) ); - composeChildren ( out, input.getChildren ( ) ); - out.emplace_back ( ObjectsTrie < >::getXmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); -} - -template < class KeyType, class ValueType > -void ObjectsTrie < KeyType, ValueType >::compose ( ext::deque < sax::Token > & out, const ObjectsTrie < KeyType, ValueType > & input ) { - compose ( out, static_cast < const ext::trie < KeyType, ValueType > & > ( input ) ); -} - -template < class KeyType, class ValueType > -alib::ObjectBase* ObjectsTrie < KeyType, ValueType >::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +template < typename T, typename R > +void xmlApi < ext::trie < T, R > >::compose ( ext::deque < sax::Token > & output, const ext::trie < T, R > & input ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < R >::compose ( output, input.getData ( ) ); + composeChildren ( output, input.getChildren ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); } -} /* namespace container */ - -namespace alib { - template < typename T, typename R > -struct xmlApi < ext::trie < T, R > > { - static ext::trie < T, R > parse ( ext::deque < sax::Token >::iterator & input ); +struct xmlApi < container::ObjectsTrie < T, R > > { + static container::ObjectsTrie < T, R > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const ext::trie < T, R > & data ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsTrie < T, R > & data ); }; template < typename T, typename R > -ext::trie < T, R > xmlApi < ext::trie < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsTrie < T, R >::parseRaw ( input ); +container::ObjectsTrie < T, R > xmlApi < container::ObjectsTrie < T, R > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsTrie < T, R > ( xmlApi < ext::trie < T, R > >::parse ( input ) ); } template < typename T, typename R > -bool xmlApi < ext::trie < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { +bool xmlApi < container::ObjectsTrie < T, R > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } template < typename T, typename R > -std::string xmlApi < ext::trie < T, R > >::xmlTagName ( ) { - return container::ObjectsTrie < >::getXmlTagName ( ); +const std::string & xmlApi < container::ObjectsTrie < T, R > >::xmlTagName ( ) { + return xmlApi < ext::trie < T, R > >::xmlTagName ( ); } template < typename T, typename R > -void xmlApi < ext::trie < T, R > >::compose ( ext::deque < sax::Token > & output, const ext::trie < T, R > & input ) { - return container::ObjectsTrie < T, R >::compose ( output, input ); +void xmlApi < container::ObjectsTrie < T, R > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsTrie < T, R > & input ) { + xmlApi < ext::trie < T, R > >::compose ( output, input ); } template < > diff --git a/alib2common/src/container/ObjectsVector.h b/alib2common/src/container/ObjectsVector.h index 0a66b2fa078708d0f3795430239cc13e3d4b9eb1..acedb19d7405c00f3202fbdee138a8aa36d6b32c 100644 --- a/alib2common/src/container/ObjectsVector.h +++ b/alib2common/src/container/ObjectsVector.h @@ -49,18 +49,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Vector"; - - return xmlTagName; - } - - static ObjectsVector parse ( ext::deque < sax::Token >::iterator & input ); - static ext::vector < ElementType > parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const ext::vector < ElementType > & input ); - static void compose ( ext::deque < sax::Token > & out, const ObjectsVector < ElementType > & input ); - virtual alib::ObjectBase * inc ( ) &&; typedef ObjectsVector < > normalized_type; @@ -104,73 +92,83 @@ ObjectsVector < ElementType >::operator std::string ( ) const { } template < class ElementType > -ObjectsVector < ElementType > ObjectsVector < ElementType >::parse ( ext::deque < sax::Token >::iterator & input ) { - return ObjectsVector < ElementType > ( parseRaw ( input ) ); +alib::ObjectBase* ObjectsVector < ElementType >::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); } -template < class ElementType > -ext::vector < ElementType > ObjectsVector < ElementType >::parseRaw ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, ObjectsVector < >::getXmlTagName() ); +} /* namespace container */ - ext::vector < ElementType > vector; +namespace alib { - while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) - vector.push_back ( alib::xmlApi < ElementType >::parse ( input ) ); +template < typename T > +struct xmlApi < ext::vector < T > > { + static ext::vector < T > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const ext::vector < T > & data ); +}; - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, ObjectsVector < >::getXmlTagName() ); - return vector; -} +template < typename T > +ext::vector < T > xmlApi < ext::vector < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); -template < class ElementType > -void ObjectsVector < ElementType >::compose ( ext::deque < sax::Token > & out, const ext::vector < ElementType > & input ) { - out.emplace_back ( ObjectsVector < >::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); + ext::vector < T > vector; - for ( const ElementType & item : input ) - alib::xmlApi < ElementType >::compose ( out, item ); + while ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::START_ELEMENT ) ) + vector.push_back ( alib::xmlApi < T >::parse ( input ) ); - out.emplace_back ( ObjectsVector < >::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return vector; } -template < class ElementType > -void ObjectsVector < ElementType >::compose ( ext::deque < sax::Token > & out, const ObjectsVector < ElementType > & input ) { - compose ( out, static_cast < const ext::vector < ElementType > & > ( input ) ); +template < typename T > +bool xmlApi < ext::vector < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -template < class ElementType > -alib::ObjectBase* ObjectsVector < ElementType >::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +template < typename T > +const std::string & xmlApi < ext::vector < T > >::xmlTagName ( ) { + static std::string xmlTagName = "Vector"; + + return xmlTagName; } -} /* namespace container */ +template < typename T > +void xmlApi < ext::vector < T > >::compose ( ext::deque < sax::Token > & output, const ext::vector < T > & input ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); -namespace alib { + for ( const T & item : input ) + alib::xmlApi < T >::compose ( output, item ); + + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} template < typename T > -struct xmlApi < ext::vector < T > > { - static ext::vector < T > parse ( ext::deque < sax::Token >::iterator & input ); +struct xmlApi < container::ObjectsVector < T > > { + static container::ObjectsVector < T > parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const ext::vector < T > & data ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const container::ObjectsVector < T > & data ); }; template < typename T > -ext::vector < T > xmlApi < ext::vector < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { - return container::ObjectsVector < T >::parseRaw ( input ); +container::ObjectsVector < T > xmlApi < container::ObjectsVector < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return container::ObjectsVector < T > ( xmlApi < ext::vector < T > >::parse ( input ) ); } template < typename T > -bool xmlApi < ext::vector < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); +bool xmlApi < container::ObjectsVector < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return xmlApi < ext::vector < T > >::first ( input ); } template < typename T > -std::string xmlApi < ext::vector < T > >::xmlTagName ( ) { - return container::ObjectsVector < >::getXmlTagName(); +const std::string & xmlApi < container::ObjectsVector < T > >::xmlTagName ( ) { + return xmlApi < ext::vector < T > >::xmlTagName ( ); } template < typename T > -void xmlApi < ext::vector < T > >::compose ( ext::deque < sax::Token > & output, const ext::vector < T > & input ) { - return container::ObjectsVector < T >::compose ( output, input ); +void xmlApi < container::ObjectsVector < T > >::compose ( ext::deque < sax::Token > & output, const container::ObjectsVector < T > & input ) { + return xmlApi < ext::vector < T > >::compose ( output, input ); } template < > diff --git a/alib2common/src/core/xmlApi.hpp b/alib2common/src/core/xmlApi.hpp index 2a573a4edd3bb2bad32cae2bab51e666a084c2e8..f3103be001efb766f713b148d60e113387eabda3 100644 --- a/alib2common/src/core/xmlApi.hpp +++ b/alib2common/src/core/xmlApi.hpp @@ -19,12 +19,14 @@ #include "base/CommonBase.hpp" #include "base/WrapperBase.hpp" -#include "exception/CommonException.h" #include <global/GlobalData.h> namespace alib { +template < typename T, typename Enable = void > +struct xmlApi { }; + class xmlApiInputContext : public ext::deque < sax::Token >::iterator { template < typename T, typename Enable > friend struct xmlApi; @@ -77,28 +79,11 @@ public: }; -template < typename T, typename Enable = void > -struct xmlApi { }; - -template < typename Type > -struct xmlApi < Type, typename std::enable_if < std::is_base_of < CommonBaseBase, Type >::value >::type > { - static Type parse ( ext::deque < sax::Token >::iterator & input ) { - return Type::parse ( input ); - } - - static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); - } - - static std::string xmlTagName ( ) { - return Type::getXmlTagName(); - } +} /* namespace alib */ - static void compose ( ext::deque < sax::Token > & output, const Type & data ) { - Type::compose ( output, data ); - } +#include "exception/CommonException.h" -}; +namespace alib { template < typename Group > struct xmlApi < Group, typename std::enable_if < std::is_base_of < WrapperBaseBase, Group >::value >::type > { @@ -119,7 +104,7 @@ private: std::function < Type ( ext::deque < sax::Token >::iterator & ) > parseFunction; public: - ParserRegister( ) : parseFunction ( Type::parse ) { + ParserRegister( ) : parseFunction ( xmlApi < Type >::parse ) { } virtual Group parse ( ext::deque < sax::Token >::iterator & input ) { @@ -144,7 +129,7 @@ private: std::function < void ( ext::deque < sax::Token > &, const Type & ) > composeFunction; public: - ComposerRegister( ) : composeFunction ( ( void (*) ( ext::deque < sax::Token > &, const Type & ) ) Type::compose ) { + ComposerRegister( ) : composeFunction ( xmlApi < Type >::compose ) { } virtual void compose ( ext::deque < sax::Token > & input, const Group & group ) { diff --git a/alib2common/src/exception/CommonException.cpp b/alib2common/src/exception/CommonException.cpp index 84ffc6f70b4ee682c873eef243ff90d2959c8700..44f91297453da89358e3d0efb073c36fc9cf3c40 100644 --- a/alib2common/src/exception/CommonException.cpp +++ b/alib2common/src/exception/CommonException.cpp @@ -77,8 +77,16 @@ CommonException::operator std::string() const { return this->m_whatMessage; } -CommonException CommonException::parse(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, CommonException::getXmlTagName()); +alib::ObjectBase* CommonException::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +} + +} /* namespace exception */ + +namespace alib { + +exception::CommonException xmlApi < exception::CommonException >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName()); sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "cause"); std::string cause = ""; if (input->getType() == sax::Token::TokenType::CHARACTER) { @@ -100,35 +108,33 @@ CommonException CommonException::parse(ext::deque<sax::Token>::iterator& input) ++input; } sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "command"); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, CommonException::getXmlTagName()); - return CommonException(std::move(cause), std::move(backtrace), std::move(command)); + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, xmlTagName()); + return exception::CommonException(std::move(cause), std::move(backtrace), std::move(command)); } -void CommonException::compose(ext::deque<sax::Token>& out) const { - out.emplace_back(CommonException::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - out.emplace_back("cause", sax::Token::TokenType::START_ELEMENT); - out.emplace_back(m_cause, sax::Token::TokenType::CHARACTER); - out.emplace_back("cause", sax::Token::TokenType::END_ELEMENT); - out.emplace_back("backtrace", sax::Token::TokenType::START_ELEMENT); - out.emplace_back(m_backtrace, sax::Token::TokenType::CHARACTER); - out.emplace_back("backtrace", sax::Token::TokenType::END_ELEMENT); - out.emplace_back("command", sax::Token::TokenType::START_ELEMENT); - out.emplace_back(m_command, sax::Token::TokenType::CHARACTER); - out.emplace_back("command", sax::Token::TokenType::END_ELEMENT); - out.emplace_back(CommonException::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < exception::CommonException >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void CommonException::compose(ext::deque<sax::Token>& out, const CommonException & exception ) { - exception.compose ( out ); -} +const std::string & xmlApi < exception::CommonException >::xmlTagName ( ) { + static std::string xmlTagName = "CommonException"; -alib::ObjectBase* CommonException::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); + return xmlTagName; } -} /* namespace exception */ - -namespace alib { +void xmlApi < exception::CommonException >::compose ( ext::deque < sax::Token > & output, const exception::CommonException & data ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( "cause", sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( data.getCause ( ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( "cause", sax::Token::TokenType::END_ELEMENT ); + output.emplace_back ( "backtrace", sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( data.getBacktrace ( ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( "backtrace", sax::Token::TokenType::END_ELEMENT ); + output.emplace_back ( "command", sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( data.getCommand ( ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( "command", sax::Token::TokenType::END_ELEMENT ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} auto alibExceptionType = registration::TypeRegister<alib::Object, exception::CommonException>(); diff --git a/alib2common/src/exception/CommonException.h b/alib2common/src/exception/CommonException.h index 28dff248ab6fe4cd48570a8552fc3c8f0aafcf96..e9bda298d76feec16e5a6314e11c451d8b95556d 100644 --- a/alib2common/src/exception/CommonException.h +++ b/alib2common/src/exception/CommonException.h @@ -12,7 +12,6 @@ #include <exception> #include <string> #include <ostream> -#include "../sax/Token.h" #include "../object/ObjectBase.h" @@ -70,20 +69,23 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "CommonException"; + virtual alib::ObjectBase * inc ( ) &&; +}; - return xmlTagName; - } +} /* namespace exception */ - static CommonException parse ( ext::deque < sax::Token >::iterator & input ); +#include <core/xmlApi.hpp> - void compose ( ext::deque < sax::Token > & out ) const; - static void compose ( ext::deque < sax::Token > & out, const CommonException & input ); +namespace alib { - virtual alib::ObjectBase * inc ( ) &&; +template < > +struct xmlApi < exception::CommonException > { + static exception::CommonException parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const exception::CommonException & data ); }; -} /* namespace exception */ +} /* namespace alib */ #endif /* COMMON_EXCEPTION_H_ */ diff --git a/alib2common/src/object/AnyObject.h b/alib2common/src/object/AnyObject.h index 89bfbd5e95867d6a4fd7ead2b566a3a49e1f8e34..8616e9cb8dd19187ec6c6431372c2062a672f8d3 100644 --- a/alib2common/src/object/AnyObject.h +++ b/alib2common/src/object/AnyObject.h @@ -95,11 +95,6 @@ AnyObject < T > ::operator std::string () const { return "V"; } -template < class T > -void AnyObject < T >::compose(ext::deque<sax::Token>& out, const AnyObject & input) { - alib::xmlApi < T >::compose(out, input.m_data); -} - template < class T > ObjectBase* AnyObject < T >::inc() && { return new UniqueObject(Object(std::move(*this)), primitive::Integer(0)); @@ -107,4 +102,36 @@ ObjectBase* AnyObject < T >::inc() && { } /* namespace alib */ +namespace alib { + +template < typename T > +struct xmlApi < alib::AnyObject < T > > { + static alib::AnyObject < T > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const alib::AnyObject < T > & data ); +}; + +template < typename T > +alib::AnyObject < T > xmlApi < alib::AnyObject < T > >::parse ( ext::deque < sax::Token >::iterator & input ) { + return alib::AnyObject < T > ( alib::xmlApi < T >::parse ( input ) ); +} + +template < typename T > +bool xmlApi < alib::AnyObject < T > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return alib::xmlApi < T >::first ( input ); +} + +template < typename T > +const std::string & xmlApi < alib::AnyObject < T > >::xmlTagName ( ) { + return alib::xmlApi < T >::xmlTagName ( ); +} + +template < typename T > +void xmlApi < alib::AnyObject < T > >::compose ( ext::deque < sax::Token > & output, const alib::AnyObject < T > & input ) { + alib::xmlApi < T >::compose ( output, input.getData ( ) ); +} + +} /* namespace alib */ + #endif /* ANY_OBJECT_H_ */ diff --git a/alib2common/src/object/UniqueObject.cpp b/alib2common/src/object/UniqueObject.cpp index 1829bd551a84d68b045a65ff8bb60e2a9598beaf..c83b6d0a3ae1004e119586f24f5b7e687488aba7 100644 --- a/alib2common/src/object/UniqueObject.cpp +++ b/alib2common/src/object/UniqueObject.cpp @@ -57,32 +57,42 @@ UniqueObject::operator std::string() const { return std::move(ss).str(); } -UniqueObject UniqueObject::parse(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, UniqueObject::getXmlTagName()); +ObjectBase* UniqueObject::inc() && { + std::move(m_id).inc(); + return NULL; +} + +} /* namespace alib */ + +namespace alib { + +alib::UniqueObject xmlApi < alib::UniqueObject >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); - Object firstSymbol = alib::xmlApi<Object>::parse(input); - primitive::Integer secondSymbol = alib::xmlApi<primitive::Integer>::parse(input); + Object firstSymbol = alib::xmlApi < Object >::parse ( input ); + primitive::Integer secondSymbol = alib::xmlApi < primitive::Integer >::parse ( input ); - UniqueObject data(std::move(firstSymbol), std::move(secondSymbol)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, UniqueObject::getXmlTagName()); + UniqueObject data ( std::move ( firstSymbol ), std::move ( secondSymbol ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return data; } -void UniqueObject::compose(ext::deque<sax::Token>& out, const UniqueObject & input ) { - out.emplace_back(UniqueObject::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - alib::xmlApi<alib::Object>::compose(out, input.m_symbol); - alib::xmlApi<primitive::Integer>::compose(out, input.m_id); - out.emplace_back(UniqueObject::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < alib::UniqueObject >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -ObjectBase* UniqueObject::inc() && { - std::move(m_id).inc(); - return NULL; -} +const std::string & xmlApi < alib::UniqueObject >::xmlTagName ( ) { + static std::string xmlTagName = "UniqueObject"; -} /* namespace alib */ + return xmlTagName; +} -namespace alib { +void xmlApi < alib::UniqueObject >::compose ( ext::deque < sax::Token > & output, const alib::UniqueObject & object ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < alib::Object >::compose ( output, object.getSymbol ( ) ); + alib::xmlApi < primitive::Integer >::compose ( output, object.getId ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} auto uniqueSymbolType2 = registration::TypeRegister < alib::Object, alib::UniqueObject > (); diff --git a/alib2common/src/object/UniqueObject.h b/alib2common/src/object/UniqueObject.h index 98210271c6255e5079df12bf12df494f459bdb7b..b3cb9a7328ed57b45f0f737aeef005a9d9330493 100644 --- a/alib2common/src/object/UniqueObject.h +++ b/alib2common/src/object/UniqueObject.h @@ -53,17 +53,19 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "UniqueObject"; - - return xmlTagName; - } + virtual ObjectBase * inc ( ) &&; +}; - static UniqueObject parse ( ext::deque < sax::Token >::iterator & input ); +} /* namespace alib */ - static void compose ( ext::deque < sax::Token > & out, const UniqueObject & input ); +namespace alib { - virtual ObjectBase * inc ( ) &&; +template < > +struct xmlApi < alib::UniqueObject > { + static alib::UniqueObject parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const alib::UniqueObject & data ); }; } /* namespace alib */ diff --git a/alib2common/src/object/Void.cpp b/alib2common/src/object/Void.cpp index 6fe6f8a17ff289929d1ccb843f2ac8cf23b2037e..a3a1e3d709886249bc691fc29026bd0d4e9f267c 100644 --- a/alib2common/src/object/Void.cpp +++ b/alib2common/src/object/Void.cpp @@ -40,15 +40,6 @@ Void::operator std::string () const { Void Void::VOID = Void(); -Void Void::parse(ext::deque<sax::Token>::iterator& input) { - xmlApi < void >::parse ( input ); - return Void(); -} - -void Void::compose(ext::deque<sax::Token>& out, const Void & ) { - xmlApi < void >::compose ( out ); -} - ObjectBase* Void::inc() && { return new UniqueObject(Object(std::move(*this)), primitive::Integer(0)); } @@ -57,18 +48,41 @@ ObjectBase* Void::inc() && { namespace alib { -void xmlApi<void>::parse(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, Void::getXmlTagName()); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, Void::getXmlTagName()); +void xmlApi < void >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); +} + +bool xmlApi < void >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +const std::string & xmlApi < void >::xmlTagName ( ) { + static std::string xmlTagName = "Void"; + + return xmlTagName; +} + +void xmlApi < void >::compose ( ext::deque < sax::Token > & output ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + +alib::Void xmlApi < alib::Void >::parse ( ext::deque < sax::Token >::iterator & input ) { + xmlApi < void >::parse ( input ); + return alib::Void ( ); +} + +bool xmlApi < alib::Void >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -bool xmlApi<void>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, alib::Void::getXmlTagName()); +const std::string & xmlApi < alib::Void >::xmlTagName ( ) { + return xmlApi < void >::xmlTagName ( ); } -void xmlApi<void>::compose(ext::deque<sax::Token>& output) { - output.emplace_back(Void::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - output.emplace_back(Void::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +void xmlApi < alib::Void >::compose ( ext::deque < sax::Token > & output, const alib::Void & ) { + xmlApi < void >::compose ( output ); } auto voidType = registration::TypeRegister < alib::Object, alib::Void > (); diff --git a/alib2common/src/object/Void.h b/alib2common/src/object/Void.h index 975c7a0c663536e16fc2449a314cda6b5fa7cd8b..738da4a25fb9a29d9b97c96c77af38894d3f5b70 100644 --- a/alib2common/src/object/Void.h +++ b/alib2common/src/object/Void.h @@ -43,16 +43,6 @@ public: static Void VOID; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Void"; - - return xmlTagName; - } - - static Void parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const Void & input ); - virtual ObjectBase * inc ( ) &&; }; @@ -64,9 +54,18 @@ template < > struct xmlApi < void > { static void parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output ); }; +template < > +struct xmlApi < alib::Void > { + static alib::Void parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const alib::Void & data ); +}; + } /* namespace alib */ #endif /* VOID_H_ */ diff --git a/alib2common/src/primitive/Bool.cpp b/alib2common/src/primitive/Bool.cpp index 2f892b6b9023dae56b22cfc5112acd474b737563..6d9a278be94bf2c45e4c98b8c13384b126a97a95 100644 --- a/alib2common/src/primitive/Bool.cpp +++ b/alib2common/src/primitive/Bool.cpp @@ -51,60 +51,64 @@ Bool::operator std::string() const { return m_data ? "true" : "false"; } -Bool Bool::parse(ext::deque<sax::Token>::iterator& input) { - return Bool(parseRaw(input)); +PrimitiveBase * Bool::inc() && { + m_data = !m_data; + return NULL; } -bool Bool::parseRaw(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, Bool::getXmlTagName()); - std::string tmp = sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER); +} /* namespace primitive */ + +namespace alib { + +bool xmlApi < bool >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + + std::string tmp = sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ); bool data; - if(tmp == "true") + if ( tmp == "true" ) data = true; - else if(tmp == "false") + else if ( tmp == "false" ) data = false; else - throw exception::CommonException("Invalid boolean value"); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, Bool::getXmlTagName()); + throw exception::CommonException ( "Invalid boolean value" ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return data; } -void Bool::compose(ext::deque<sax::Token>& out, bool primitive) { - out.emplace_back(Bool::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - if(primitive) - out.emplace_back("true", sax::Token::TokenType::CHARACTER); - else - out.emplace_back("false", sax::Token::TokenType::CHARACTER); - out.emplace_back(Bool::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < bool >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void Bool::compose(ext::deque<sax::Token>& out, const Bool & primitive) { - compose ( out, primitive.getData ( ) ); -} +const std::string & xmlApi < bool >::xmlTagName ( ) { + static std::string xmlTagName = "Bool"; -PrimitiveBase * Bool::inc() && { - m_data = !m_data; - return NULL; + return xmlTagName; } -} /* namespace primitive */ - -namespace alib { +void xmlApi < bool >::compose ( ext::deque < sax::Token > & output, bool data ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT); + if ( data ) + output.emplace_back ( "true", sax::Token::TokenType::CHARACTER ); + else + output.emplace_back ( "false", sax::Token::TokenType::CHARACTER ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} -bool xmlApi<bool>::parse(ext::deque<sax::Token>::iterator& input) { - return primitive::Bool::parseRaw(input); +primitive::Bool xmlApi < primitive::Bool >::parse ( ext::deque < sax::Token >::iterator & input ) { + return primitive::Bool ( xmlApi < bool >::parse ( input ) ); } -bool xmlApi<bool>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName()); +bool xmlApi < primitive::Bool >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -std::string xmlApi<bool>::xmlTagName() { - return primitive::Bool::getXmlTagName(); +const std::string & xmlApi < primitive::Bool >::xmlTagName ( ) { + return xmlApi < bool >::xmlTagName ( ); } -void xmlApi<bool>::compose(ext::deque<sax::Token>& output, bool data) { - primitive::Bool::compose(output, data); +void xmlApi < primitive::Bool >::compose ( ext::deque < sax::Token > & output, const primitive::Bool & data ) { + xmlApi < bool >::compose ( output, data.getData ( ) ); } auto boolType = registration::TypeRegister < primitive::Primitive, primitive::Bool > (); diff --git a/alib2common/src/primitive/Bool.h b/alib2common/src/primitive/Bool.h index ace43722bec062cc2497491731a78a1b6904e6e1..de75f2d210db7f7cf70419afca66844e205c467c 100644 --- a/alib2common/src/primitive/Bool.h +++ b/alib2common/src/primitive/Bool.h @@ -55,18 +55,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Bool"; - - return xmlTagName; - } - - static Bool parse ( ext::deque < sax::Token >::iterator & input ); - static bool parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, bool primitive ); - static void compose ( ext::deque < sax::Token > & out, const Bool & primitive ); - virtual PrimitiveBase * inc ( ) &&; }; @@ -78,10 +66,18 @@ template < > struct xmlApi < bool > { static bool parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, bool data ); }; +template < > +struct xmlApi < primitive::Bool > { + static primitive::Bool parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const primitive::Bool & data ); +}; + } /* namespace alib */ #endif /* PRIMITIVE_BOOL_H_ */ diff --git a/alib2common/src/primitive/Character.cpp b/alib2common/src/primitive/Character.cpp index e29fefcaf42cc9ccfe48b4e0ed5081265990fd5f..92f1eca16e906051e2811317a5c0ee06c9500901 100644 --- a/alib2common/src/primitive/Character.cpp +++ b/alib2common/src/primitive/Character.cpp @@ -50,50 +50,52 @@ Character::operator std::string() const { return std::string(1, m_data); } -Character Character::parse(ext::deque<sax::Token>::iterator& input) { - return Character(parseRaw(input)); +PrimitiveBase * Character::inc() && { + m_data++; + return NULL; } -char Character::parseRaw(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, Character::getXmlTagName()); - char data = sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER)[0]; - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, Character::getXmlTagName()); +} /* namespace primitive */ + +namespace alib { + +char xmlApi < char >::parse ( ext::deque < sax::Token >::iterator & input) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + char data = sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ) [ 0 ]; + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return data; } -void Character::compose(ext::deque<sax::Token>& out, char primitive) { - out.emplace_back(Character::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - out.emplace_back(std::string(1, primitive), sax::Token::TokenType::CHARACTER); - out.emplace_back(Character::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < char >::first ( const ext::deque < sax::Token >::const_iterator & input) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void Character::compose(ext::deque<sax::Token>& out, const Character & primitive) { - compose ( out, primitive.getData ( ) ); -} +const std::string & xmlApi < char >::xmlTagName ( ) { + static std::string xmlTagName = "Character"; -PrimitiveBase * Character::inc() && { - m_data++; - return NULL; + return xmlTagName; } -} /* namespace primitive */ - -namespace alib { +void xmlApi < char >::compose ( ext::deque < sax::Token > & output, char data ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( std::string ( 1, data ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} -char xmlApi<char>::parse(ext::deque<sax::Token>::iterator& input) { - return primitive::Character::parseRaw(input); +primitive::Character xmlApi < primitive::Character >::parse ( ext::deque < sax::Token >::iterator & input ) { + return primitive::Character ( xmlApi < char >::parse ( input ) ); } -bool xmlApi<char>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName()); +bool xmlApi < primitive::Character >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -std::string xmlApi<char>::xmlTagName() { - return primitive::Character::getXmlTagName(); +const std::string & xmlApi < primitive::Character >::xmlTagName ( ) { + return xmlApi < char >::xmlTagName ( ); } -void xmlApi<char>::compose(ext::deque<sax::Token>& output, char data) { - primitive::Character::compose(output, data); +void xmlApi < primitive::Character >::compose ( ext::deque < sax::Token > & output, const primitive::Character & data ) { + xmlApi < char >::compose ( output, data.getData ( ) ); } auto characterType = registration::TypeRegister < primitive::Primitive, primitive::Character > (); diff --git a/alib2common/src/primitive/Character.h b/alib2common/src/primitive/Character.h index ab2e7b27d7a13258120f1f16083ff588f8c73d7a..9c70787a772daa247558725bea12a2193f750c58 100644 --- a/alib2common/src/primitive/Character.h +++ b/alib2common/src/primitive/Character.h @@ -55,18 +55,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Character"; - - return xmlTagName; - } - - static Character parse ( ext::deque < sax::Token >::iterator & input ); - static char parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, char primitive ); - static void compose ( ext::deque < sax::Token > & out, const Character & primitive ); - virtual PrimitiveBase * inc ( ) &&; }; @@ -78,10 +66,18 @@ template < > struct xmlApi < char > { static char parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, char data ); }; +template < > +struct xmlApi < primitive::Character > { + static primitive::Character parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const primitive::Character & data ); +}; + } /* namespace alib */ #endif /* PRIMITIVE_CHARACTER_H_ */ diff --git a/alib2common/src/primitive/Double.cpp b/alib2common/src/primitive/Double.cpp index d60afc88b6693f2f628d75fca9e6a92a88292e0b..914d110862dec238090c733181f28cf8d3c30866 100644 --- a/alib2common/src/primitive/Double.cpp +++ b/alib2common/src/primitive/Double.cpp @@ -55,50 +55,52 @@ Double::operator std::string() const { return ext::to_string(m_data); } -Double Double::parse(ext::deque<sax::Token>::iterator& input) { - return Double(parseRaw(input)); +PrimitiveBase * Double::inc() && { + m_data += 1; // TODO fix this + return this; } -double Double::parseRaw(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, Double::getXmlTagName()); - double data = ext::from_string < double > (sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, Double::getXmlTagName()); +} /* namespace primitive */ + +namespace alib { + +int xmlApi < double >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + double data = ext::from_string < double > ( sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return data; } -void Double::compose(ext::deque<sax::Token>& out, double primitive) { - out.emplace_back(Double::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - out.emplace_back(ext::to_string(primitive), sax::Token::TokenType::CHARACTER); - out.emplace_back(Double::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < double >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void Double::compose(ext::deque<sax::Token>& out, const Double & primitive) { - compose ( out, primitive.getData ( ) ); -} +const std::string & xmlApi < double >::xmlTagName ( ) { + static std::string xmlTagName = "Double"; -PrimitiveBase * Double::inc() && { - m_data += 1; // TODO fix this - return this; + return xmlTagName; } -} /* namespace primitive */ - -namespace alib { +void xmlApi < double >::compose ( ext::deque < sax::Token > & output, double data ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( ext::to_string ( data ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} -int xmlApi<double>::parse(ext::deque<sax::Token>::iterator& input) { - return primitive::Double::parseRaw(input); +primitive::Double xmlApi < primitive::Double >::parse ( ext::deque < sax::Token >::iterator & input ) { + return primitive::Double ( xmlApi < double >::parse ( input ) ); } -bool xmlApi<double>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName()); +bool xmlApi < primitive::Double >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -std::string xmlApi<double>::xmlTagName() { - return primitive::Double::getXmlTagName(); +const std::string & xmlApi < primitive::Double >::xmlTagName ( ) { + return xmlApi < double >::xmlTagName ( ); } -void xmlApi<double>::compose(ext::deque<sax::Token>& output, double data) { - primitive::Double::compose(output, data); +void xmlApi < primitive::Double >::compose ( ext::deque < sax::Token > & output, const primitive::Double & data ) { + xmlApi < double >::compose ( output, data.getData ( ) ); } auto doubleType = registration::TypeRegister < primitive::Primitive, primitive::Double > (); diff --git a/alib2common/src/primitive/Double.h b/alib2common/src/primitive/Double.h index 97440845a95bde7a14c615850772b9bb9971da25..615dba2a98fd6dabda6289db1c99fd4b8a7aefed 100644 --- a/alib2common/src/primitive/Double.h +++ b/alib2common/src/primitive/Double.h @@ -55,18 +55,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Double"; - - return xmlTagName; - } - - static Double parse ( ext::deque < sax::Token >::iterator & input ); - static double parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, double primitive ); - static void compose ( ext::deque < sax::Token > & out, const Double & primitive ); - virtual PrimitiveBase * inc ( ) &&; }; @@ -78,10 +66,18 @@ template < > struct xmlApi < double > { static int parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, double data ); }; +template < > +struct xmlApi < primitive::Double > { + static primitive::Double parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const primitive::Double & data ); +}; + } /* namespace alib */ #endif /* PRIMITIVE_DOUBLE_H_ */ diff --git a/alib2common/src/primitive/Integer.cpp b/alib2common/src/primitive/Integer.cpp index 14c10d7710a88e62c54d8dcb9836eee45fc28cf5..9bcba39ad9ae06ef98fe1156705b906ae0e9286c 100644 --- a/alib2common/src/primitive/Integer.cpp +++ b/alib2common/src/primitive/Integer.cpp @@ -50,50 +50,52 @@ Integer::operator std::string() const { return ext::to_string(m_data); } -Integer Integer::parse(ext::deque<sax::Token>::iterator& input) { - return Integer(parseRaw(input)); +PrimitiveBase * Integer::inc() && { + m_data++; + return NULL; } -int Integer::parseRaw(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, Integer::getXmlTagName()); - int data = ext::from_string < int > (sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, Integer::getXmlTagName()); +} /* namespace primitive */ + +namespace alib { + +int xmlApi < int >::parse ( ext::deque < sax::Token >::iterator & input) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + int data = ext::from_string < int > ( sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return data; } -void Integer::compose(ext::deque<sax::Token>& out, int primitive) { - out.emplace_back(Integer::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - out.emplace_back(ext::to_string(primitive), sax::Token::TokenType::CHARACTER); - out.emplace_back(Integer::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < int >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void Integer::compose(ext::deque<sax::Token>& out, const Integer & primitive) { - compose ( out, primitive.getData ( ) ); -} +const std::string & xmlApi < int >::xmlTagName ( ) { + static std::string xmlTagName = "Integer"; -PrimitiveBase * Integer::inc() && { - m_data++; - return NULL; + return xmlTagName; } -} /* namespace primitive */ - -namespace alib { +void xmlApi < int >::compose ( ext::deque < sax::Token > & output, int data ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( ext::to_string ( data ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} -int xmlApi<int>::parse(ext::deque<sax::Token>::iterator& input) { - return primitive::Integer::parseRaw(input); +primitive::Integer xmlApi < primitive::Integer >::parse ( ext::deque < sax::Token >::iterator & input ) { + return primitive::Integer ( xmlApi < int >::parse ( input ) ); } -bool xmlApi<int>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName()); +bool xmlApi < primitive::Integer >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -std::string xmlApi<int>::xmlTagName() { - return primitive::Integer::getXmlTagName(); +const std::string & xmlApi < primitive::Integer >::xmlTagName ( ) { + return xmlApi < int >::xmlTagName ( ); } -void xmlApi<int>::compose(ext::deque<sax::Token>& output, int data) { - primitive::Integer::compose(output, data); +void xmlApi < primitive::Integer >::compose ( ext::deque < sax::Token > & output, const primitive::Integer & data ) { + xmlApi < int >::compose ( output, data.getData ( ) ); } auto integerType = registration::TypeRegister < primitive::Primitive, primitive::Integer > (); diff --git a/alib2common/src/primitive/Integer.h b/alib2common/src/primitive/Integer.h index 54cfd637cc0c0104bc926f746ed03f001f7425ff..9e8f10a22b9c6a086e688022411224df3c18c071 100644 --- a/alib2common/src/primitive/Integer.h +++ b/alib2common/src/primitive/Integer.h @@ -55,18 +55,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Integer"; - - return xmlTagName; - } - - static Integer parse ( ext::deque < sax::Token >::iterator & input ); - static int parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, int primitive ); - static void compose ( ext::deque < sax::Token > & out, const Integer & primitive ); - virtual PrimitiveBase * inc ( ) &&; }; @@ -78,10 +66,18 @@ template < > struct xmlApi < int > { static int parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, int data ); }; +template < > +struct xmlApi < primitive::Integer > { + static primitive::Integer parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const primitive::Integer & data ); +}; + } /* namespace alib */ #endif /* PRIMITIVE_INTEGER_H_ */ diff --git a/alib2common/src/primitive/String.cpp b/alib2common/src/primitive/String.cpp index 3dcfe602882dfa90f9854a7b5ea14ce91a6c3261..5a8134853e1e33c95ca6c888bd16f77d08e77fd5 100644 --- a/alib2common/src/primitive/String.cpp +++ b/alib2common/src/primitive/String.cpp @@ -50,52 +50,54 @@ String::operator std::string() const { return m_data; } -String String::parse(ext::deque<sax::Token>::iterator& input) { - return String(parseRaw(input)); +PrimitiveBase * String::inc() && { + m_data.push_back('\''); + return NULL; } -std::string String::parseRaw(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, primitive::String::getXmlTagName()); +} /* namespace primitive */ + +namespace alib { + +std::string xmlApi < std::string >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); std::string data = ""; - if( sax::FromXMLParserHelper::isTokenType(input, sax::Token::TokenType::CHARACTER)) - data = sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, primitive::String::getXmlTagName()); + if ( sax::FromXMLParserHelper::isTokenType ( input, sax::Token::TokenType::CHARACTER ) ) + data = sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return data; } -void String::compose(ext::deque<sax::Token>& out, const std::string & primitive) { - out.emplace_back(primitive::String::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - out.emplace_back(primitive, sax::Token::TokenType::CHARACTER); - out.emplace_back(primitive::String::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < std::string >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void String::compose(ext::deque<sax::Token>& out, const String & primitive) { - compose ( out, primitive.getData ( ) ); -} +const std::string & xmlApi < std::string >::xmlTagName ( ) { + static std::string xmlTagName = "String"; -PrimitiveBase * String::inc() && { - m_data.push_back('\''); - return NULL; + return xmlTagName; } -} /* namespace primitive */ - -namespace alib { +void xmlApi < std::string >::compose ( ext::deque < sax::Token > & output, const std::string & data) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( data, sax::Token::TokenType::CHARACTER ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} -std::string xmlApi<std::string>::parse(ext::deque<sax::Token>::iterator& input) { - return primitive::String::parseRaw(input); +primitive::String xmlApi < primitive::String >::parse ( ext::deque < sax::Token >::iterator & input ) { + return primitive::String ( xmlApi < std::string >::parse ( input ) ); } -bool xmlApi<std::string>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName()); +bool xmlApi < primitive::String >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -std::string xmlApi<std::string>::xmlTagName() { - return primitive::String::getXmlTagName(); +const std::string & xmlApi < primitive::String >::xmlTagName ( ) { + return xmlApi < std::string >::xmlTagName ( ); } -void xmlApi<std::string>::compose(ext::deque<sax::Token>& output, const std::string & data) { - primitive::String::compose(output, data); +void xmlApi < primitive::String >::compose ( ext::deque < sax::Token > & output, const primitive::String & data ) { + xmlApi < std::string >::compose ( output, data.getData ( ) ); } auto stringType = registration::TypeRegister < primitive::Primitive, primitive::String > (); diff --git a/alib2common/src/primitive/String.h b/alib2common/src/primitive/String.h index a6bf8b809040b1e7da9f7522dee6060edcfcc924..8c656772634981894addd3f099fc07e9309a2b05 100644 --- a/alib2common/src/primitive/String.h +++ b/alib2common/src/primitive/String.h @@ -56,18 +56,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "String"; - - return xmlTagName; - } - - static String parse ( ext::deque < sax::Token >::iterator & input ); - static std::string parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const std::string & primitive ); - static void compose ( ext::deque < sax::Token > & out, const String & primitive ); - virtual PrimitiveBase * inc ( ) &&; }; @@ -79,10 +67,18 @@ template < > struct xmlApi < std::string > { static std::string parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, const std::string & data ); }; +template < > +struct xmlApi < primitive::String > { + static primitive::String parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const primitive::String & data ); +}; + } /* namespace alib */ #endif /* PRIMITIVE_STRING_H_ */ diff --git a/alib2common/src/primitive/Unsigned.cpp b/alib2common/src/primitive/Unsigned.cpp index 9afaf921fc4d57e949b7f25a4482e36ca40705d0..0ee19cdad397d9bcd41d4bc5430c1d582e17168c 100644 --- a/alib2common/src/primitive/Unsigned.cpp +++ b/alib2common/src/primitive/Unsigned.cpp @@ -54,50 +54,52 @@ Unsigned::operator std::string() const { return ext::to_string(m_data); } -Unsigned Unsigned::parse(ext::deque<sax::Token>::iterator& input) { - return Unsigned(parseRaw(input)); +PrimitiveBase * Unsigned::inc() && { + m_data++; + return NULL; } -unsigned Unsigned::parseRaw(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, Unsigned::getXmlTagName()); - unsigned data = ext::from_string < unsigned > (sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, Unsigned::getXmlTagName()); +} /* namespace primitive */ + +namespace alib { + +unsigned xmlApi < unsigned >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + unsigned data = ext::from_string < unsigned > ( sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return data; } -void Unsigned::compose(ext::deque<sax::Token>& out, unsigned primitive) { - out.emplace_back(Unsigned::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - out.emplace_back(ext::to_string(primitive), sax::Token::TokenType::CHARACTER); - out.emplace_back(Unsigned::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < unsigned >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void Unsigned::compose(ext::deque<sax::Token>& out, const Unsigned & primitive) { - compose ( out, primitive.getData ( ) ); -} +const std::string & xmlApi < unsigned >::xmlTagName ( ) { + static std::string xmlTagName = "Unsigned"; -PrimitiveBase * Unsigned::inc() && { - m_data++; - return NULL; + return xmlTagName; } -} /* namespace primitive */ - -namespace alib { +void xmlApi < unsigned >::compose ( ext::deque < sax::Token > & output, unsigned data ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( ext::to_string ( data ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} -unsigned xmlApi<unsigned>::parse(ext::deque<sax::Token>::iterator& input) { - return primitive::Unsigned::parseRaw(input); +primitive::Unsigned xmlApi < primitive::Unsigned >::parse ( ext::deque < sax::Token >::iterator & input ) { + return primitive::Unsigned ( xmlApi < unsigned >::parse ( input ) ); } -bool xmlApi<unsigned>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName()); +bool xmlApi < primitive::Unsigned >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -std::string xmlApi<unsigned>::xmlTagName() { - return primitive::Unsigned::getXmlTagName(); +const std::string & xmlApi < primitive::Unsigned >::xmlTagName ( ) { + return xmlApi < unsigned >::xmlTagName ( ); } -void xmlApi<unsigned>::compose(ext::deque<sax::Token>& output, unsigned data) { - primitive::Unsigned::compose(output, data); +void xmlApi < primitive::Unsigned >::compose ( ext::deque < sax::Token > & output, const primitive::Unsigned & data ) { + xmlApi < unsigned >::compose ( output, data.getData ( ) ); } auto unsignedType = registration::TypeRegister < primitive::Primitive, primitive::Unsigned > (); diff --git a/alib2common/src/primitive/Unsigned.h b/alib2common/src/primitive/Unsigned.h index 5ec168b88a4a200a1601e85ebc59521eb50554cf..a4505a15f9a5b70b2ff3d8c464b082d74e6d3da4 100644 --- a/alib2common/src/primitive/Unsigned.h +++ b/alib2common/src/primitive/Unsigned.h @@ -57,18 +57,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "Unsigned"; - - return xmlTagName; - } - - static Unsigned parse ( ext::deque < sax::Token >::iterator & input ); - static unsigned parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, unsigned primitive ); - static void compose ( ext::deque < sax::Token > & out, const Unsigned & primitive ); - virtual PrimitiveBase * inc ( ) &&; }; @@ -80,10 +68,18 @@ template < > struct xmlApi < unsigned > { static unsigned parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, unsigned data ); }; +template < > +struct xmlApi < primitive::Unsigned > { + static primitive::Unsigned parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const primitive::Unsigned & data ); +}; + } /* namespace alib */ #endif /* PRIMITIVE_UNSIGNED_H_ */ diff --git a/alib2common/src/primitive/UnsignedLong.cpp b/alib2common/src/primitive/UnsignedLong.cpp index e7e9dcecf703464fa3378c06d149b87c1ca9b3e7..893f7b8d9ce39a73ef711366c9d2ce02c71111a6 100644 --- a/alib2common/src/primitive/UnsignedLong.cpp +++ b/alib2common/src/primitive/UnsignedLong.cpp @@ -50,50 +50,52 @@ UnsignedLong::operator std::string() const { return ext::to_string(m_data); } -UnsignedLong UnsignedLong::parse(ext::deque<sax::Token>::iterator& input) { - return UnsignedLong(parseRaw(input)); +PrimitiveBase * UnsignedLong::inc() && { + m_data++; + return NULL; } -unsigned long UnsignedLong::parseRaw(ext::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, UnsignedLong::getXmlTagName()); - unsigned long data = ext::from_string < unsigned long > (sax::FromXMLParserHelper::popTokenData(input, sax::Token::TokenType::CHARACTER)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, UnsignedLong::getXmlTagName()); +} /* namespace primitive */ + +namespace alib { + +unsigned long xmlApi < unsigned long >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + unsigned long data = ext::from_string < unsigned long > ( sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ) ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); return data; } -void UnsignedLong::compose(ext::deque<sax::Token>& out, unsigned long primitive) { - out.emplace_back(UnsignedLong::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - out.emplace_back(ext::to_string(primitive), sax::Token::TokenType::CHARACTER); - out.emplace_back(UnsignedLong::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +bool xmlApi < unsigned long >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -void UnsignedLong::compose(ext::deque<sax::Token>& out, const UnsignedLong & primitive) { - compose ( out, primitive.getData ( ) ); -} +const std::string & xmlApi < unsigned long >::xmlTagName ( ) { + static std::string xmlTagName = "UnsignedLong"; -PrimitiveBase * UnsignedLong::inc() && { - m_data++; - return NULL; + return xmlTagName; } -} /* namespace primitive */ - -namespace alib { +void xmlApi < unsigned long >::compose ( ext::deque < sax::Token > & output, unsigned long data ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + output.emplace_back ( ext::to_string ( data ), sax::Token::TokenType::CHARACTER ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} -unsigned long xmlApi<unsigned long>::parse(ext::deque<sax::Token>::iterator& input) { - return primitive::UnsignedLong::parseRaw(input); +primitive::UnsignedLong xmlApi < primitive::UnsignedLong >::parse ( ext::deque < sax::Token >::iterator & input ) { + return primitive::UnsignedLong ( xmlApi < unsigned long >::parse ( input ) ); } -bool xmlApi<unsigned long>::first(const ext::deque<sax::Token>::const_iterator& input) { - return sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( )); +bool xmlApi < primitive::UnsignedLong >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -std::string xmlApi<unsigned long>::xmlTagName() { - return primitive::UnsignedLong::getXmlTagName(); +const std::string & xmlApi < primitive::UnsignedLong >::xmlTagName ( ) { + return xmlApi < unsigned long >::xmlTagName ( ); } -void xmlApi<unsigned long>::compose(ext::deque<sax::Token>& output, unsigned long data) { - primitive::UnsignedLong::compose(output, data); +void xmlApi < primitive::UnsignedLong >::compose ( ext::deque < sax::Token > & output, const primitive::UnsignedLong & data ) { + xmlApi < unsigned long >::compose ( output, data.getData ( ) ); } auto unsignedLongType = registration::TypeRegister < primitive::Primitive, primitive::UnsignedLong > (); diff --git a/alib2common/src/primitive/UnsignedLong.h b/alib2common/src/primitive/UnsignedLong.h index 78636656913ecf64cb01e8d04d13136eefd254b8..20e47aefe27bda28383cce93d148f477447a3cca 100644 --- a/alib2common/src/primitive/UnsignedLong.h +++ b/alib2common/src/primitive/UnsignedLong.h @@ -55,18 +55,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "UnsignedLong"; - - return xmlTagName; - } - - static UnsignedLong parse ( ext::deque < sax::Token >::iterator & input ); - static unsigned long parseRaw ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, unsigned long primitive ); - static void compose ( ext::deque < sax::Token > & out, const UnsignedLong & primitive ); - virtual PrimitiveBase * inc ( ) &&; }; @@ -78,10 +66,18 @@ template < > struct xmlApi < unsigned long > { static unsigned long parse ( ext::deque < sax::Token >::iterator & input ); static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); + static const std::string & xmlTagName ( ); static void compose ( ext::deque < sax::Token > & output, unsigned long data ); }; +template < > +struct xmlApi < primitive::UnsignedLong > { + static primitive::UnsignedLong parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const primitive::UnsignedLong & data ); +}; + } /* namespace alib */ #endif /* PRIMITIVE_UNSIGNED_LONG_H_ */ diff --git a/alib2data/src/alphabet/SymbolBase.h b/alib2data/src/alphabet/SymbolBase.h index 031a52ac77c148d130903f3bf69cdd55a93120d6..20b0d3b415b7297d973641b20124e289b7f1d253 100644 --- a/alib2data/src/alphabet/SymbolBase.h +++ b/alib2data/src/alphabet/SymbolBase.h @@ -10,6 +10,8 @@ #include <object/ObjectBase.h> +#include <core/xmlApi.hpp> + namespace alphabet { /** @@ -25,4 +27,28 @@ public: } /* namespace alphabet */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < alphabet::SymbolBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* SYMBOL_BASE_H_ */ diff --git a/alib2data/src/automaton/AutomatonBase.h b/alib2data/src/automaton/AutomatonBase.h index ed17dc3f051bb0ca0854f15f56d578725bb97c1c..42545da988b92defb7136ca99997e273774de891 100644 --- a/alib2data/src/automaton/AutomatonBase.h +++ b/alib2data/src/automaton/AutomatonBase.h @@ -10,6 +10,8 @@ #include <object/ObjectBase.h> +#include <core/xmlApi.hpp> + namespace automaton { /** @@ -23,5 +25,29 @@ public: } /* namespace automaton */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < automaton::AutomatonBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* AUTOMATON_BASE_H_ */ diff --git a/alib2data/src/grammar/GrammarBase.h b/alib2data/src/grammar/GrammarBase.h index e1a920950547a75c6bca6d57765ea1b98860adff..94f000d1bbb7651a86cae33766f41a3beebcfe3b 100644 --- a/alib2data/src/grammar/GrammarBase.h +++ b/alib2data/src/grammar/GrammarBase.h @@ -10,6 +10,8 @@ #include <object/ObjectBase.h> +#include <core/xmlApi.hpp> + namespace grammar { /** @@ -30,4 +32,28 @@ public: } /* namespace grammar */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < grammar::GrammarBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* GRAMMAR_BASE_H_ */ diff --git a/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h b/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h index 122d3fa08f371b77f43f529cd1d05b493320649c..65356ef1d3d8df6ab59ddf6ee625b7641ae2d965 100644 --- a/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h +++ b/alib2data/src/indexes/arbology/CompressedBitParallelTreeIndex.h @@ -115,16 +115,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName ( ) { - static std::string xmlTagName = "CompressedBitParallelTreeIndex"; - - return xmlTagName; - } - - static CompressedBitParallelTreeIndex parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const CompressedBitParallelTreeIndex & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef CompressedBitParallelTreeIndex < > normalized_type; @@ -217,28 +207,6 @@ CompressedBitParallelTreeIndex < SymbolType, RankType >::operator std::string ( return ss.str ( ); } -template < class SymbolType, class RankType > -CompressedBitParallelTreeIndex < SymbolType, RankType > CompressedBitParallelTreeIndex < SymbolType, RankType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, CompressedBitParallelTreeIndex::getXmlTagName ( ) ); - ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet = alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); - ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > data = alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::parse ( input ); - ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); - - CompressedBitParallelTreeIndex < SymbolType, RankType > res ( std::move ( alphabet ), std::move ( data ), std::move ( jumps ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, CompressedBitParallelTreeIndex::getXmlTagName ( ) ); - return res; -} - -template < class SymbolType, class RankType > -void CompressedBitParallelTreeIndex < SymbolType, RankType >::compose ( ext::deque < sax::Token > & out, const CompressedBitParallelTreeIndex & index ) { - out.emplace_back ( CompressedBitParallelTreeIndex::getXmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::compose ( out, index.getData ( ) ); - alib::xmlApi < ext::vector < int > >::compose ( out, index.getJumps ( ) ); - out.emplace_back ( CompressedBitParallelTreeIndex::getXmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType, class RankType > alib::ObjectBase * CompressedBitParallelTreeIndex < SymbolType, RankType >::inc ( ) && { return new alib::UniqueObject ( alib::Object ( std::move ( * this ) ), primitive::Integer ( 0 ) ); @@ -281,6 +249,48 @@ struct normalize < indexes::arbology::CompressedBitParallelTreeIndex < SymbolTyp } }; +template < class SymbolType, class RankType > +struct xmlApi < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > > { + static indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > & data ); +}; + +template < class SymbolType, class RankType > +indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > xmlApi < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet = alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); + ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > data = alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::parse ( input ); + ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); + + indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > res ( std::move ( alphabet ), std::move ( data ), std::move ( jumps ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType, class RankType > +bool xmlApi < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType, class RankType > +const std::string & xmlApi < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > >::xmlTagName ( ) { + static std::string xmlTagName = "CompressedBitParallelTreeIndex"; + + return xmlTagName; +} + +template < class SymbolType, class RankType > +void xmlApi < indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > >::compose ( ext::deque < sax::Token > & output, const indexes::arbology::CompressedBitParallelTreeIndex < SymbolType, RankType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::compose ( output, index.getData ( ) ); + alib::xmlApi < ext::vector < int > >::compose ( output, index.getJumps ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* ARBOLOGY_COMPRESSED_BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/arbology/FullAndLinearIndex.h b/alib2data/src/indexes/arbology/FullAndLinearIndex.h index 3e8b4eea4029740c1d60b1fb164088fdd1911b5e..775af9dbe235be405d4a8d4bf3b75d67289c469f 100644 --- a/alib2data/src/indexes/arbology/FullAndLinearIndex.h +++ b/alib2data/src/indexes/arbology/FullAndLinearIndex.h @@ -111,16 +111,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName ( ) { - static std::string xmlTagName = "FullAndLinearIndex"; - - return xmlTagName; - } - - static FullAndLinearIndex parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const FullAndLinearIndex & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef FullAndLinearIndex < > normalized_type; @@ -205,26 +195,6 @@ FullAndLinearIndex < SymbolType, RankType >::operator std::string ( ) const { return ss.str ( ); } -template < class SymbolType, class RankType > -FullAndLinearIndex < SymbolType, RankType > FullAndLinearIndex < SymbolType, RankType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, FullAndLinearIndex::getXmlTagName ( ) ); - indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > stringIndex = alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); - ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); - - FullAndLinearIndex < SymbolType, RankType > res ( std::move ( stringIndex ), std::move ( jumps ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, FullAndLinearIndex::getXmlTagName ( ) ); - return res; -} - -template < class SymbolType, class RankType > -void FullAndLinearIndex < SymbolType, RankType >::compose ( ext::deque < sax::Token > & out, const FullAndLinearIndex & index ) { - out.emplace_back ( FullAndLinearIndex::getXmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::compose ( out, index.getStringIndex ( ) ); - alib::xmlApi < ext::vector < int > >::compose ( out, index.getJumps ( ) ); - out.emplace_back ( FullAndLinearIndex::getXmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType, class RankType > alib::ObjectBase * FullAndLinearIndex < SymbolType, RankType >::inc ( ) && { return new alib::UniqueObject ( alib::Object ( std::move ( * this ) ), primitive::Integer ( 0 ) ); @@ -245,6 +215,46 @@ struct normalize < indexes::arbology::FullAndLinearIndex < SymbolType, RankType } }; +template < class SymbolType, class RankType > +struct xmlApi < indexes::arbology::FullAndLinearIndex < SymbolType, RankType > > { + static indexes::arbology::FullAndLinearIndex < SymbolType, RankType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::arbology::FullAndLinearIndex < SymbolType, RankType > & data ); +}; + +template < class SymbolType, class RankType > +indexes::arbology::FullAndLinearIndex < SymbolType, RankType > xmlApi < indexes::arbology::FullAndLinearIndex < SymbolType, RankType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > stringIndex = alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); + ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); + + indexes::arbology::FullAndLinearIndex < SymbolType, RankType > res ( std::move ( stringIndex ), std::move ( jumps ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType, class RankType > +bool xmlApi < indexes::arbology::FullAndLinearIndex < SymbolType, RankType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType, class RankType > +const std::string & xmlApi < indexes::arbology::FullAndLinearIndex < SymbolType, RankType > >::xmlTagName ( ) { + static std::string xmlTagName = "FullAndLinearIndex"; + + return xmlTagName; +} + +template < class SymbolType, class RankType > +void xmlApi < indexes::arbology::FullAndLinearIndex < SymbolType, RankType > >::compose ( ext::deque < sax::Token > & output, const indexes::arbology::FullAndLinearIndex < SymbolType, RankType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::compose ( output, index.getStringIndex ( ) ); + alib::xmlApi < ext::vector < int > >::compose ( output, index.getJumps ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* ARBOLOGY_FULL_AND_LINEAR_INDEX_H_ */ diff --git a/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h b/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h index fcc4472b835b3f96d0aad58fe0d18ddc04dafce0..9739f2e1c3967ea85f681556b3ab4f1c88d3147a 100644 --- a/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h +++ b/alib2data/src/indexes/arbology/NonlinearCompressedBitParallelTreeIndex.h @@ -119,16 +119,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName ( ) { - static std::string xmlTagName = "NonlinearCompressedBitParallelTreeIndex"; - - return xmlTagName; - } - - static NonlinearCompressedBitParallelTreeIndex parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const NonlinearCompressedBitParallelTreeIndex & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef NonlinearCompressedBitParallelTreeIndex < > normalized_type; @@ -231,30 +221,6 @@ NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType >::operator std:: return ss.str ( ); } -template < class SymbolType, class RankType > -NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, NonlinearCompressedBitParallelTreeIndex::getXmlTagName ( ) ); - ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet = alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); - ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > data = alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::parse ( input ); - ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); - ext::vector < unsigned > repeats = alib::xmlApi < ext::vector < unsigned > >::parse ( input ); - - NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > res ( std::move ( alphabet ), std::move ( data ), std::move ( jumps ), std::move ( repeats ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, NonlinearCompressedBitParallelTreeIndex::getXmlTagName ( ) ); - return res; -} - -template < class SymbolType, class RankType > -void NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType >::compose ( ext::deque < sax::Token > & out, const NonlinearCompressedBitParallelTreeIndex & index ) { - out.emplace_back ( NonlinearCompressedBitParallelTreeIndex::getXmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::compose ( out, index.getData ( ) ); - alib::xmlApi < ext::vector < int > >::compose ( out, index.getJumps ( ) ); - alib::xmlApi < ext::vector < unsigned > >::compose ( out, index.getRepeats ( ) ); - out.emplace_back ( NonlinearCompressedBitParallelTreeIndex::getXmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType, class RankType > alib::ObjectBase * NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType >::inc ( ) && { return new alib::UniqueObject ( alib::Object ( std::move ( * this ) ), primitive::Integer ( 0 ) ); @@ -297,6 +263,50 @@ struct normalize < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < } }; +template < class SymbolType, class RankType > +struct xmlApi < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > > { + static indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > & data ); +}; + +template < class SymbolType, class RankType > +indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > xmlApi < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < common::ranked_symbol < SymbolType, RankType > > alphabet = alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); + ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > data = alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::parse ( input ); + ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); + ext::vector < unsigned > repeats = alib::xmlApi < ext::vector < unsigned > >::parse ( input ); + + indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > res ( std::move ( alphabet ), std::move ( data ), std::move ( jumps ), std::move ( repeats ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType, class RankType > +bool xmlApi < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType, class RankType > +const std::string & xmlApi < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > >::xmlTagName ( ) { + static std::string xmlTagName = "NonlinearCompressedBitParallelTreeIndex"; + + return xmlTagName; +} + +template < class SymbolType, class RankType > +void xmlApi < indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > >::compose ( ext::deque < sax::Token > & output, const indexes::arbology::NonlinearCompressedBitParallelTreeIndex < SymbolType, RankType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < common::ranked_symbol < SymbolType, RankType > > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::map < common::ranked_symbol < SymbolType, RankType >, common::SparseBoolVector > >::compose ( output, index.getData ( ) ); + alib::xmlApi < ext::vector < int > >::compose ( output, index.getJumps ( ) ); + alib::xmlApi < ext::vector < unsigned > >::compose ( output, index.getRepeats ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* ARBOLOGY_NONLINEAR_COMPRESSED_BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h b/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h index 995b8285cae2649ebb5828bba85ba046ec8f9b3a..cf8d4b9eb17558ebb50a8c56792d4607408143a2 100644 --- a/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h +++ b/alib2data/src/indexes/arbology/NonlinearFullAndLinearIndex.h @@ -119,16 +119,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName ( ) { - static std::string xmlTagName = "NonlinearFullAndLinearIndex"; - - return xmlTagName; - } - - static NonlinearFullAndLinearIndex parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const NonlinearFullAndLinearIndex & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef NonlinearFullAndLinearIndex < > normalized_type; @@ -223,28 +213,6 @@ NonlinearFullAndLinearIndex < SymbolType, RankType >::operator std::string ( ) c return ss.str ( ); } -template < class SymbolType, class RankType > -NonlinearFullAndLinearIndex < SymbolType, RankType > NonlinearFullAndLinearIndex < SymbolType, RankType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, NonlinearFullAndLinearIndex::getXmlTagName ( ) ); - indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > stringIndex = alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); - ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); - ext::vector < unsigned > repeats = alib::xmlApi < ext::vector < unsigned > >::parse ( input ); - - NonlinearFullAndLinearIndex < SymbolType, RankType > res ( std::move ( stringIndex ), std::move ( jumps ), std::move ( repeats ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, NonlinearFullAndLinearIndex::getXmlTagName ( ) ); - return res; -} - -template < class SymbolType, class RankType > -void NonlinearFullAndLinearIndex < SymbolType, RankType >::compose ( ext::deque < sax::Token > & out, const NonlinearFullAndLinearIndex & index ) { - out.emplace_back ( NonlinearFullAndLinearIndex::getXmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::compose ( out, index.getStringIndex ( ) ); - alib::xmlApi < ext::vector < int > >::compose ( out, index.getJumps ( ) ); - alib::xmlApi < ext::vector < unsigned > >::compose ( out, index.getRepeats ( ) ); - out.emplace_back ( NonlinearFullAndLinearIndex::getXmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType, class RankType > alib::ObjectBase * NonlinearFullAndLinearIndex < SymbolType, RankType >::inc ( ) && { return new alib::UniqueObject ( alib::Object ( std::move ( * this ) ), primitive::Integer ( 0 ) ); @@ -265,6 +233,48 @@ struct normalize < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, } }; +template < class SymbolType, class RankType > +struct xmlApi < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > > { + static indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > & data ); +}; + +template < class SymbolType, class RankType > +indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > xmlApi < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > stringIndex = alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::parse ( input ); + ext::vector < int > jumps = alib::xmlApi < ext::vector < int > >::parse ( input ); + ext::vector < unsigned > repeats = alib::xmlApi < ext::vector < unsigned > >::parse ( input ); + + indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > res ( std::move ( stringIndex ), std::move ( jumps ), std::move ( repeats ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType, class RankType > +bool xmlApi < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType, class RankType > +const std::string & xmlApi < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > >::xmlTagName ( ) { + static std::string xmlTagName = "NonlinearFullAndLinearIndex"; + + return xmlTagName; +} + +template < class SymbolType, class RankType > +void xmlApi < indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > >::compose ( ext::deque < sax::Token > & output, const indexes::arbology::NonlinearFullAndLinearIndex < SymbolType, RankType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < indexes::stringology::PositionHeap < common::ranked_symbol < SymbolType, RankType > > >::compose ( output, index.getStringIndex ( ) ); + alib::xmlApi < ext::vector < int > >::compose ( output, index.getJumps ( ) ); + alib::xmlApi < ext::vector < unsigned > >::compose ( output, index.getRepeats ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* ARBOLOGY_NONLINEAR_FULL_AND_LINEAR_INDEX_H_ */ diff --git a/alib2data/src/indexes/stringology/BNDMMatcher.h b/alib2data/src/indexes/stringology/BNDMMatcher.h index f79b0766740589dc195a7cc1924ea30713949327..ad27092f2e7cdd0d40b200a2e406684c84edc794 100644 --- a/alib2data/src/indexes/stringology/BNDMMatcher.h +++ b/alib2data/src/indexes/stringology/BNDMMatcher.h @@ -111,16 +111,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "BNDMMatcher"; - - return xmlTagName; - } - - static BNDMMatcher parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const BNDMMatcher & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef BNDMMatcher < > normalized_type; @@ -195,27 +185,6 @@ BNDMMatcher < SymbolType, BitmaskBitCount >::operator std::string ( ) const { return ss.str ( ); } -template < class SymbolType, size_t BitmaskBitCount > -BNDMMatcher < SymbolType, BitmaskBitCount > BNDMMatcher < SymbolType, BitmaskBitCount >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, BNDMMatcher::getXmlTagName() ); - ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); - ext::map < SymbolType, ext::bitset < BitmaskBitCount > > data = alib::xmlApi < ext::map < SymbolType, ext::bitset < BitmaskBitCount > > >::parse ( input ); - ext::vector < SymbolType > string = alib::xmlApi < ext::vector < SymbolType > >::parse ( input ); - BNDMMatcher < SymbolType, BitmaskBitCount > res ( std::move ( alphabet ), std::move ( data ), std::move ( string ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, BNDMMatcher::getXmlTagName() ); - return res; -} - -template < class SymbolType, size_t BitmaskBitCount > -void BNDMMatcher < SymbolType, BitmaskBitCount >::compose ( ext::deque < sax::Token > & out, const BNDMMatcher & index ) { - out.emplace_back ( BNDMMatcher::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < SymbolType > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::map < SymbolType, ext::bitset < BitmaskBitCount > > >::compose ( out, index.getData ( ) ); - alib::xmlApi < ext::vector < SymbolType > >::compose ( out, index.getString ( ) ); - out.emplace_back ( BNDMMatcher::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType, size_t BitmaskBitCount > alib::ObjectBase* BNDMMatcher < SymbolType, BitmaskBitCount >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); @@ -265,6 +234,47 @@ struct normalize < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCou } }; +template < class SymbolType, size_t BitmaskBitCount > +struct xmlApi < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > > { + static indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > & data ); +}; + +template < class SymbolType, size_t BitmaskBitCount > +indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > xmlApi < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); + ext::map < SymbolType, ext::bitset < BitmaskBitCount > > data = alib::xmlApi < ext::map < SymbolType, ext::bitset < BitmaskBitCount > > >::parse ( input ); + ext::vector < SymbolType > string = alib::xmlApi < ext::vector < SymbolType > >::parse ( input ); + indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > res ( std::move ( alphabet ), std::move ( data ), std::move ( string ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType, size_t BitmaskBitCount > +bool xmlApi < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType, size_t BitmaskBitCount > +const std::string & xmlApi < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > >::xmlTagName ( ) { + static std::string xmlTagName = "BNDMMatcher"; + + return xmlTagName; +} + +template < class SymbolType, size_t BitmaskBitCount > +void xmlApi < indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > >::compose ( ext::deque < sax::Token > & output, const indexes::stringology::BNDMMatcher < SymbolType, BitmaskBitCount > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < SymbolType > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::map < SymbolType, ext::bitset < BitmaskBitCount > > >::compose ( output, index.getData ( ) ); + alib::xmlApi < ext::vector < SymbolType > >::compose ( output, index.getString ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* BNDM_MATCHER_H_ */ diff --git a/alib2data/src/indexes/stringology/BitParallelIndex.h b/alib2data/src/indexes/stringology/BitParallelIndex.h index 086d4921dfa8a8d145855d9d1e0a58716a2c4b9b..252b7000ad3bd11765c9700dceb8f83032d8e8ce 100644 --- a/alib2data/src/indexes/stringology/BitParallelIndex.h +++ b/alib2data/src/indexes/stringology/BitParallelIndex.h @@ -106,16 +106,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "BitParallelIndex"; - - return xmlTagName; - } - - static BitParallelIndex parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const BitParallelIndex & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef BitParallelIndex < > normalized_type; @@ -197,25 +187,6 @@ BitParallelIndex < SymbolType >::operator std::string ( ) const { return ss.str ( ); } -template < class SymbolType > -BitParallelIndex < SymbolType > BitParallelIndex < SymbolType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, BitParallelIndex::getXmlTagName() ); - ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); - ext::map < SymbolType, ext::vector < bool > > data = alib::xmlApi < ext::map < SymbolType, ext::vector < bool > > >::parse ( input ); - BitParallelIndex < SymbolType > res ( std::move ( alphabet ), std::move ( data ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, BitParallelIndex::getXmlTagName() ); - return res; -} - -template < class SymbolType > -void BitParallelIndex < SymbolType >::compose ( ext::deque < sax::Token > & out, const BitParallelIndex & index ) { - out.emplace_back ( BitParallelIndex::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < SymbolType > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::map < SymbolType, ext::vector < bool > > >::compose ( out, index.getData ( ) ); - out.emplace_back ( BitParallelIndex::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType > alib::ObjectBase* BitParallelIndex < SymbolType >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); @@ -256,6 +227,45 @@ struct normalize < indexes::stringology::BitParallelIndex < SymbolType >, typena } }; +template < class SymbolType > +struct xmlApi < indexes::stringology::BitParallelIndex < SymbolType > > { + static indexes::stringology::BitParallelIndex < SymbolType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::stringology::BitParallelIndex < SymbolType > & data ); +}; + +template < class SymbolType > +indexes::stringology::BitParallelIndex < SymbolType > xmlApi < indexes::stringology::BitParallelIndex < SymbolType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); + ext::map < SymbolType, ext::vector < bool > > data = alib::xmlApi < ext::map < SymbolType, ext::vector < bool > > >::parse ( input ); + indexes::stringology::BitParallelIndex < SymbolType > res ( std::move ( alphabet ), std::move ( data ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType > +bool xmlApi < indexes::stringology::BitParallelIndex < SymbolType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType > +const std::string & xmlApi < indexes::stringology::BitParallelIndex < SymbolType > >::xmlTagName ( ) { + static std::string xmlTagName = "BitParallelIndex"; + + return xmlTagName; +} + +template < class SymbolType > +void xmlApi < indexes::stringology::BitParallelIndex < SymbolType > >::compose ( ext::deque < sax::Token > & output, const indexes::stringology::BitParallelIndex < SymbolType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < SymbolType > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::map < SymbolType, ext::vector < bool > > >::compose ( output, index.getData ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h b/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h index 87898056bf2043a3a3c57ca37805fdd794cfe92e..0d5941a150c1642efd487fb6a32a694ce276d5f2 100644 --- a/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h +++ b/alib2data/src/indexes/stringology/CompressedBitParallelIndex.h @@ -106,16 +106,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "CompressedBitParallelIndex"; - - return xmlTagName; - } - - static CompressedBitParallelIndex parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const CompressedBitParallelIndex & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef CompressedBitParallelIndex < > normalized_type; @@ -197,25 +187,6 @@ CompressedBitParallelIndex < SymbolType >::operator std::string ( ) const { return ss.str ( ); } -template < class SymbolType > -CompressedBitParallelIndex < SymbolType > CompressedBitParallelIndex < SymbolType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, CompressedBitParallelIndex::getXmlTagName() ); - ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); - ext::map < SymbolType, common::SparseBoolVector > data = alib::xmlApi < ext::map < SymbolType, common::SparseBoolVector > >::parse ( input ); - CompressedBitParallelIndex < SymbolType > res ( std::move ( alphabet ), std::move ( data ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, CompressedBitParallelIndex::getXmlTagName() ); - return res; -} - -template < class SymbolType > -void CompressedBitParallelIndex < SymbolType >::compose ( ext::deque < sax::Token > & out, const CompressedBitParallelIndex & index ) { - out.emplace_back ( CompressedBitParallelIndex::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < SymbolType > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::map < SymbolType, common::SparseBoolVector > >::compose ( out, index.getData ( ) ); - out.emplace_back ( CompressedBitParallelIndex::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType > alib::ObjectBase* CompressedBitParallelIndex < SymbolType >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); @@ -256,6 +227,45 @@ struct normalize < indexes::stringology::CompressedBitParallelIndex < SymbolType } }; +template < class SymbolType > +struct xmlApi < indexes::stringology::CompressedBitParallelIndex < SymbolType > > { + static indexes::stringology::CompressedBitParallelIndex < SymbolType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::stringology::CompressedBitParallelIndex < SymbolType > & data ); +}; + +template < class SymbolType > +indexes::stringology::CompressedBitParallelIndex < SymbolType > xmlApi < indexes::stringology::CompressedBitParallelIndex < SymbolType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); + ext::map < SymbolType, common::SparseBoolVector > data = alib::xmlApi < ext::map < SymbolType, common::SparseBoolVector > >::parse ( input ); + indexes::stringology::CompressedBitParallelIndex < SymbolType > res ( std::move ( alphabet ), std::move ( data ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType > +bool xmlApi < indexes::stringology::CompressedBitParallelIndex < SymbolType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType > +const std::string & xmlApi < indexes::stringology::CompressedBitParallelIndex < SymbolType > >::xmlTagName ( ) { + static std::string xmlTagName = "CompressedBitParallelIndex"; + + return xmlTagName; +} + +template < class SymbolType > +void xmlApi < indexes::stringology::CompressedBitParallelIndex < SymbolType > >::compose ( ext::deque < sax::Token > & output, const indexes::stringology::CompressedBitParallelIndex < SymbolType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < SymbolType > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::map < SymbolType, common::SparseBoolVector > >::compose ( output, index.getData ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* COMPRESSED_BIT_PARALLEL_INDEX_H_ */ diff --git a/alib2data/src/indexes/stringology/PositionHeap.h b/alib2data/src/indexes/stringology/PositionHeap.h index 40aeef6ff73303c283b9072b1c5ab94449f3b58d..0b46267acaeeb34e6f5591e9b75189065342a2ed 100644 --- a/alib2data/src/indexes/stringology/PositionHeap.h +++ b/alib2data/src/indexes/stringology/PositionHeap.h @@ -118,16 +118,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "PositionHeap"; - - return xmlTagName; - } - - static PositionHeap parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const PositionHeap & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef PositionHeap < > normalized_type; @@ -218,27 +208,6 @@ PositionHeap < SymbolType >::operator std::string ( ) const { return ss.str ( ); } -template < class SymbolType > -PositionHeap < SymbolType > PositionHeap < SymbolType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, PositionHeap::getXmlTagName() ); - ext::set < SymbolType > edgeAlphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); - ext::trie < SymbolType, unsigned > root = alib::xmlApi < ext::trie < SymbolType, unsigned > >::parse ( input ); - ext::vector < SymbolType > string = alib::xmlApi < ext::vector < SymbolType > >::parse ( input ); - PositionHeap < SymbolType > trie ( std::move ( edgeAlphabet ), std::move ( root ), std::move ( string ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, PositionHeap::getXmlTagName() ); - return trie; -} - -template < class SymbolType > -void PositionHeap < SymbolType >::compose ( ext::deque < sax::Token > & out, const PositionHeap & index ) { - out.emplace_back ( PositionHeap::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < SymbolType > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::trie < SymbolType, unsigned > >::compose ( out, index.getRoot ( ) ); - alib::xmlApi < ext::vector < SymbolType > >::compose ( out, index.getString ( ) ); - out.emplace_back ( PositionHeap::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType > alib::ObjectBase* PositionHeap < SymbolType >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); @@ -304,6 +273,47 @@ struct normalize < indexes::stringology::PositionHeap < SymbolType >, typename s } }; +template < class SymbolType > +struct xmlApi < indexes::stringology::PositionHeap < SymbolType > > { + static indexes::stringology::PositionHeap < SymbolType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::stringology::PositionHeap < SymbolType > & data ); +}; + +template < class SymbolType > +indexes::stringology::PositionHeap < SymbolType > xmlApi < indexes::stringology::PositionHeap < SymbolType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < SymbolType > edgeAlphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); + ext::trie < SymbolType, unsigned > root = alib::xmlApi < ext::trie < SymbolType, unsigned > >::parse ( input ); + ext::vector < SymbolType > string = alib::xmlApi < ext::vector < SymbolType > >::parse ( input ); + indexes::stringology::PositionHeap < SymbolType > res ( std::move ( edgeAlphabet ), std::move ( root ), std::move ( string ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType > +bool xmlApi < indexes::stringology::PositionHeap < SymbolType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType > +const std::string & xmlApi < indexes::stringology::PositionHeap < SymbolType > >::xmlTagName ( ) { + static std::string xmlTagName = "PositionHeap"; + + return xmlTagName; +} + +template < class SymbolType > +void xmlApi < indexes::stringology::PositionHeap < SymbolType > >::compose ( ext::deque < sax::Token > & output, const indexes::stringology::PositionHeap < SymbolType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < SymbolType > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::trie < SymbolType, unsigned > >::compose ( output, index.getRoot ( ) ); + alib::xmlApi < ext::vector < SymbolType > >::compose ( output, index.getString ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* POSITION_HEAP_H_ */ diff --git a/alib2data/src/indexes/stringology/SuffixArray.h b/alib2data/src/indexes/stringology/SuffixArray.h index 838a0d0bba59f43b411967e81833ad18620f3c26..ca7a27e2c00d836741dd1a3ac15a63847ba6cc2e 100644 --- a/alib2data/src/indexes/stringology/SuffixArray.h +++ b/alib2data/src/indexes/stringology/SuffixArray.h @@ -112,16 +112,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "SuffixArray"; - - return xmlTagName; - } - - static SuffixArray parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const SuffixArray & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef SuffixArray < > normalized_type; @@ -197,27 +187,6 @@ SuffixArray < SymbolType >::operator std::string ( ) const { return ss.str ( ); } -template < class SymbolType > -SuffixArray < SymbolType > SuffixArray < SymbolType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, SuffixArray::getXmlTagName() ); - ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); - ext::vector < unsigned > data = alib::xmlApi < ext::vector < unsigned > >::parse ( input ); - ext::vector < SymbolType > string = alib::xmlApi < ext::vector < SymbolType > >::parse ( input ); - SuffixArray < SymbolType > res ( std::move ( alphabet ), std::move ( data ), std::move ( string ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, SuffixArray::getXmlTagName() ); - return res; -} - -template < class SymbolType > -void SuffixArray < SymbolType >::compose ( ext::deque < sax::Token > & out, const SuffixArray & index ) { - out.emplace_back ( SuffixArray::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < SymbolType > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::vector < unsigned > >::compose ( out, index.getData ( ) ); - alib::xmlApi < ext::vector < SymbolType > >::compose ( out, index.getString ( ) ); - out.emplace_back ( SuffixArray::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType > alib::ObjectBase* SuffixArray < SymbolType >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); @@ -255,6 +224,47 @@ struct normalize < indexes::stringology::SuffixArray < SymbolType >, typename st } }; +template < class SymbolType > +struct xmlApi < indexes::stringology::SuffixArray < SymbolType > > { + static indexes::stringology::SuffixArray < SymbolType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::stringology::SuffixArray < SymbolType > & data ); +}; + +template < class SymbolType > +indexes::stringology::SuffixArray < SymbolType > xmlApi < indexes::stringology::SuffixArray < SymbolType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < SymbolType > alphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); + ext::vector < unsigned > data = alib::xmlApi < ext::vector < unsigned > >::parse ( input ); + ext::vector < SymbolType > string = alib::xmlApi < ext::vector < SymbolType > >::parse ( input ); + indexes::stringology::SuffixArray < SymbolType > res ( std::move ( alphabet ), std::move ( data ), std::move ( string ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType > +bool xmlApi < indexes::stringology::SuffixArray < SymbolType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType > +const std::string & xmlApi < indexes::stringology::SuffixArray < SymbolType > >::xmlTagName ( ) { + static std::string xmlTagName = "SuffixArray"; + + return xmlTagName; +} + +template < class SymbolType > +void xmlApi < indexes::stringology::SuffixArray < SymbolType > >::compose ( ext::deque < sax::Token > & output, const indexes::stringology::SuffixArray < SymbolType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < SymbolType > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::vector < unsigned > >::compose ( output, index.getData ( ) ); + alib::xmlApi < ext::vector < SymbolType > >::compose ( output, index.getString ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* SUFFIX_ARRAY_H_ */ diff --git a/alib2data/src/indexes/stringology/SuffixTrie.h b/alib2data/src/indexes/stringology/SuffixTrie.h index e5ac85eb3d8cca48cc4ffb84fb3ff09a1764cfc0..be89b75290c83a6709dd82fdc73f5f9e51da2a5f 100644 --- a/alib2data/src/indexes/stringology/SuffixTrie.h +++ b/alib2data/src/indexes/stringology/SuffixTrie.h @@ -116,16 +116,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "SuffixTrie"; - - return xmlTagName; - } - - static SuffixTrie parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const SuffixTrie & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef SuffixTrie < > normalized_type; @@ -209,25 +199,6 @@ SuffixTrie < SymbolType >::operator std::string ( ) const { return ss.str ( ); } -template < class SymbolType > -SuffixTrie < SymbolType > SuffixTrie < SymbolType >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, SuffixTrie::getXmlTagName() ); - ext::set < SymbolType > edgeAlphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); - ext::trie < SymbolType, ext::variant < void, unsigned > > root = alib::xmlApi < ext::trie < SymbolType, ext::variant < void, unsigned > > >::parse ( input ); - SuffixTrie < SymbolType > trie ( std::move ( edgeAlphabet ), std::move ( root ) ); - - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, SuffixTrie::getXmlTagName() ); - return trie; -} - -template < class SymbolType > -void SuffixTrie < SymbolType >::compose ( ext::deque < sax::Token > & out, const SuffixTrie & index ) { - out.emplace_back ( SuffixTrie::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - alib::xmlApi < ext::set < SymbolType > >::compose ( out, index.getAlphabet ( ) ); - alib::xmlApi < ext::trie < SymbolType, ext::variant < void, unsigned > > >::compose ( out, index.getRoot ( ) ); - out.emplace_back ( SuffixTrie::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - template < class SymbolType > alib::ObjectBase* SuffixTrie < SymbolType >::inc() && { return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); @@ -273,6 +244,45 @@ struct normalize < indexes::stringology::SuffixTrie < SymbolType >, typename std } }; +template < class SymbolType > +struct xmlApi < indexes::stringology::SuffixTrie < SymbolType > > { + static indexes::stringology::SuffixTrie < SymbolType > parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::stringology::SuffixTrie < SymbolType > & data ); +}; + +template < class SymbolType > +indexes::stringology::SuffixTrie < SymbolType > xmlApi < indexes::stringology::SuffixTrie < SymbolType > >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < SymbolType > edgeAlphabet = alib::xmlApi < ext::set < SymbolType > >::parse ( input ); + ext::trie < SymbolType, ext::variant < void, unsigned > > root = alib::xmlApi < ext::trie < SymbolType, ext::variant < void, unsigned > > >::parse ( input ); + indexes::stringology::SuffixTrie < SymbolType > res ( std::move ( edgeAlphabet ), std::move ( root ) ); + + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; +} + +template < class SymbolType > +bool xmlApi < indexes::stringology::SuffixTrie < SymbolType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); +} + +template < class SymbolType > +const std::string & xmlApi < indexes::stringology::SuffixTrie < SymbolType > >::xmlTagName ( ) { + static std::string xmlTagName = "SuffixTrie"; + + return xmlTagName; +} + +template < class SymbolType > +void xmlApi < indexes::stringology::SuffixTrie < SymbolType > >::compose ( ext::deque < sax::Token > & output, const indexes::stringology::SuffixTrie < SymbolType > & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + alib::xmlApi < ext::set < SymbolType > >::compose ( output, index.getAlphabet ( ) ); + alib::xmlApi < ext::trie < SymbolType, ext::variant < void, unsigned > > >::compose ( output, index.getRoot ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} + } /* namespace alib */ #endif /* SUFFIX_TRIE_H_ */ diff --git a/alib2data/src/label/LabelBase.h b/alib2data/src/label/LabelBase.h index 9acd07d6b74f3504ee168360d0f1abe91511ee6a..17c1b0c2c63c9c72fe87c0ed9599ad75e9e8c0dd 100644 --- a/alib2data/src/label/LabelBase.h +++ b/alib2data/src/label/LabelBase.h @@ -10,6 +10,8 @@ #include <object/ObjectBase.h> +#include <core/xmlApi.hpp> + namespace label { /** @@ -25,4 +27,28 @@ public: } /* namespace label */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < label::LabelBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* LABEL_BASE_H_ */ diff --git a/alib2data/src/regexp/RegExpBase.h b/alib2data/src/regexp/RegExpBase.h index 3c23d3ce95824eb18e21d2a4af6e7f1accd5504c..9164fcfa7875545456a1cc421e4b44015113476b 100644 --- a/alib2data/src/regexp/RegExpBase.h +++ b/alib2data/src/regexp/RegExpBase.h @@ -10,6 +10,8 @@ #include <object/ObjectBase.h> +#include <core/xmlApi.hpp> + namespace regexp { /** @@ -23,4 +25,28 @@ public: } /* namespace regexp */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < regexp::RegExpBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* REG_EXP_BASE_H_ */ diff --git a/alib2data/src/rte/RTEBase.h b/alib2data/src/rte/RTEBase.h index 2ee291af36a11276f01bc594b1bf867e0b43e62d..7a980d698af775ac9af1898d5d9b8a990679a7df 100644 --- a/alib2data/src/rte/RTEBase.h +++ b/alib2data/src/rte/RTEBase.h @@ -9,8 +9,8 @@ #define RTE_BASE_H_ #include <object/ObjectBase.h> -#include <set> -#include <common/ranked_symbol.hpp> + +#include <core/xmlApi.hpp> namespace rte { @@ -22,4 +22,28 @@ public: } /* namespace rte */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < rte::RTEBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* RTE_BASE_H_ */ diff --git a/alib2data/src/string/StringBase.h b/alib2data/src/string/StringBase.h index fe7c47a54f84f9d7a90b3975253a9d608bbe24e6..5d6098657b6908f550c6f3a475b13033ef74d620 100644 --- a/alib2data/src/string/StringBase.h +++ b/alib2data/src/string/StringBase.h @@ -9,8 +9,8 @@ #define STRING_BASE_H_ #include <object/ObjectBase.h> -#include <set> -#include "../alphabet/Symbol.h" + +#include <core/xmlApi.hpp> namespace string { @@ -25,4 +25,28 @@ public: } /* namespace string */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < string::StringBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* STRING_BASE_H_ */ diff --git a/alib2data/src/tree/TreeBase.h b/alib2data/src/tree/TreeBase.h index caa1a7624ea2a3f1d4edfb5da1d8978f74f11a52..d95863cfddd530f46e8b072715b3bcd733115b7f 100644 --- a/alib2data/src/tree/TreeBase.h +++ b/alib2data/src/tree/TreeBase.h @@ -10,6 +10,8 @@ #include <object/ObjectBase.h> +#include <core/xmlApi.hpp> + namespace tree { /** @@ -23,4 +25,28 @@ public: } /* namespace tree */ +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < tree::TreeBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif /* TREE_BASE_H_ */ diff --git a/alib2data_experimental/src/graph/GraphBase.h b/alib2data_experimental/src/graph/GraphBase.h index 2b9a5cf74b90b6c79e007ae79f6d2c42af35c176..d2da665eb42a560c4037fb706c75fd928442a843 100644 --- a/alib2data_experimental/src/graph/GraphBase.h +++ b/alib2data_experimental/src/graph/GraphBase.h @@ -14,6 +14,8 @@ #include "GraphTypes.h" #include "common/Macros.h" +#include <core/xmlApi.hpp> + /* zvazit zmeny: * - ohodnoceny/neohodnoceny graf jako trida * aby bylo mozne u grafu vstupujiciho do algoritmu overit existujici vahy behem kompilace a nehazet vyjimky @@ -45,4 +47,28 @@ class GraphBase : public alib::ObjectBase { } // namespace graph +namespace alib { + +template < typename Type > +struct xmlApi < Type, typename std::enable_if < std::is_base_of < graph::GraphBase, Type >::value >::type > { + static Type parse ( ext::deque < sax::Token >::iterator & input ) { + return Type::parse ( input ); + } + + static bool first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName() ); + } + + static std::string xmlTagName ( ) { + return Type::getXmlTagName(); + } + + static void compose ( ext::deque < sax::Token > & output, const Type & data ) { + Type::compose ( output, data ); + } + +}; + +} /* namespace alib */ + #endif // GRAPH_BASE_H_ diff --git a/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.cpp b/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.cpp index 1dc6fd9c5b33b6d7894b6376119b7f2068a164a8..8a9b0fa7cb7a314c342bb0b3995f25f297b7d29d 100644 --- a/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.cpp +++ b/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.cpp @@ -111,33 +111,43 @@ SuffixTrieTerminatingSymbol::operator std::string ( ) const { return ss.str ( ); } -SuffixTrieTerminatingSymbol SuffixTrieTerminatingSymbol::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, SuffixTrieTerminatingSymbol::getXmlTagName() ); - ext::set < DefaultSymbolType > rankedAlphabet = IndexFromXMLParser::parseAlphabet ( input ); +alib::ObjectBase* SuffixTrieTerminatingSymbol::inc() && { + return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); +} + +} /* namespace indexes */ + +namespace alib { + +indexes::SuffixTrieTerminatingSymbol xmlApi < indexes::SuffixTrieTerminatingSymbol >::parse ( ext::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); + ext::set < DefaultSymbolType > rankedAlphabet = indexes::IndexFromXMLParser::parseAlphabet ( input ); DefaultSymbolType terminatingSymbol = alib::xmlApi < DefaultSymbolType >::parse ( input ); - SuffixTrieNodeTerminatingSymbol * root = IndexFromXMLParser::parseSuffixTrieNodeTerminatingSymbol ( input ); - SuffixTrieTerminatingSymbol tree ( std::move ( rankedAlphabet ), terminatingSymbol, std::move ( * root ) ); + indexes::SuffixTrieNodeTerminatingSymbol * root = indexes::IndexFromXMLParser::parseSuffixTrieNodeTerminatingSymbol ( input ); + indexes::SuffixTrieTerminatingSymbol res ( std::move ( rankedAlphabet ), terminatingSymbol, std::move ( * root ) ); delete root; - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, SuffixTrieTerminatingSymbol::getXmlTagName() ); - return tree; + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); + return res; } -void SuffixTrieTerminatingSymbol::compose ( ext::deque < sax::Token > & out, const SuffixTrieTerminatingSymbol & index ) { - out.emplace_back ( SuffixTrieTerminatingSymbol::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - IndexToXMLComposer::composeAlphabet ( out, index.getAlphabet ( ) ); - alib::xmlApi < DefaultSymbolType >::compose ( out, index.getTerminatingSymbol ( ) ); - IndexToXMLComposer::composeNode ( out, * index.m_tree ); - out.emplace_back ( SuffixTrieTerminatingSymbol::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); +bool xmlApi < indexes::SuffixTrieTerminatingSymbol >::first ( const ext::deque < sax::Token >::const_iterator & input ) { + return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); } -alib::ObjectBase* SuffixTrieTerminatingSymbol::inc() && { - return new alib::UniqueObject(alib::Object(std::move(*this)), primitive::Integer(0)); -} +const std::string & xmlApi < indexes::SuffixTrieTerminatingSymbol >::xmlTagName ( ) { + static std::string xmlTagName = "SuffixTrieTerminatingSymbol"; -} /* namespace indexes */ + return xmlTagName; +} -namespace alib { +void xmlApi < indexes::SuffixTrieTerminatingSymbol >::compose ( ext::deque < sax::Token > & output, const indexes::SuffixTrieTerminatingSymbol & index ) { + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); + indexes::IndexToXMLComposer::composeAlphabet ( output, index.getAlphabet ( ) ); + alib::xmlApi < DefaultSymbolType >::compose ( output, index.getTerminatingSymbol ( ) ); + indexes::IndexToXMLComposer::composeNode ( output, index.getRoot ( ) ); + output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); +} auto suffixTreeTerminatingSymbolType = registration::TypeRegister < alib::Object, indexes::SuffixTrieTerminatingSymbol > ( ); diff --git a/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h b/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h index c92990d4bd54e38d2a67d75b32a4ded5d9c3b7b1..78ea11eed75c1a3684313baac984d1ec3b7df21a 100644 --- a/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h +++ b/alib2data_experimental/src/indexes/suffixTrie/SuffixTrieTerminatingSymbol.h @@ -97,16 +97,6 @@ public: virtual explicit operator std::string ( ) const; - static const std::string & getXmlTagName() { - static std::string xmlTagName = "SuffixTrieTerminatingSymbol"; - - return xmlTagName; - } - - static SuffixTrieTerminatingSymbol parse ( ext::deque < sax::Token >::iterator & input ); - - static void compose ( ext::deque < sax::Token > & out, const SuffixTrieTerminatingSymbol & index ); - virtual alib::ObjectBase * inc ( ) &&; typedef SuffixTrieTerminatingSymbol normalized_type; @@ -142,6 +132,14 @@ public: } }; +template < > +struct xmlApi < indexes::SuffixTrieTerminatingSymbol > { + static indexes::SuffixTrieTerminatingSymbol parse ( ext::deque < sax::Token >::iterator & input ); + static bool first ( const ext::deque < sax::Token >::const_iterator & input ); + static const std::string & xmlTagName ( ); + static void compose ( ext::deque < sax::Token > & output, const indexes::SuffixTrieTerminatingSymbol & data ); +}; + } /* namespace alib */ #endif /* SUFFIX_TRIE_TERMINATING_SYMBOL_H_ */