diff --git a/alib2common/src/core/castApi.hpp b/alib2common/src/core/castApi.hpp index 2eb566e19c91530a4503c91d5d0b72f904b395f5..3afa288d3cb795f1cee6fdbc7a712482d19bbc70 100644 --- a/alib2common/src/core/castApi.hpp +++ b/alib2common/src/core/castApi.hpp @@ -53,14 +53,26 @@ struct castApi { public: template < class From > void add ( ) { - castFunctions.insert ( std::make_pair ( std::type_index ( typeid ( From ) ), [] ( const alib::ObjectBase & from ) { return alib::Object ( To ( ( const From & ) from ) ); } ) ); + bool res = castFunctions.insert ( std::make_pair ( std::type_index ( typeid ( From ) ), [] ( const alib::ObjectBase & from ) { return alib::Object ( To ( ( const From & ) from ) ); } ) ).second; + if ( ! res ) { + std::string fromName = std::type_name < From > ( ); + std::string toName = std::type_name < To > ( ); + + throw::exception::CommonException ( "Casting from " + fromName + " to " + toName + " already registered." ); + } } template < class From > void add ( To ( * castFunction )( const From & ) ) { - castFunctions.insert ( std::make_pair ( std::type_index ( typeid ( From ) ), [=] ( const alib::ObjectBase & from ) { + bool res = castFunctions.insert ( std::make_pair ( std::type_index ( typeid ( From ) ), [=] ( const alib::ObjectBase & from ) { return alib::Object ( ( ( To ( * )( const alib::ObjectBase & ) )castFunction )( from ) ); - } ) ); + } ) ).second; + if ( ! res ) { + std::string fromName = std::type_name < From > ( ); + std::string toName = std::type_name < To > ( ); + + throw::exception::CommonException ( "Casting from " + fromName + " to " + toName + " already registered." ); + } } template < class From > @@ -146,7 +158,12 @@ public: class CastPoolStringBinder { public: CastPoolStringBinder ( std::string tagName ) { - castFunctionsByString ( ).insert ( std::make_pair ( tagName, & getCastPool < To > ( ) ) ); + bool res = castFunctionsByString ( ).insert ( std::make_pair ( tagName, & getCastPool < To > ( ) ) ).second; + if ( ! res ) { + std::string toName = std::type_name < To > ( ); + + throw::exception::CommonException ( "String cast pool for " + toName + "already exists." ); + } } }; diff --git a/alib2common/src/core/multipleDispatch.hpp b/alib2common/src/core/multipleDispatch.hpp index aa7356ab6bfb5720c25ab5291ca65978e9a90e78..4c37b7ce940b177f0b7a233748173b07092cb3a0 100644 --- a/alib2common/src/core/multipleDispatch.hpp +++ b/alib2common/src/core/multipleDispatch.hpp @@ -51,7 +51,8 @@ public: } RegistratorWrapper ( RealReturnType ( * callback ) ( FrontStaticParamTypes ..., typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type && ..., BackStaticParamTypes ... ) ) : m_callback ( callback ) { - if ( !getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::make_tuple ( std::type_index ( typeid ( typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type ) ) ... ), this ) ).second ) { + bool res = getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::make_tuple ( std::type_index ( typeid ( typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type ) ) ... ), this ) ).second; + if ( ! res ) { std::stringstream ss; ( void ) initializer_list < int > { ( ss << std::type_name < typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type > ( ), 0 ) ... }; @@ -145,7 +146,8 @@ public: } RegistratorWrapper ( RealReturnType ( * callback ) ( RealParametersType &&, RealParametersType && ) ) : m_callback ( callback ) { - if ( !getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::type_index ( typeid ( RealParametersType ) ), this ) ).second ) { + bool res = getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::type_index ( typeid ( RealParametersType ) ), this ) ).second; + if ( ! res ) { std::string paramsType = std::type_name < RealParametersType > ( ); std::string classType = std::type_name < Algorithm > ( ); diff --git a/alib2common/src/core/xmlApi.hpp b/alib2common/src/core/xmlApi.hpp index 9348d0bb69b7cb9e74f6d8a53542198ba83d8bd4..485869a41f737e4abbe0d0fecd4eaf6975f4519d 100644 --- a/alib2common/src/core/xmlApi.hpp +++ b/alib2common/src/core/xmlApi.hpp @@ -116,8 +116,14 @@ public: std::function < Type ( std::deque < sax::Token >::iterator & ) > parseFunction; public: - ParserRegister ( ) : parseFunction ( Type::parse ) { - parseFunctions ( ).insert ( std::make_pair ( Type::getXmlTagName(), this ) ); + ParserRegister( ) : parseFunction ( Type::parse ) { + bool res = parseFunctions ( ).insert ( std::make_pair ( Type::getXmlTagName(), this ) ).second; + if ( ! res ) { + std::string groupName = std::type_name < Group > ( ); + std::string typeName = std::type_name < Type > ( ); + + throw::exception::CommonException ( "Parse callback of " + typeName + " already registered in group " + groupName + "." ); + } } virtual Group parse ( std::deque < sax::Token >::iterator & input ) {