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

add various callbacks insertion checks

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