Replace Boost.TypeInfo

This commit is contained in:
Alexander Grund 2020-07-11 14:58:37 +02:00
parent 6702d68940
commit 9af9f0e2ea
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
4 changed files with 24 additions and 26 deletions

View file

@ -15,15 +15,6 @@
#include <boost/algorithm/string/erase.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION >= 107000
# include <boost/core/typeinfo.hpp>
# define MOCK_TYPEID( t ) BOOST_CORE_TYPEID(t)
# define MOCK_TYPEINFO boost::core::typeinfo
#else
# include <boost/detail/sp_typeinfo.hpp>
# define MOCK_TYPEID( t ) BOOST_SP_TYPEID(t)
# define MOCK_TYPEINFO boost::detail::sp_typeinfo
#endif
#include <stdexcept>
#include <memory>
#include <typeinfo>
@ -33,8 +24,6 @@
#include <cstdlib>
#endif
#define MOCK_TYPE_NAME( t ) mock::detail::type_name( MOCK_TYPEID(t) )
namespace mock
{
namespace detail
@ -42,7 +31,7 @@ namespace detail
class type_name
{
public:
explicit type_name( const MOCK_TYPEINFO& info )
explicit type_name( const std::type_info& info )
: info_( &info )
{}
friend std::ostream& operator<<( std::ostream& s, const type_name& t )
@ -51,8 +40,7 @@ namespace detail
return s;
}
private:
void serialize( std::ostream& s,
const MOCK_TYPEINFO& info ) const
static void serialize( std::ostream& s, const std::type_info& info )
{
const char* name = info.name();
#ifdef __GNUC__
@ -69,7 +57,7 @@ namespace detail
typedef std::string::size_type size_type;
void serialize( std::ostream& s, std::string name ) const
static void serialize( std::ostream& s, std::string name )
{
const size_type nm = rfind( name, ':' ) + 1;
const size_type tpl = name.find( '<', nm );
@ -80,7 +68,7 @@ namespace detail
list( s, name.substr( tpl + 1, name.rfind( '>' ) - tpl - 1 ) );
s << '>';
}
void list( std::ostream& s, const std::string& name ) const
static void list( std::ostream& s, const std::string& name )
{
const size_type comma = rfind( name, ',' );
if( comma != std::string::npos )
@ -90,7 +78,7 @@ namespace detail
}
serialize( s, name.substr( comma + 1 ) );
}
std::string clean( std::string name ) const
static std::string clean( std::string name )
{
boost::algorithm::trim( name );
boost::algorithm::erase_all( name, "class " );
@ -102,7 +90,7 @@ namespace detail
boost::algorithm::replace_all( name, "* ", "*" );
return name;
}
size_type rfind( const std::string& name, char c ) const
static size_type rfind( const std::string& name, char c )
{
size_type count = 0;
for( size_type i = name.size() - 1; i > 0; --i )
@ -117,8 +105,18 @@ namespace detail
return std::string::npos;
}
const MOCK_TYPEINFO* info_;
const std::type_info* info_;
};
template< typename T >
type_name make_type_name()
{
return type_name( typeid(T) );
}
template< typename T >
type_name make_type_name( const T& )
{
return type_name( typeid(T) );
}
}
} // mock

View file

@ -63,7 +63,7 @@
{ \
mock::detail::configure( *this, t##_mock_, \
instance.substr( 0, instance.rfind( BOOST_PP_STRINGIZE(t) ) ), \
MOCK_TYPE_NAME(*this), \
mock::detail::make_type_name(*this), \
BOOST_PP_STRINGIZE(t) ); \
return t##_mock_; \
}