diff --git a/alib2common/src/base/WrapperBase.hpp b/alib2common/src/base/WrapperBase.hpp deleted file mode 100644 index 56046d668a183f2d91242bdbd8d44387acf3a3bb..0000000000000000000000000000000000000000 --- a/alib2common/src/base/WrapperBase.hpp +++ /dev/null @@ -1,266 +0,0 @@ -/* - * WrapperBase.h - * - * Created on: Apr 10, 2013 - * Author: Jan Travnicek - */ - -#ifndef WRAPPER_BASE_H_ -#define WRAPPER_BASE_H_ - -#include <ostream> -#include <alib/memory> - -namespace base { - -/** - * Most common base for every datatype wrapper in algorithms library toolkit. - */ -class WrapperBaseBase { -public: - /** - * Virtual destructor just to have it. - */ - virtual ~WrapperBaseBase ( ) noexcept { } - -}; - -/** - * Middle wrapper base specifies usual operations of all datatypes wrappers in algorithms library toolkit. - * - * \tparam T type that is a base class of the concrete wrapper that inherits from this. - */ -template < typename T > -class WrapperBaseMiddle : public WrapperBaseBase { -protected: - /** - * The wrapped data. - */ - ext::cow_shared_ptr < T > m_data; - -private: - /** - * \brief - * Unifies the shared pointers. For internal use when two pointer eval equal. - */ - void unify ( WrapperBaseMiddle & other ) { - if ( this->m_data.getUseCount ( ) > other.m_data.getUseCount ( ) ) - other.m_data = this->m_data; - else - this->m_data = other.m_data; - } - -public: - /** - * Disable construction from integer so that it is not confused with other constructors. - */ - WrapperBaseMiddle ( int ) = delete; - - /** - * Constructor that wraps raw pointer. Takes ownership of the pointer. - */ - explicit WrapperBaseMiddle ( T * data ) : m_data ( data ) { - } - - /** - * Constructor that wraps an object given by constant reference. Uses clone of the parameter internally. - */ - explicit WrapperBaseMiddle ( const T & data ) : m_data ( data.clone ( ) ) { - } - - /** - * Constructor that wraps an object given by r-value reference. Uses clone of the parameter internally. - */ - explicit WrapperBaseMiddle ( T && data ) : m_data ( std::move ( data ).clone ( ) ) { - } - - /** - * Gets the wrapped object. - * - * \returns wrapped object. - */ - const T & getData ( ) const { - return * m_data; - } - - /** - * Gets the wrapped object. - * - * \returns wrapped object. - */ - T & getData ( ) { - return * m_data; - } - - /** - * Sets the wrapped object from raw pointer. Takes ownership of the pointer. - * - * Internally handles situation like storing the same value that is already wrapped. Usefull in normalisation. - */ - void setData ( T * data ) { - if ( & getData ( ) == data ) - return; - - this->m_data = ext::cow_shared_ptr < T > ( data ); - } - - /** - * Sets the wrapped object from constant reference. Uses clone of the parameter internally. - */ - void setData ( const T & data ) { - setData ( data.clone ( ) ); - } - - /** - * Sets the wrapped object from r-value reference. Uses clone of the parameter internally. - */ - void setData ( T && data ) { - setData ( std::move ( data ).clone ( ) ); - } - - /** - * Determines whether this object is bigger or equal in relation to the other object. - * - * \returns true if this object is bigger or equal than other object are not equal, false othervise - */ - bool operator >=( const WrapperBaseMiddle & other ) const { - return this->compare ( other ) >= 0; - } - - /** - * Determines whether this object is smaller or equal in relation to the other object. - * - * \returns true if this object is smaller or equal than other object are not equal, false othervise - */ - bool operator <=( const WrapperBaseMiddle & other ) const { - return this->compare ( other ) <= 0; - } - - /** - * Determines whether this object is strictly bigger in relation to the other object. - * - * \returns true if this object is strictly bigger than other object are not equal, false othervise - */ - bool operator >( const WrapperBaseMiddle & other ) const { - return this->compare ( other ) > 0; - } - - /** - * Determines whether this object is strictly smaller in relation to the other object. - * - * \returns true if this object is strictly smaller than other object are not equal, false othervise - */ - bool operator <( const WrapperBaseMiddle & other ) const { - return this->compare ( other ) < 0; - } - - /** - * Compares this object with other for inequality. - * - * \returns true if this and other objects are not equal, false othervise - */ - bool operator !=( const WrapperBaseMiddle & other ) const { - return this->compare ( other ) != 0; - } - - /** - * Compares this object with other for equality. - * - * \returns true if this and other objects are equal, false othervise - */ - bool operator ==( const WrapperBaseMiddle & other ) const { - return this->compare ( other ) == 0; - } - - /** - * \brief Compares this wrapper with another, establishing relationship between them. - * - * \returns result of actual comparison of wrapped objects returning: - * value < 0 if this < other - * value == 0 if this == other - * value > 0 if this > other - */ - int compare ( const WrapperBaseMiddle & other ) const { - if ( this->m_data.get ( ) == other.m_data.get ( ) ) return 0; - - int res = ( * this->m_data ).compare ( * other.m_data ); - - if ( res == 0 ) const_cast < WrapperBaseMiddle * > ( this )->unify ( const_cast < WrapperBaseMiddle & > ( other ) ); - - return res; - } - - /** - * Print the wrapped object as raw representation to ostream. - * - * \param os ostream where to print - * \param instance wrapper to print - * - * \returns modified output stream - */ - friend std::ostream & operator <<( std::ostream & os, const WrapperBaseMiddle & instance ) { - os << instance.getData ( ); - return os; - } - - /** - * Casts the wrapped object to as compact as possible string representation. - * - * \returns string representation of the wrapped object - */ - explicit operator std::string ( ) const { - return ( std::string ) * m_data; - } - - /** - * Internaly increments the wrapped object by one to make different from the original one. - * - * \returns reference to this - */ - WrapperBaseMiddle < T > & operator ++ ( ) { - T * res = std::move ( this->getData ( ) ).inc ( ); - - if ( res != NULL ) - this->setData ( res ); - - return *this; - } -}; - -/** - * The actual wrapper base that is to be used as a base class for concrete type hierarchy object types. - * - * \tparam T type that is a base class of the concrete wrapper that inherits from this. - */ -template < typename T > -class WrapperBase : public WrapperBaseMiddle < T > { -public: - using WrapperBaseMiddle < T >::WrapperBaseMiddle; -}; - -} /* namespace base */ - -namespace ext { - -/** - * Helper for comparing everything that inherits from WrapperBaseBase. - */ -template < class T > -struct compare < T, typename std::enable_if < std::is_base_of < base::WrapperBaseBase, T >::value >::type > { - - /** - * Compare operator that determines relation between first and second object. - * - * \returns value < 0 if first < second - * value == 0 if first == second - * value > 0 if first > second - */ - int operator ()( const T & first, const T & second ) const { - return first.getData ( ).compare ( second.getData ( ) ); - } - -}; - -} /* namespace ext */ - -#endif /* WRAPPER_BASE_H_ */ diff --git a/alib2common/src/object/Object.cpp b/alib2common/src/object/Object.cpp index e4cdf248c7b1eb1bd9f50097c73157b862589d9b..51b2129d7e183285118dd168421788f9db72ddcb 100644 --- a/alib2common/src/object/Object.cpp +++ b/alib2common/src/object/Object.cpp @@ -17,19 +17,19 @@ void Object::inc ( ) { this->operator ++ ( ); } -Object::Object ( int number ) : base::WrapperBase < ObjectBase > ( primitive::Integer ( number ) ) { +Object::Object ( int number ) : Object ( primitive::Integer ( number ) ) { } Object::Object ( int number1, int number2 ) : Object ( Object ( number1 ), Object ( number2 ) ) { } -Object::Object ( Object object1, Object object2 ) : base::WrapperBase < ObjectBase > ( container::ObjectsPair < Object, Object > { ext::make_pair ( std::move ( object1 ), std::move ( object2 ) ) } ) { +Object::Object ( Object object1, Object object2 ) : Object ( container::ObjectsPair < Object, Object > { ext::make_pair ( std::move ( object1 ), std::move ( object2 ) ) } ) { } -Object::Object ( char character ) : base::WrapperBase < ObjectBase > ( primitive::Character ( character ) ) { +Object::Object ( char character ) : Object ( primitive::Character ( character ) ) { } -Object::Object ( std::string string ) : base::WrapperBase < ObjectBase > ( primitive::String ( std::move ( string ) ) ) { +Object::Object ( std::string string ) : Object ( primitive::String ( std::move ( string ) ) ) { } Object::Object ( const char * string ) : Object ( ( std::string ) string ) { diff --git a/alib2common/src/object/Object.h b/alib2common/src/object/Object.h index b61691c09a1d42c12829ccf96bd482329a5eede2..405efa4ccd10d23f8c6e8d77773afcf46f98b249 100644 --- a/alib2common/src/object/Object.h +++ b/alib2common/src/object/Object.h @@ -8,7 +8,6 @@ #ifndef OBJECT_H_ #define OBJECT_H_ -#include <base/WrapperBase.hpp> #include "ObjectBase.h" namespace object { @@ -16,8 +15,22 @@ namespace object { /** * Wrapper around object. */ -class Object : public base::WrapperBase < ObjectBase > { - using base::WrapperBase < ObjectBase >::WrapperBase; +class Object { + /** + * The wrapped data. + */ + ext::cow_shared_ptr < ObjectBase > m_data; + + /** + * \brief + * Unifies the shared pointers. For internal use when two pointer eval equal. + */ + void unify ( Object & other ) { + if ( this->m_data.getUseCount ( ) > other.m_data.getUseCount ( ) ) + other.m_data = this->m_data; + else + this->m_data = other.m_data; + } public: explicit Object ( Object label1, Object label2 ); @@ -29,8 +42,200 @@ public: void inc ( ); + /** + * Constructor that wraps raw pointer. Takes ownership of the pointer. + */ + explicit Object ( ObjectBase * data ) : m_data ( data ) { + } + + /** + * Constructor that wraps an object given by constant reference. Uses clone of the parameter internally. + */ + explicit Object ( const ObjectBase & data ) : m_data ( data.clone ( ) ) { + } + + /** + * Constructor that wraps an object given by r-value reference. Uses clone of the parameter internally. + */ + explicit Object ( ObjectBase && data ) : m_data ( std::move ( data ).clone ( ) ) { + } + + /** + * Gets the wrapped object. + * + * \returns wrapped object. + */ + const ObjectBase & getData ( ) const { + return * m_data; + } + + /** + * Gets the wrapped object. + * + * \returns wrapped object. + */ + ObjectBase & getData ( ) { + return * m_data; + } + + /** + * Sets the wrapped object from raw pointer. Takes ownership of the pointer. + * + * Internally handles situation like storing the same value that is already wrapped. Usefull in normalisation. + */ + void setData ( ObjectBase * data ) { + if ( & getData ( ) == data ) + return; + + this->m_data = ext::cow_shared_ptr < ObjectBase > ( data ); + } + + /** + * Sets the wrapped object from constant reference. Uses clone of the parameter internally. + */ + void setData ( const ObjectBase & data ) { + setData ( data.clone ( ) ); + } + + /** + * Sets the wrapped object from r-value reference. Uses clone of the parameter internally. + */ + void setData ( ObjectBase && data ) { + setData ( std::move ( data ).clone ( ) ); + } + + /** + * Determines whether this object is bigger or equal in relation to the other object. + * + * \returns true if this object is bigger or equal than other object are not equal, false othervise + */ + bool operator >=( const Object & other ) const { + return this->compare ( other ) >= 0; + } + + /** + * Determines whether this object is smaller or equal in relation to the other object. + * + * \returns true if this object is smaller or equal than other object are not equal, false othervise + */ + bool operator <=( const Object & other ) const { + return this->compare ( other ) <= 0; + } + + /** + * Determines whether this object is strictly bigger in relation to the other object. + * + * \returns true if this object is strictly bigger than other object are not equal, false othervise + */ + bool operator >( const Object & other ) const { + return this->compare ( other ) > 0; + } + + /** + * Determines whether this object is strictly smaller in relation to the other object. + * + * \returns true if this object is strictly smaller than other object are not equal, false othervise + */ + bool operator <( const Object & other ) const { + return this->compare ( other ) < 0; + } + + /** + * Compares this object with other for inequality. + * + * \returns true if this and other objects are not equal, false othervise + */ + bool operator !=( const Object & other ) const { + return this->compare ( other ) != 0; + } + + /** + * Compares this object with other for equality. + * + * \returns true if this and other objects are equal, false othervise + */ + bool operator ==( const Object & other ) const { + return this->compare ( other ) == 0; + } + + /** + * \brief Compares this wrapper with another, establishing relationship between them. + * + * \returns result of actual comparison of wrapped objects returning: + * value < 0 if this < other + * value == 0 if this == other + * value > 0 if this > other + */ + int compare ( const Object & other ) const { + if ( this->m_data.get ( ) == other.m_data.get ( ) ) return 0; + + int res = ( * this->m_data ).compare ( * other.m_data ); + + if ( res == 0 ) const_cast < Object * > ( this )->unify ( const_cast < Object & > ( other ) ); + + return res; + } + + /** + * Print the wrapped object as raw representation to ostream. + * + * \param os ostream where to print + * \param instance wrapper to print + * + * \returns modified output stream + */ + friend std::ostream & operator <<( std::ostream & os, const Object & instance ) { + os << instance.getData ( ); + return os; + } + + /** + * Casts the wrapped object to as compact as possible string representation. + * + * \returns string representation of the wrapped object + */ + explicit operator std::string ( ) const { + return ( std::string ) * m_data; + } + + /** + * Internaly increments the wrapped object by one to make different from the original one. + * + * \returns reference to this + */ + Object & operator ++ ( ) { + ObjectBase * res = std::move ( this->getData ( ) ).inc ( ); + + if ( res != NULL ) + this->setData ( res ); + + return *this; + } }; } /* namespace object */ +namespace ext { + +/** + * Helper for comparing everything that inherits from WrapperBaseBase. + */ +template < > +struct compare < object::Object > { + + /** + * Compare operator that determines relation between first and second object. + * + * \returns value < 0 if first < second + * value == 0 if first == second + * value > 0 if first > second + */ + int operator ()( const object::Object & first, const object::Object & second ) const { + return first.compare ( second ); + } + +}; + +} /* namespace ext */ + #endif /* OBJECT_H_ */ diff --git a/alib2str/src/core/stringApi.hpp b/alib2str/src/core/stringApi.hpp index 8c63b7a1675d607d3cf28662903492cc2d62704c..fe06be7e69d9a2f941c44c80890496c88e4a52c7 100644 --- a/alib2str/src/core/stringApi.hpp +++ b/alib2str/src/core/stringApi.hpp @@ -15,7 +15,7 @@ #include <alib/memory> #include <alib/algorithm> -#include "base/WrapperBase.hpp" +#include <object/Object.h> #include "exception/CommonException.h" @@ -24,12 +24,12 @@ namespace core { template < typename T, typename Enable = void > struct stringApi { }; -template < typename Group > -struct stringApi < Group, typename std::enable_if < std::is_base_of < base::WrapperBaseBase, Group >::value >::type > { +template < > +struct stringApi < object::Object > { private: class GroupReader { public: - virtual Group parse ( std::istream & input ) = 0; + virtual object::Object parse ( std::istream & input ) = 0; virtual ~GroupReader ( ) { } }; @@ -51,14 +51,14 @@ private: virtual ~ReaderRegister ( ) { } - virtual Group parse ( std::istream & input ) { - return Group ( parseFunction ( input ) ); + virtual object::Object parse ( std::istream & input ) { + return object::Object ( parseFunction ( input ) ); } }; class GroupWriter { public: - virtual void compose ( std::ostream & output, const Group & group ) = 0; + virtual void compose ( std::ostream & output, const object::Object & group ) = 0; virtual ~GroupWriter ( ) { } @@ -81,7 +81,7 @@ private: virtual ~WriterRegister ( ) { } - virtual void compose ( std::ostream & output, const Group & group ) { + virtual void compose ( std::ostream & output, const object::Object & group ) { composeFunction ( output, static_cast < const Type & > ( group.getData ( ) ) ); } }; @@ -96,14 +96,14 @@ public: static void registerStringWriter ( ) { bool res = composeFunctions ( ).insert ( std::make_pair ( ext::to_string < Type > ( ), std::unique_ptr < GroupWriter > ( new WriterRegister < Type > ( ) ) ) ).second; if ( ! res ) { - std::string groupName = ext::to_string < Group > ( ); + std::string groupName = ext::to_string < object::Object > ( ); std::string typeName = ext::to_string < Type > ( ); throw::exception::CommonException ( "Parse callback of " + typeName + " already registered in group " + groupName + "." ); } } - static Group parse ( std::istream & input ) { + static object::Object parse ( std::istream & input ) { auto lambda = [ & ] ( const std::pair < std::function < bool ( std::istream & ) >, std::unique_ptr < GroupReader > > & entry ) { return entry.first ( input ); @@ -129,8 +129,9 @@ public: return std::any_of ( parseFunctions ( ).begin ( ), parseFunctions ( ).end ( ), lambda ); } - static void compose ( std::ostream & output, const Group & data ) { - std::string type = ext::to_string ( ext::type_index ( typeid ( data.getData ( ) ) ) ); + static void compose ( std::ostream & output, const object::Object & data ) { + const auto & content = data.getData ( ); + std::string type = ext::to_string ( ext::type_index ( typeid ( content ) ) ); auto callback = composeFunctions ( ).find ( type ); if ( callback == composeFunctions ( ).end ( ) ) throw exception::CommonException ( "Compose callback for " + type + " tag not registered." ); diff --git a/alib2xml/src/core/xmlApi.hpp b/alib2xml/src/core/xmlApi.hpp index d5267af54cb0bda8defdbe8633b41f70235bb081..7115e1de792335ce80a8b382f6095595971c88d4 100644 --- a/alib2xml/src/core/xmlApi.hpp +++ b/alib2xml/src/core/xmlApi.hpp @@ -17,7 +17,7 @@ #include "sax/FromXMLParserHelper.h" #include "base/CommonBase.hpp" -#include "base/WrapperBase.hpp" +#include "object/Object.h" #include <global/GlobalData.h> @@ -32,7 +32,7 @@ class xmlApiInputContext : public ext::deque < sax::Token >::iterator { template < typename T, typename Enable > friend struct xmlApi; - ext::map < std::string, ext::map < int, base::WrapperBaseBase * > > idToInstanceContexts; + ext::map < std::string, ext::map < int, object::Object * > > idToInstanceContexts; int idMaxContext; public: @@ -40,12 +40,12 @@ public: } ~xmlApiInputContext ( ) { - for ( const std::pair < const std::string, ext::map < int, base::WrapperBaseBase * > > context : idToInstanceContexts ) - for ( const std::pair < const int, base::WrapperBaseBase * > entry : context.second ) + for ( const std::pair < const std::string, ext::map < int, object::Object * > > context : idToInstanceContexts ) + for ( const std::pair < const int, object::Object * > entry : context.second ) delete entry.second; } - ext::map < int, base::WrapperBaseBase * > & idToInstance ( const std::string & name ) { + ext::map < int, object::Object * > & idToInstance ( const std::string & name ) { return idToInstanceContexts[name]; } @@ -53,7 +53,7 @@ public: return idMaxContext; } - const ext::map < std::string, ext::map < int, base::WrapperBaseBase * > > & dump ( ) const { + const ext::map < std::string, ext::map < int, object::Object * > > & dump ( ) const { return idToInstanceContexts; } @@ -80,12 +80,12 @@ public: }; -template < typename Group > -struct xmlApi < Group, typename std::enable_if < std::is_base_of < base::WrapperBaseBase, Group >::value >::type > { +template < > +struct xmlApi < object::Object > { private: class GroupParser { public: - virtual Group parse ( ext::deque < sax::Token >::iterator & input ) = 0; + virtual object::Object parse ( ext::deque < sax::Token >::iterator & input ) = 0; virtual ~GroupParser ( ) { } @@ -108,15 +108,15 @@ private: virtual ~ParserRegister( ) { } - virtual Group parse ( ext::deque < sax::Token >::iterator & input ) { - return Group ( parseFunction ( input ) ); + virtual object::Object parse ( ext::deque < sax::Token >::iterator & input ) { + return object::Object ( parseFunction ( input ) ); } }; class GroupComposer { public: - virtual void compose ( ext::deque < sax::Token > & input, const Group & group ) = 0; + virtual void compose ( ext::deque < sax::Token > & input, const object::Object & group ) = 0; virtual ~GroupComposer( ) { } @@ -139,7 +139,7 @@ private: virtual ~ComposerRegister ( ) { } - virtual void compose ( ext::deque < sax::Token > & input, const Group & group ) { + virtual void compose ( ext::deque < sax::Token > & input, const object::Object & group ) { composeFunction ( input, static_cast < const Type & > ( group.getData ( ) ) ); } @@ -150,7 +150,7 @@ public: static void registerXmlReader ( ) { bool res = parseFunctions ( ).insert ( std::make_pair ( xmlApi < Type >::xmlTagName(), std::unique_ptr < GroupParser > ( new ParserRegister < Type > ( ) ) ) ).second; if ( ! res ) { - std::string groupName = ext::to_string < Group > ( ); + std::string groupName = ext::to_string < object::Object > ( ); std::string typeName = ext::to_string < Type > ( ); throw::exception::CommonException ( "Parse callback of " + typeName + " already registered in group " + groupName + "." ); @@ -161,14 +161,14 @@ public: static void registerXmlWriter ( ) { bool res = composeFunctions ( ).insert ( std::make_pair ( ext::to_string < Type > ( ), std::unique_ptr < GroupComposer > ( new ComposerRegister < Type > ( ) ) ) ).second; if ( ! res ) { - std::string groupName = ext::to_string < Group > ( ); + std::string groupName = ext::to_string < object::Object > ( ); std::string typeName = ext::to_string < Type > ( ); throw::exception::CommonException ( "Parse callback of " + typeName + " already registered in group " + groupName + "." ); } } - static Group parse ( ext::deque < sax::Token >::iterator & data ) { + static object::Object parse ( ext::deque < sax::Token >::iterator & data ) { xmlApiInputContext & input = ( xmlApiInputContext & ) data; sax::FromXMLParserHelper::skipAttributes ( input, sax::Token::TokenType::START_ELEMENT ); @@ -179,14 +179,14 @@ public: int id = ext::from_string < int > ( sax::FromXMLParserHelper::popTokenData ( input, sax::Token::TokenType::CHARACTER ) ); sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ATTRIBUTE, "id" ); sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, "Ref" ); - ext::map < int, base::WrapperBaseBase * >::iterator elem = input.idToInstance ( ext::to_string < Group > ( ) ).find ( id ); + ext::map < int, object::Object * >::iterator elem = input.idToInstance ( ext::to_string < object::Object > ( ) ).find ( id ); - if ( elem == input.idToInstance ( ext::to_string < Group > ( ) ).end ( ) ) { + if ( elem == input.idToInstance ( ext::to_string < object::Object > ( ) ).end ( ) ) { common::Streams::err << input.dump ( ) << std::endl; throw exception::CommonException ( "XML Inconsistent ( id not found " + ext::to_string ( id ) + " )" ); } - return * ( ( Group * ) elem->second ); + return * ( ( object::Object * ) elem->second ); } else { typename ext::map < std::string, std::unique_ptr < GroupParser > >::iterator callback = parseFunctions ( ).find ( tagName ); @@ -200,11 +200,11 @@ public: id = ext::from_string < int > ( sax::FromXMLParserHelper::popTokenData ( tmp, sax::Token::TokenType::CHARACTER ) ); } - Group res ( callback->second->parse ( input ) ); + object::Object res ( callback->second->parse ( input ) ); /* if object is a base of reference, register it */ if ( ref ) - input.idToInstance ( ext::to_string < Group > ( ) ).insert ( std::make_pair ( id, ( base::WrapperBaseBase * ) new Group ( res ) ) ); + input.idToInstance ( ext::to_string < object::Object > ( ) ).insert ( std::make_pair ( id, ( object::Object * ) new object::Object ( res ) ) ); return res; } @@ -223,17 +223,17 @@ public: } static std::string xmlTagName ( ) { - std::string target = ext::to_string < Group > ( ); + std::string target = ext::to_string < object::Object > ( ); throw ::exception::CommonException ( "Type " + target + " does not have xmlTagName." ); } - static void compose ( ext::deque < sax::Token > & output, const Group & data ) { + static void compose ( ext::deque < sax::Token > & output, const object::Object & data ) { xmlApiOutputContext & context = ( xmlApiOutputContext & ) output; - typename ext::map < const base::CommonBaseBase *, int >::iterator elem = context.instanceToId ( ext::to_string < Group > ( ) ).find ( static_cast < const base::CommonBaseBase * > ( & data.getData ( ) ) ); + typename ext::map < const base::CommonBaseBase *, int >::iterator elem = context.instanceToId ( ext::to_string < object::Object > ( ) ).find ( static_cast < const base::CommonBaseBase * > ( & data.getData ( ) ) ); - if ( common::GlobalData::optimizeXml && elem != context.instanceToId ( ext::to_string < Group > ( ) ).end ( ) ) { + if ( common::GlobalData::optimizeXml && elem != context.instanceToId ( ext::to_string < object::Object > ( ) ).end ( ) ) { output.emplace_back ( "Ref", sax::Token::TokenType::START_ELEMENT ); output.emplace_back ( "id", sax::Token::TokenType::START_ATTRIBUTE ); output.emplace_back ( ext::to_string ( elem->second ), sax::Token::TokenType::CHARACTER ); @@ -247,7 +247,8 @@ public: id = context.idMax ( )++; } - std::string type = ext::to_string ( ext::type_index ( typeid ( data.getData ( ) ) ) ); + const auto & content = data.getData ( ); + std::string type = ext::to_string ( ext::type_index ( typeid ( content ) ) ); typename ext::map < std::string, std::unique_ptr < GroupComposer > >::iterator callback = composeFunctions ( ).find ( type ); if ( callback == composeFunctions ( ).end ( ) ) throw exception::CommonException ( "Compose callback for " + type + " tag not registered." ); @@ -261,7 +262,7 @@ public: output.emplace ( output.begin ( ) + pos + 2, ext::to_string ( id ), sax::Token::TokenType::CHARACTER ); output.emplace ( output.begin ( ) + pos + 3, "ref", sax::Token::TokenType::END_ATTRIBUTE ); - context.instanceToId ( ext::to_string < Group > ( ) ).insert ( std::make_pair ( static_cast< const base::CommonBaseBase * > ( & data.getData ( ) ), id ) ); + context.instanceToId ( ext::to_string < object::Object > ( ) ).insert ( std::make_pair ( static_cast< const base::CommonBaseBase * > ( & data.getData ( ) ), id ) ); } } }