From 19c07d82e7c109fd64ab36f0332cdf0968059b41 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 21 May 2015 19:48:24 +0200 Subject: [PATCH] more concrete cast --- acast2/src/CastVisitorBase.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/acast2/src/CastVisitorBase.hpp b/acast2/src/CastVisitorBase.hpp index 3e87ff2483..ab9d4fe56c 100644 --- a/acast2/src/CastVisitorBase.hpp +++ b/acast2/src/CastVisitorBase.hpp @@ -7,6 +7,7 @@ #include <exception/AlibException.h> #include <factory/XmlDataFactory.hpp> +#include <cxxabi.h> template<typename T, typename R, typename std::enable_if< std::is_constructible<T, R>::value >::type* = nullptr > T cast(const R& orig) { @@ -84,7 +85,15 @@ public: template<typename BaseVisitor, typename Base, typename Types, typename R, typename ... Rs > void cast_helper<BaseVisitor, Base, Types, R, Rs ...>::do_cast(const std::string& name, const Base& obj) { - if(std::string(typeid(R).name()).find(name) != std::string::npos) { + int status; + + char namespaceId[100]; + char classId[100]; + char* ret = abi::__cxa_demangle(typeid(R).name(), 0, 0, &status); + sscanf(ret, "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId); + free( ret ); + + if(std::string(classId) == name) { cast_implementer<BaseVisitor, Base, R, Types>::cast(obj); } else { cast_helper<BaseVisitor, Base, Types, Rs ...>::do_cast(name, obj); -- GitLab