summaryrefslogtreecommitdiff
path: root/Runtime/mecanim/types.h
blob: 088e0cb23d91f89b6ec715207c4f33afb173498d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#pragma once

#include "Runtime/mecanim/defs.h"

// Microsoft is not supporting standard integer type define in C99 <cstdint>
//
#if defined(_MSC_VER) || defined(__GNUC__)

#include <cfloat>
#include <climits>

namespace mecanim
{
//  8-bit types  -----------------------------------------------------------//
# if UCHAR_MAX == 0xff
	typedef signed char     int8_t;
    typedef unsigned char   uint8_t;

	#define INT8_T_MIN CHAR_MIN
	#define INT8_T_MAX CHAR_MAX
	#define UINT8_T_MIN 0
	#define UINT8_T_MAX UCHAR_MAX
# else
#   error defaults not correct; you must hand modify types.h
# endif

//  16-bit types  -----------------------------------------------------------//
# if USHRT_MAX == 0xffff
    typedef short           int16_t;
    typedef unsigned short  uint16_t;

	#define INT16_T_MIN SHRT_MIN
	#define INT16_T_MAX SHRT_MAX
	#define UINT16_T_MIN 0
	#define UINT16_T_MAX USHRT_MAX
# else
#   error defaults not correct; you must hand modify types.h
# endif

//  32-bit types  -----------------------------------------------------------//
#if UINT_MAX == 0xffffffff
    typedef int             int32_t;
    typedef unsigned int    uint32_t;

	#define INT32_T_MIN INT_MIN
	#define INT32_T_MAX INT_MAX
	#define UINT32_T_MIN 0
	#define UINT32_T_MAX UINT_MAX
#elif ULONG_MAX == 0xffffffff
    typedef long            int32_t;
    typedef unsigned long   uint32_t;
	
	#define INT32_T_MIN LONG_MIN
	#define INT32_T_MAX LONG_MAX
	#define UINT32_T_MIN 0
	#define UINT32_T_MAX ULONG_MAX
# else
#   error defaults not correct; you must hand modify types.h
# endif

//  64-bit types  -----------------------------------------------------------//
# if ULLONG_MAX == 0xffffffffffffffff
	typedef long long            int64_t;
    typedef unsigned long long   uint64_t;

	#define INT64_T_MIN LLONG_MIN
	#define INT64_T_MAX LLONG_MAX
	#define UINT64_T_MIN 0
	#define UINT64_T_MAX ULLONG_MAX
# else
//#   error defaults not correct; you must hand modify types.h
	typedef long long            int64_t;
    typedef unsigned long long   uint64_t;
# endif
	//typedef char String[20];
};
#else

#include <cfloat>
#include <climits>
#include <cstdint.h>
namespace mecanim
{
	using std::int8_t;
	using std::uint8_t;
	using std::int16_t;
	using std::uint16_t;
	using std::int32_t;
	using std::uint32_t;
	using std::int64_t;
	using std::uint64_t;

	#define INT8_T_MIN		CHAR_MIN
	#define INT8_T_MAX		CHAR_MAX
	#define UINT8_T_MIN		0
	#define UINT8_T_MAX		UCHAR_MAX

	#define INT16_T_MIN		SHRT_MIN
	#define INT16_T_MAX		SHRT_MAX
	#define UINT16_T_MIN	0
	#define UINT16_T_MAX	USHRT_MAX

# if ULONG_MAX == 0xffffffff
	#define INT32_T_MIN		LONG_MIN
	#define INT32_T_MAX		LONG_MAX
	#define UINT32_T_MIN	0
	#define UINT32_T_MAX	ULONG_MAX
# elif UINT_MAX == 0xffffffff
	#define INT32_T_MIN		INT_MIN
	#define INT32_T_MAX		INT_MAX
	#define UINT32_T_MIN	0
	#define UINT32_T_MAX	UINT_MAX
# else
#   error defaults not correct; you must hand modify types.h
# endif
	#define INT64_T_MIN		LLONG_MIN
	#define INT64_T_MAX		LLONG_MAX
	#define UINT64_T_MIN	0
	#define UINT64_T_MAX	ULLONG_MAX
};

#endif

namespace mecanim
{
	template <typename _Ty> struct BindValue
	{
		typedef _Ty		value_type;

		value_type		mValue;
		uint32_t		mID;
	};

	template <typename _Ty> struct numeric_limits
	{
		typedef _Ty Type;

		// C++ allow us to initialize only a static constant data member if
		// it has an integral or enumeration Type

		// All other specialization cannot have these member, consequently we do provide
		// min/max trait has inline member function for those case.
		static const Type min_value = Type(0);
		static const Type max_value = Type(0); 

		static Type min() { return min_value; }
		static Type max() { return max_value; }
	};

	template<> struct numeric_limits<int32_t>
	{
		typedef int32_t Type;

		static const Type min_value = Type(INT32_T_MIN);
		static const Type max_value = Type(INT32_T_MAX); 

		static Type min() { return min_value; }
		static Type max() { return max_value; }
	};

	template<> struct numeric_limits<uint32_t>
	{
		typedef uint32_t Type;

		static const Type min_value = Type(UINT32_T_MIN);
		static const Type max_value = Type(UINT32_T_MAX); 

		static Type min() { return min_value; }
		static Type max() { return max_value; }
	};

	template<> struct numeric_limits<float>
	{
		typedef float Type;

		static Type min() { return -FLT_MAX; }
		static Type max() { return FLT_MAX; }
	};

	template <std::size_t> struct uint_t;
	template <> struct uint_t<8>  { typedef uint8_t value_type; };
	template <> struct uint_t<16> { typedef uint16_t value_type; };
	template <> struct uint_t<32> { typedef uint32_t value_type; };
	template <> struct uint_t<64> { typedef uint64_t value_type; };

	template <std::size_t> struct int_t;
	template <> struct int_t<8>  { typedef int8_t value_type; };
	template <> struct int_t<16> { typedef int16_t value_type; };
	template <> struct int_t<32> { typedef int32_t value_type; };
	template <> struct int_t<64> { typedef int64_t value_type; };


	template <bool C, typename Ta, typename Tb> class IfThenElse;
	template< typename Ta, typename Tb> class IfThenElse<true, Ta, Tb>
	{
	public:
		typedef Ta result_type;
	};

	template< typename Ta, typename Tb> class IfThenElse<false, Ta, Tb>
	{
	public:
		typedef Tb result_type;
	};

	template<typename T> class is_pointer
	{
	public:
		static const bool value = false;
	};

	template<typename T> class is_pointer<T*>
	{
	public:
		static const bool value = true;
	};


}