1 #ifndef __cxxtest__ValueTraits_h__ 2 #define __cxxtest__ValueTraits_h__ 15 #ifdef _CXXTEST_OLD_TEMPLATE_SYNTAX 16 # define CXXTEST_TEMPLATE_INSTANTIATION 17 #else // !_CXXTEST_OLD_TEMPLATE_SYNTAX 18 # define CXXTEST_TEMPLATE_INSTANTIATION template<> 19 #endif // _CXXTEST_OLD_TEMPLATE_SYNTAX 26 # define TS_AS_STRING(x) CxxTest::traits(x).asString() 37 const char *
byteToHex(
unsigned char byte );
43 char *
bytesToString(
const unsigned char *bytes,
unsigned numBytes,
unsigned maxBytes,
char *
s );
50 char *
copyString(
char *dst,
const char *src );
97 # define CXXTEST_COPY_TRAITS(CXXTEST_NEW_CLASS, CXXTEST_OLD_CLASS) \ 98 CXXTEST_TEMPLATE_INSTANTIATION \ 99 class ValueTraits< CXXTEST_NEW_CLASS > \ 101 ValueTraits< CXXTEST_OLD_CLASS > _old; \ 103 ValueTraits( CXXTEST_NEW_CLASS n ) : _old( (CXXTEST_OLD_CLASS)n ) {} \ 104 const char *asString( void ) const { return _old.asString(); } \ 110 # ifdef _CXXTEST_NO_COPY_CONST 111 # define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS) 112 # else // !_CXXTEST_NO_COPY_CONST 113 # define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS) CXXTEST_COPY_TRAITS(CXXTEST_CLASS, const CXXTEST_CLASS) 114 # endif // _CXXTEST_NO_COPY_CONST 119 template<
class N>
inline bool negative(
N n ) {
return n < 0; }
122 # define CXXTEST_NON_NEGATIVE(Type) \ 123 CXXTEST_TEMPLATE_INSTANTIATION \ 124 inline bool negative<Type>( Type ) { return false; } \ 125 CXXTEST_TEMPLATE_INSTANTIATION \ 126 inline Type abs<Type>( Type value ) { return value; } 133 # ifdef _CXXTEST_LONGLONG 135 # endif // _CXXTEST_LONGLONG 143 char *numberToString(
N n,
char *
s,
154 while ( digit <= (n /
base) )
158 digitValue = (
unsigned)(n / digit);
160 *
s++ =
digitToChar( (
unsigned)(digitValue = (unsigned)(n / digit)) );
171 #ifndef CXXTEST_USER_VALUE_TRAITS 177 class ValueTraits<
const char *
const &>
179 ValueTraits &operator=(
const ValueTraits & );
180 const char *_asString;
183 ValueTraits(
const char *
const &value ) : _asString( value ) {}
184 ValueTraits(
const ValueTraits &other ) : _asString( other._asString ) {}
185 const char *asString(
void )
const {
return _asString; }
201 const char *
asString(
void )
const {
return _value ?
"true" :
"false"; }
206 # ifdef _CXXTEST_LONGLONG 211 class ValueTraits<
const signed _CXXTEST_LONGLONG>
213 typedef _CXXTEST_LONGLONG
T;
226 class ValueTraits<
const unsigned _CXXTEST_LONGLONG>
228 typedef unsigned _CXXTEST_LONGLONG
T;
236 # endif // _CXXTEST_LONGLONG 244 typedef signed long int T;
259 typedef unsigned long int T;
315 ( requiredDigitsOnLeft( t ) > MAX_DIGITS_ON_LEFT ) ?
323 enum { MAX_DIGITS_ON_LEFT = 24, DIGITS_ON_RIGHT = 4, BASE = 10 };
324 char _asString[1 + MAX_DIGITS_ON_LEFT + 1 + DIGITS_ON_RIGHT + 1];
326 static unsigned requiredDigitsOnLeft(
double t );
327 char *doNegative(
double &t );
328 void hugeNumber(
double t );
329 void normalNumber(
double t );
330 char *doubleToString(
double t,
char *
s,
unsigned skip = 0,
unsigned max = (
unsigned)-1 );
340 #endif // !CXXTEST_USER_VALUE_TRAITS 343 #ifdef _CXXTEST_HAVE_STD 345 #endif // _CXXTEST_HAVE_STD 350 #define CXXTEST_ENUM_TRAITS( TYPE, VALUES ) \ 353 CXXTEST_TEMPLATE_INSTANTIATION \ 354 class ValueTraits<TYPE> \ 357 char _fallback[sizeof("(" #TYPE ")") + 3 * sizeof(TYPE)]; \ 359 ValueTraits( TYPE value ) { \ 361 numberToString<unsigned long int>( _value, copyString( _fallback, "(" #TYPE ")" ) ); \ 363 const char *asString( void ) const \ 368 default: return _fallback; \ 374 #define CXXTEST_ENUM_MEMBER( MEMBER ) \ 375 case MEMBER: return #MEMBER; 377 #endif // __cxxtest__ValueTraits_h__ const char * asString(void) const
ValueTraits(const bool value)
ValueTraits< T > traits(T t)
CXXTEST_COPY_CONST_TRAITS(CXXTEST_STD(string))
const char * asString(void) const
char * charToString(unsigned long c, char *s)
char N unsigned unsigned maxDigits
char * copyString(char *dst, const char *src)
const char * asString(void) const
char _asString[sizeof("{ ")+sizeof("XX ") *MAX_BYTES+sizeof("... }")]
bool stringsEqual(const char *s1, const char *s2)
#define CXXTEST_TEMPLATE_INSTANTIATION
char * bytesToString(const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s)
const CanonicalForm CFMap CFMap & N
static int max(int a, int b)
const char * asString(void) const
char N unsigned skipDigits
const char * asString(void) const
const char * byteToHex(unsigned char byte)
CXXTEST_NON_NEGATIVE(bool) CXXTEST_NON_NEGATIVE(unsigned char) CXXTEST_NON_NEGATIVE(unsigned short int) CXXTEST_NON_NEGATIVE(unsigned int) CXXTEST_NON_NEGATIVE(unsigned long int) template< class N > char *numberToString(N n
CXXTEST_COPY_TRAITS(const char *, const char *const &)
const char * asString(void) const
char digitToChar(unsigned digit)