diff --git a/alib2common/src/core/castApi.hpp b/alib2common/src/core/castApi.hpp index 385fe064c83b61e4c68b280719279e520339a312..2eb566e19c91530a4503c91d5d0b72f904b395f5 100644 --- a/alib2common/src/core/castApi.hpp +++ b/alib2common/src/core/castApi.hpp @@ -34,7 +34,7 @@ struct castApi { 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::type_name ( typeid ( from ) ); throw exception::CommonException ( "Bad cast: From: " + fromType + " To: " + toType ( ) ); } @@ -69,7 +69,7 @@ struct castApi { } std::string toType ( ) { - return std::cstringToString ( std::type_name < To > ( ) ); + return std::type_name < To > ( ); } }; @@ -125,7 +125,7 @@ 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::type_name ( typeId ); throw exception::CommonException ( "Casting to type " + toType + " not available." ); } else { diff --git a/alib2common/src/core/multipleDispatch.hpp b/alib2common/src/core/multipleDispatch.hpp index fbb4f2cbb2a15d4a5378318db1962aaa6d8adb32..aa7356ab6bfb5720c25ab5291ca65978e9a90e78 100644 --- a/alib2common/src/core/multipleDispatch.hpp +++ b/alib2common/src/core/multipleDispatch.hpp @@ -53,9 +53,9 @@ 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 ) { std::stringstream ss; - ( void ) initializer_list < int > { ( ss << cstringToString ( std::type_name < typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type > ( ) ), 0 ) ... }; + ( void ) initializer_list < int > { ( ss << std::type_name < typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type > ( ), 0 ) ... }; - std::string classType = cstringToString ( std::type_name < Algorithm > ( ) ); + std::string classType = std::type_name < Algorithm > ( ); throw::exception::CommonException ( "Callback for " + ss.str ( ) + " already registered on " + classType + "." ); } @@ -68,9 +68,9 @@ public: if ( callback == getInstance ( ).registeredFunctions.end ( ) ) { std::stringstream ss; - ( void ) initializer_list < int > { ( ss << cstringToString ( std::type_name ( typeid ( dispatched ) ) ), 0 ) ... }; + ( void ) initializer_list < int > { ( ss << std::type_name ( typeid ( dispatched ) ), 0 ) ... }; - std::string classType = cstringToString ( std::type_name < Algorithm > ( ) ); + std::string classType = std::type_name < Algorithm > ( ); throw::exception::CommonException ( "Callback for " + ss.str ( ) + " not registered on " + classType + "." ); } @@ -146,9 +146,9 @@ public: RegistratorWrapper ( RealReturnType ( * callback ) ( RealParametersType &&, RealParametersType && ) ) : m_callback ( callback ) { if ( !getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::type_index ( typeid ( RealParametersType ) ), this ) ).second ) { - std::string paramsType = std::cstringToString ( std::type_name < RealParametersType > ( ) ); + std::string paramsType = std::type_name < RealParametersType > ( ); - std::string classType = std::cstringToString ( std::type_name < Algorithm > ( ) ); + std::string classType = std::type_name < Algorithm > ( ); throw::exception::CommonException ( "Callback for " + paramsType + " already registered on " + classType + "." ); } @@ -167,11 +167,11 @@ public: if ( ( callback != getInstance ( ).registeredFunctions.end ( ) ) && callback->second->available ( false, std::type_index ( typeid ( first ) ), std::type_index ( typeid ( second ) ) ) ) return callback->second->eval ( false, std::forward < ParametersType > ( first ), std::forward < ParametersType > ( second ) ); - std::string firstType = std::cstringToString ( std::type_name ( typeid ( first ) ) ); + std::string firstType = std::type_name ( typeid ( first ) ); - std::string secondType = std::cstringToString ( std::type_name ( typeid ( second ) ) ); + std::string secondType = std::type_name ( typeid ( second ) ); - std::string classType = std::cstringToString ( std::type_name < Algorithm > ( ) ); + std::string classType = std::type_name < Algorithm > ( ); throw::exception::CommonException ( "Callback for (" + firstType + ", " + secondType + ") (promoting) not registered on " + classType + "." ); } diff --git a/alib2std/src/extensions/typeinfo.cpp b/alib2std/src/extensions/typeinfo.cpp index 8767b632b1b1b2ded2d1eae82640cb2072b31a0c..5f6e691b1e80d0c105aa06779599362fa0820576 100644 --- a/alib2std/src/extensions/typeinfo.cpp +++ b/alib2std/src/extensions/typeinfo.cpp @@ -9,15 +9,16 @@ namespace std { - char* type_name(const std::type_info& type) { - int status; - - return abi::__cxa_demangle(type.name(), 0, 0, &status); + string type_name(const std::type_info& type) { + return type_name ( type_index ( type ) ); } - char* type_name(const std::type_index& type) { + string type_name(const std::type_index& type) { int status; - return abi::__cxa_demangle(type.name(), 0, 0, &status); + char* demangled = abi::__cxa_demangle(type.name(), 0, 0, &status); + string res ( demangled ); + free ( demangled ); + return res; } } /* namespace std */ diff --git a/alib2std/src/extensions/typeinfo.hpp b/alib2std/src/extensions/typeinfo.hpp index 447e0d69887e48bbd869c2f851018dfc2216e397..3cd4bcdc1d158dc2349afad17bea0d7e4ac604a9 100644 --- a/alib2std/src/extensions/typeinfo.hpp +++ b/alib2std/src/extensions/typeinfo.hpp @@ -10,11 +10,11 @@ namespace std { - char* type_name(const std::type_info& type); - char* type_name(const std::type_index& type); + string type_name(const std::type_info& type); + string type_name(const std::type_index& type); template <class T> - char* type_name() { + string type_name() { return type_name(typeid(T)); } @@ -22,9 +22,8 @@ namespace std { bool is_same_type(const char* name) { char namespaceId[100]; char classId[100]; - char* ret = type_name<T>(); - sscanf(ret, "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId); - free( ret ); + string ret = type_name<T>(); + sscanf(ret.c_str(), "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId); if(strcmp(classId, name) == 0) { return true; diff --git a/alib2std/src/typeinfo b/alib2std/src/typeinfo index 7885373e3598844d0f6acc13005ed3e26f96d818..323f08415b9bd4bcb138e93e03431a6e2c7875ea 100644 --- a/alib2std/src/typeinfo +++ b/alib2std/src/typeinfo @@ -7,6 +7,7 @@ #include <cstring> #include <cxxabi.h> #include "typeindex" +#include <string> #include "extensions/typeinfo.hpp" #endif /* __TYPEINFO_HEADER_WRAPPER_ */