1#ifndef __cxxtest__ValueTraits_h__
2#define __cxxtest__ValueTraits_h__
15#ifdef _CXXTEST_OLD_TEMPLATE_SYNTAX
16# define CXXTEST_TEMPLATE_INSTANTIATION
18# define CXXTEST_TEMPLATE_INSTANTIATION template<>
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)
113# define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS) CXXTEST_COPY_TRAITS(CXXTEST_CLASS, const CXXTEST_CLASS)
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
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
213 typedef _CXXTEST_LONGLONG
T;
226 class ValueTraits<
const unsigned _CXXTEST_LONGLONG>
228 typedef unsigned _CXXTEST_LONGLONG
T;
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];
343#ifdef _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;
#define CXXTEST_COPY_TRAITS(CXXTEST_NEW_CLASS, CXXTEST_OLD_CLASS)
#define CXXTEST_TEMPLATE_INSTANTIATION
#define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS)
#define CXXTEST_NON_NEGATIVE(Type)
const CanonicalForm CFMap CFMap & N
const char * asString(void) const
ValueTraits(const bool value)
const char * asString(void) const
char * doNegative(double &t)
const char * asString(void) const
void normalNumber(double t)
char * doubleToString(double t, char *s, unsigned skip=0, unsigned max=(unsigned) -1)
void hugeNumber(double t)
static unsigned requiredDigitsOnLeft(double t)
const char * asString(void) const
const char * asString(void) const
char _asString[sizeof("{ ")+sizeof("XX ") *MAX_BYTES+sizeof("... }")]
const char * asString(void) const
static int max(int a, int b)
char N unsigned skipDigits
bool stringsEqual(const char *s1, const char *s2)
const char * byteToHex(unsigned char byte)
char digitToChar(unsigned digit)
ValueTraits< T > traits(T t)
char * copyString(char *dst, const char *src)
char N unsigned unsigned maxDigits
char * charToString(unsigned long c, char *s)
char * bytesToString(const unsigned char *bytes, unsigned numBytes, unsigned maxBytes, char *s)