diff --git a/alib2common/src/cast/CastApi.hpp b/alib2common/src/cast/CastApi.hpp index dbb1d1318e375bc7225a86cbd24fd7ce4896d52c..53b4fb95f4f474fd82612e709bbd5ec19f5b2dc5 100644 --- a/alib2common/src/cast/CastApi.hpp +++ b/alib2common/src/cast/CastApi.hpp @@ -27,16 +27,16 @@ struct castApi { virtual std::string toType ( ) = 0; public: - virtual ~CastPoolBase() { + virtual ~CastPoolBase ( ) { } alib::Object cast ( const alib::ObjectBase & from ) { std::map < std::type_index, std::function < alib::Object ( const alib::ObjectBase & ) > >::iterator res = castFunctions.find ( std::type_index ( typeid ( from ) ) ); if ( res == castFunctions.end ( ) ) { - std::string fromType = std::cstringToString(std::type_name(typeid(from))); + std::string fromType = std::cstringToString ( std::type_name ( typeid ( from ) ) ); - throw exception::CommonException ( "Bad cast: From: " + fromType + " To: " + toType()); + throw exception::CommonException ( "Bad cast: From: " + fromType + " To: " + toType ( ) ); } return res->second ( from ); @@ -57,11 +57,10 @@ struct castApi { } template < class From > - void add ( To(*castFunction)(const From&) ) { - castFunctions.insert ( std::make_pair ( std::type_index ( typeid ( From ) ),[=] ( const alib::ObjectBase & from ) { - return alib::Object ( ( ( To(*) ( const alib::ObjectBase & ) ) castFunction ) ( from ) ); - } - ) ); + void add ( To ( * castFunction )( const From & ) ) { + castFunctions.insert ( std::make_pair ( std::type_index ( typeid ( From ) ), [=] ( const alib::ObjectBase & from ) { + return alib::Object ( ( ( To ( * )( const alib::ObjectBase & ) )castFunction )( from ) ); + } ) ); } template < class From > @@ -70,7 +69,8 @@ struct castApi { } std::string toType ( ) { - std::string toType = std::cstringToString(std::type_name<To>()); + std::string toType = std::cstringToString ( std::type_name < To > ( ) ); + return toType; } @@ -127,11 +127,12 @@ public: std::map < std::type_index, CastPoolBase * >::iterator res = castFunctionsById ( ).find ( typeId ); if ( res == castFunctionsById ( ).end ( ) ) { - std::string toType = std::cstringToString(std::type_name( typeId )); + std::string toType = std::cstringToString ( std::type_name ( typeId ) ); throw exception::CommonException ( "Casting to type " + toType + " not available." ); - } else + } else { return * res->second; + } } static bool castAvailable ( std::type_index to, std::type_index from ) { @@ -159,9 +160,10 @@ public: getCastPool < To > ( ).template add < From > ( ); } - CastRegister ( To(*castFunction)(const From&) ) { + CastRegister ( To ( * castFunction ) ( const From & ) ) { getCastPool < To > ( ).template add < From > ( castFunction ); } + }; };