Fixes toString() for function pointers and added support for member function pointers.

- thanks to Malcolm Noyes for supplying sample code on which the solution here was based
This commit is contained in:
Phil Nash 2014-01-07 17:25:27 +00:00
parent 440a47011f
commit e091018514
7 changed files with 82 additions and 12 deletions

View file

@ -79,6 +79,25 @@ namespace Detail {
}
};
// For display purposes only.
// Does not consider endian-ness
template<typename T>
std::string rawMemoryToString( T value ) {
union
{
T value;
unsigned char bytes[sizeof(T)];
} valueAsBuffer;
valueAsBuffer.value = value;
std::ostringstream oss;
oss << "0x";
for( unsigned char* cp = valueAsBuffer.bytes; cp < valueAsBuffer.bytes+sizeof(T); ++cp )
oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp;
return oss.str();
}
} // end namespace Detail
template<typename T>
@ -94,9 +113,18 @@ struct StringMaker<T*> {
static std::string convert( U* p ) {
if( !p )
return INTERNAL_CATCH_STRINGIFY( NULL );
std::ostringstream oss;
oss << "0x" << std::hex << reinterpret_cast<unsigned long>( p );
return oss.str();
else
return Detail::rawMemoryToString( p );
}
};
template<typename R, typename C>
struct StringMaker<R C::*> {
static std::string convert( R C::* p ) {
if( !p )
return INTERNAL_CATCH_STRINGIFY( NULL );
else
return Detail::rawMemoryToString( p );
}
};