From 7eb00b6d3037a7e30c326b43e23502f777b92eb6 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 12 Dec 2007 17:06:16 +0000 Subject: Corrected some issues with the new trace system. It's now working fine. It's backword compatible, and the new features are a lot of fun. Since it uses template functions you can add any new variable types to be formatted. --- src/trace.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 src/trace.cpp (limited to 'src/trace.cpp') diff --git a/src/trace.cpp b/src/trace.cpp new file mode 100644 index 0000000..b328565 --- /dev/null +++ b/src/trace.cpp @@ -0,0 +1,116 @@ +#define BU_TRACE +#include "bu/trace.h" + +void Bu::__tracer( const char *pf ) +{ + printf("trace: %s\n", pf ); +} + +template<> void Bu::__tracer_format( const int8_t &v ) +{ + printf("%hhd", v ); +} + +template<> void Bu::__tracer_format( const uint8_t &v ) +{ + printf("%hhu", v ); +} + +template<> void Bu::__tracer_format( const int16_t &v ) +{ + printf("%hd", v ); +} + +template<> void Bu::__tracer_format( const uint16_t &v ) +{ + printf("%hu", v ); +} + +template<> void Bu::__tracer_format( const int32_t &v ) +{ + printf("%d", v ); +} + +template<> void Bu::__tracer_format( const uint32_t &v ) +{ + printf("%u", v ); +} + +template<> void Bu::__tracer_format( const int64_t &v ) +{ + printf("%lld", v ); +} + +template<> void Bu::__tracer_format( const uint64_t &v ) +{ + printf("%llu", v ); +} + +template<> void Bu::__tracer_format( const bool &v ) +{ + if( v ) + printf("true"); + else + printf("false"); +} + +template<> void Bu::__tracer_format( const char &v ) +{ + printf("%hhd", v ); +} + +template<> void Bu::__tracer_format( const long &v ) +{ + printf("%ld", v ); +} + +template<> void Bu::__tracer_format( const unsigned long &v ) +{ + printf("%lu", v ); +} + +template<> void Bu::__tracer_format( const float &v ) +{ + printf("%f", v ); +} + +template<> void Bu::__tracer_format( const double &v ) +{ + printf("%f", v ); +} + +template<> void Bu::__tracer_format( void * const &v ) +{ + printf("0x%08X", (unsigned int)v ); +} + +template<> void Bu::__tracer_format( char * const &v ) +{ + printf("\"%s\"", v ); +} + +template<> void Bu::__tracer_format( char ** const &v ) +{ + printf("["); + for( int j = 0; v[j]; j++ ) + printf("\"%s\"", v[j] ); + printf("]"); +} + +template<> void Bu::__tracer_format( void const * const &v ) +{ + printf("0x%08X", (unsigned int)v ); +} + +template<> void Bu::__tracer_format( char const * const &v ) +{ + printf("\"%s\"", v ); +} + +template<> void Bu::__tracer_format( char const ** const &v ) +{ + printf("["); + for( int j = 0; v[j]; j++ ) + printf("\"%s\"", v[j] ); + printf("]"); +} -- cgit v1.2.3