diff --git a/alib2common/src/core/components/setComponents.hpp b/alib2common/src/core/components/setComponents.hpp index 9ed8756684f653942fa60c4f1c2d2c3b0b41c95f..1746248c0c19372141ab0dd61077dc40fcfb737d 100644 --- a/alib2common/src/core/components/setComponents.hpp +++ b/alib2common/src/core/components/setComponents.hpp @@ -80,9 +80,8 @@ class SetComponent { SetConstraint < Derived, ComponentType, ComponentName >::valid ( static_cast < const Derived & > ( * this ), element ); if ( ! SetConstraint < Derived, ComponentType, ComponentName >::available ( static_cast < const Derived & > ( * this ), element ) ) { - std::string elementTypeName ( ext::to_string < ComponentName * > ( ) ); - elementTypeName.back ( ) = ' '; - throw exception::CommonException ( elementTypeName + "element " + ext::to_string ( element ) + " is not available." ); + std::string elementTypeName ( ext::to_string < ComponentName > ( ) ); + throw exception::CommonException ( elementTypeName + " element " + ext::to_string ( element ) + " is not available." ); } } @@ -92,8 +91,7 @@ class SetComponent { */ void checkRemove ( const ComponentType & element ) { if ( SetConstraint < Derived, ComponentType, ComponentName >::used ( static_cast < const Derived & > ( * this ), element ) ) { - std::string elementTypeName ( ext::to_string < ComponentName * > ( ) ); - elementTypeName.back ( ) = ' '; + std::string elementTypeName ( ext::to_string < ComponentName > ( ) ); throw exception::CommonException ( elementTypeName + "element " + ext::to_string ( element ) + " is used." ); } } diff --git a/alib2std/src/extensions/typeinfo.hpp b/alib2std/src/extensions/typeinfo.hpp index 87788250fd5eac355e56a8e03e8e7d8693788c47..e9dfc7e806bd8e6099ff72f1a5a383ba306ace06 100644 --- a/alib2std/src/extensions/typeinfo.hpp +++ b/alib2std/src/extensions/typeinfo.hpp @@ -17,7 +17,14 @@ namespace ext { -template < class T > +template < class T, typename std::enable_if < std::is_class < T >::value >::type * = nullptr > +std::string to_string ( ) { + std::string res = ext::to_string ( ext::type_index ( typeid ( T * ) ) ); // handle even incomplete class types + res.pop_back ( ); // to erase extra pointer + return res; +} + +template < class T, typename std::enable_if < ! std::is_class < T >::value >::type * = nullptr > std::string to_string ( ) { return ext::to_string ( ext::type_index ( typeid ( T ) ) ); } diff --git a/alib2std/test-src/extensions/TypeTraitsTest.cpp b/alib2std/test-src/extensions/TypeTraitsTest.cpp index 378172ede6a05213149f081e6e9ca012419f0c26..2d6c796e0c316bb5483330afa0b80941c072d098 100644 --- a/alib2std/test-src/extensions/TypeTraitsTest.cpp +++ b/alib2std/test-src/extensions/TypeTraitsTest.cpp @@ -20,3 +20,14 @@ void TypeTraitsTest::testTypeInPack() { CPPUNIT_ASSERT( ( ext::is_in< std::pair < int, int >, void, ext::pair < int, int > >::value ) == false ); } + +class Foo { +}; + +class Bar; + +void TypeTraitsTest::testTypeNames() { + CPPUNIT_ASSERT ( ext::to_string < Foo > ( ) == "Foo" ); + CPPUNIT_ASSERT ( ext::to_string < Bar > ( ) == "Bar" ); + CPPUNIT_ASSERT ( ext::to_string < int > ( ) == "int" ); +} diff --git a/alib2std/test-src/extensions/TypeTraitsTest.h b/alib2std/test-src/extensions/TypeTraitsTest.h index 84a41ae0e72917b3e92a3eb2b0c4ad5b1587ee45..d5c68afb69cb511bfc2e1f1984c40d9fa3a01a5a 100644 --- a/alib2std/test-src/extensions/TypeTraitsTest.h +++ b/alib2std/test-src/extensions/TypeTraitsTest.h @@ -8,6 +8,7 @@ class TypeTraitsTest : public CppUnit::TestFixture CPPUNIT_TEST_SUITE( TypeTraitsTest ); CPPUNIT_TEST( testAccessPackElement ); CPPUNIT_TEST( testTypeInPack ); + CPPUNIT_TEST( testTypeNames ); CPPUNIT_TEST_SUITE_END(); public: @@ -60,11 +61,12 @@ struct test2 { }; public: - void setUp(); - void tearDown(); + void setUp(); + void tearDown(); - void testAccessPackElement(); - void testTypeInPack(); + void testAccessPackElement(); + void testTypeInPack(); + void testTypeNames(); }; #endif // TYPE_TRAITS_TEST_H_