mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Fixed type name extraction
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@70 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
d0bda73778
commit
eb78cf942e
3 changed files with 76 additions and 12 deletions
|
|
@ -236,6 +236,10 @@
|
|||
RelativePath="..\..\src\tests\turtle_test\silent_error.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\tests\turtle_test\type_name_test.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
|
|
|||
|
|
@ -43,27 +43,21 @@ namespace detail
|
|||
guard g( result );
|
||||
if( result )
|
||||
return result;
|
||||
else
|
||||
return name;
|
||||
#else
|
||||
return name;
|
||||
#endif
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
std::string type_full_name()
|
||||
{
|
||||
return type_full_name( typeid( T ) );
|
||||
return name;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
std::string type_name()
|
||||
{
|
||||
const std::string name = type_full_name< T >();
|
||||
const std::string name = type_full_name( typeid( T ) );
|
||||
std::size_t p = name.rfind( "::" );
|
||||
if( p != std::string::npos )
|
||||
return name.substr( p + 2 );
|
||||
return "";
|
||||
p = name.rfind( " " );
|
||||
if( p != std::string::npos )
|
||||
return name.substr( p + 1 );
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
66
src/tests/turtle_test/type_name_test.cpp
Normal file
66
src/tests/turtle_test/type_name_test.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <turtle/type_name.hpp>
|
||||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#define BOOST_LIB_NAME boost_unit_test_framework
|
||||
#include <boost/config/auto_link.hpp>
|
||||
|
||||
struct my_type_from_default_namespace {};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_from_default_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_from_default_namespace", mock::detail::type_name< my_type_from_default_namespace >() );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct my_type_from_anonymous_namespace {};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_from_anonymous_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_from_anonymous_namespace", mock::detail::type_name< my_type_from_anonymous_namespace >() );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
struct my_type_from_named_namespace {};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_from_named_namespace", mock::detail::type_name< nm::my_type_from_named_namespace >() );
|
||||
}
|
||||
|
||||
namespace nm
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_from_named_inner_namespace {};
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_from_named_inner_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_from_named_inner_namespace", mock::detail::type_name< nm::inner::my_type_from_named_inner_namespace >() );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace inner
|
||||
{
|
||||
struct my_type_from_unnamed_inner_namespace {};
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( name_of_type_from_unnamed_inner_namespace_is_extracted )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "my_type_from_unnamed_inner_namespace", mock::detail::type_name< inner::my_type_from_unnamed_inner_namespace >() );
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue