11
// Number of elements in an array.
12
#define INL_ARRAY_COUNT( array ) \
13
( sizeof(array) / sizeof((array)[0]) )
16
// -----------------------------------------------------------------------------
18
// -----------------------------------------------------------------------------
21
template <typename U> struct VoidTraits
25
// Full specialization of template <typename T> NTraitIsVoid
26
template <> struct VoidTraits<void>
32
template <typename U> struct PointerTraits
36
// Partial specialization
37
template <typename U> struct PointerTraits<U*>
42
template <typename U> struct UnicodeCharTraits
47
template <> struct UnicodeCharTraits<wchar_t>
52
template <typename U> struct AnsiCharTraits
57
template <> struct AnsiCharTraits<char>
62
// Base type information for atomic types which pass by value.
64
class TypeTraitsNoConstructor
67
typedef T ConstInitType;
68
enum { HasConstructor = 0 };
69
enum { HasDestructor = 0 };
72
// Base type information for constructed types which pass by reference.
74
class TypeTraitsConstructor
77
typedef const T& ConstInitType;
78
enum { HasConstructor = 1 };
79
enum { HasDestructor = 1 };
83
// The default behaviour is for types to behave as constructed types.
85
class ConstructorTraits : public TypeTraitsConstructor<T>{};
87
// Pointers don't have a constructor.
89
class ConstructorTraits<T*>: public TypeTraitsNoConstructor<T*> {};
91
template <> class ConstructorTraits<bool> : public TypeTraitsNoConstructor<bool> {};
92
template <> class ConstructorTraits<char> : public TypeTraitsNoConstructor<char> {};
93
template <> class ConstructorTraits<unsigned char> : public TypeTraitsNoConstructor<unsigned char> {};
94
template <> class ConstructorTraits<short> : public TypeTraitsNoConstructor<short> {};
95
template <> class ConstructorTraits<unsigned short> : public TypeTraitsNoConstructor<unsigned short> {};
96
template <> class ConstructorTraits<int> : public TypeTraitsNoConstructor<int> {};
97
template <> class ConstructorTraits<unsigned int> : public TypeTraitsNoConstructor<unsigned int> {};
98
template <> class ConstructorTraits<long> : public TypeTraitsNoConstructor<long> {};
99
template <> class ConstructorTraits<unsigned long> : public TypeTraitsNoConstructor<unsigned long> {};
100
template <> class ConstructorTraits<long long> : public TypeTraitsNoConstructor<long long> {};
101
template <> class ConstructorTraits<unsigned long long> : public TypeTraitsNoConstructor<unsigned long long> {};
102
template <> class ConstructorTraits<float> : public TypeTraitsNoConstructor<float> {};
103
template <> class ConstructorTraits<double> : public TypeTraitsNoConstructor<double> {};
111
enum { IsVoid = VoidTraits<T>::result };
112
enum { IsPointer = PointerTraits<T>::result };
113
enum { NeedsConstructor = ConstructorTraits<T>::HasConstructor };
114
enum { NeedsDestructor = ConstructorTraits<T>::HasDestructor };
115
enum { IsAnsiChar = AnsiCharTraits<T>::result };
116
enum { IsUnicodeChar = UnicodeCharTraits<T>::result };
119
template <typename T>
120
struct RemovePointerFromType
123
template <typename T>
124
struct RemovePointerFromType<T*>
128
template <typename T>
129
struct RemovePointerFromType<const T*>
133
template <typename T>
134
struct RemovePointerFromType<volatile T*>
138
template <typename T>
139
struct RemovePointerFromType<const volatile T*>
144
// Determining if an integer is a power of 2
145
// http://graphics.stanford.edu/~seander/bithacks.html
148
// From: http://www.jb.man.ac.uk/~slowe/cpp/itoa.html
149
// John Maloney has pointed out various problems with the previous implementation.
150
// One of the major issues was the amount of heap allocation going on.
151
// He suggested that a lot of this be removed to speed up the algorithm.
152
// Below are two versions based on his excellent suggestions. The char* version
153
// is at least 10 times faster than the code above. The new std::string version
154
// is 3 times faster than before. Although the char* version is faster, you should
155
// check that you have allocated enough space to hold the output.
157
// C++ version std::string style "itoa":
158
tstring IntegerToChar(int value, int base);
159
// C++ version char* style "itoa":
160
TCHAR* IntegerToChar( int value, TCHAR* result, int base );
162
// convert an hexadecimal TCHAR to t_u32 // i.e. "0x0000000f" to 15
163
t_u32 HexCharToInteger(const TCHAR* s);
164
// convert a TCHAR to INT
165
BOOL CharToInteger(const TCHAR* digit, INT& ret);
166
int CharToInteger(const TCHAR* digit);
169
// convert a TCHAR to double
170
BOOL CharToDouble(const TCHAR* digit, double& ret);
171
double CharToDouble(const TCHAR* digit);
173
// convert a TCHAR to float
174
BOOL CharToFloat(const TCHAR* digit, float& ret);
175
float CharToFloat(const TCHAR* digit);
177
TCHAR* DoubleToChar(double d);
181
#endif // NTEMPLATE_H