~om26er/ubuntu/oneiric/nux/sru-819721

« back to all changes in this revision

Viewing changes to NuxCore/NSystemTypes.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-11-18 19:17:32 UTC
  • Revision ID: james.westby@ubuntu.com-20101118191732-rn35790vekj6o4my
Tags: upstream-0.9.4
ImportĀ upstreamĀ versionĀ 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of both the GNU Lesser General Public
 
15
 * License version 3 along with this program.  If not, see
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#ifndef SYSTEMTYPES_H
 
24
#define SYSTEMTYPES_H
 
25
 
 
26
#include "Namespace.h"
 
27
 
 
28
namespace nux
 
29
{
 
30
// Note: do not use long: long is 64 bits in LP64 while it remains 32 bits on LLP64
 
31
 
 
32
  typedef unsigned char           t_u8, t_byte, t_uchar;              // 0 to 255
 
33
  typedef char                    t_char;                       // ļæ½128 to 127
 
34
// signed char is a distinct type. See ANSI C Draft Standard and the keyword "signed"
 
35
  typedef signed char             t_s8, t_schar;                            // ļæ½128 to 127
 
36
 
 
37
  typedef unsigned short          t_u16, t_uint16, t_ushort, t_word;  // 0 to 65,535
 
38
  typedef short                   t_s16, t_int16, t_short;            // ļæ½32,768 to 32,767
 
39
 
 
40
  typedef unsigned int            t_u32, t_uint32, t_uint, t_dword;   // 0 to 4,294,967,295
 
41
  typedef int                     t_s32, t_int32, t_int;              // ļæ½2,147,483,648 to 2,147,483,647
 
42
 
 
43
  typedef unsigned long           t_ulong;                            // 0 to 4,294,967,295
 
44
  typedef long                    t_long;                             // ļæ½2,147,483,648 to 2,147,483,647
 
45
 
 
46
  typedef unsigned long long      t_u64, t_uint64, t_qword, t_ulonglong;       // 0 to 18,446,744,073,709,551,615
 
47
  typedef long long               t_s64, t_int64, t_sqword, t_slonglong;       // ļæ½9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
 
48
 
 
49
  typedef float                   t_float, t_f32;                     // 3.4E +/- 38 (7 digits)
 
50
  typedef double                  t_double, t_f64;                    // 1.7E +/- 308 (15 digits)
 
51
 
 
52
  typedef char                    *t_pchar;
 
53
  typedef wchar_t                 t_wchar;
 
54
  typedef unsigned short          t_unicodechar, *t_punicodechar;
 
55
  typedef bool                    t_bool;
 
56
 
 
57
  typedef void                    t_void, *t_pvoid;
 
58
 
 
59
  typedef unsigned char           t_UTF8;
 
60
  typedef unsigned int            t_UTF32;
 
61
#ifdef _WIN32
 
62
  typedef wchar_t             t_UTF16;
 
63
#elif defined(__linux)
 
64
  typedef wchar_t             t_UTF16;
 
65
#elif defined (__APPLE__)
 
66
  typedef wchar_t             t_UTF16;
 
67
#else
 
68
#error t_UTF16 is undefined for this platform.
 
69
#endif
 
70
 
 
71
  typedef std::size_t                  t_size;
 
72
 
 
73
// // HARDWARE
 
74
// #if defined _M_X64
 
75
//     typedef long long       t_integer;      // 64 bits
 
76
//     typedef long long       *t_pointer;     // 64 bits
 
77
//     const   long long       t_MaxInteger = 0xFFFFFFFFFFFFFFFF;
 
78
//     typedef long long       t_saddress;
 
79
//     typedef unsigned long long  t_uaddress;
 
80
// // #elif defined _WIN32
 
81
// //     typedef long           t_integer;   // 32 bits
 
82
// //     typedef long           *t_pointer;   // 32 bits
 
83
// //     const long t_MaxInteger = 0xFFFFFFFF;
 
84
// //     typedef long            t_saddress;
 
85
// //     typedef unsigned long   t_uaddress;
 
86
// #elif defined(__linux) && (defined(__ia64__) || defined(__amd64__))
 
87
//     typedef long long       t_integer;      // 64 bits
 
88
//     typedef long long       *t_pointer;     // 64 bits
 
89
//     const   long long       t_MaxInteger = 0xFFFFFFFFFFFFFFFF;
 
90
// #elif defined __linux
 
91
//     typedef long            t_integer;      // 32 bits
 
92
//     typedef long            *t_pointer;     // 32 bits
 
93
//     const   long            t_MaxInteger = 0xFFFFFFFF;
 
94
// #elif defined __APPLE__
 
95
//     typedef long long       t_integer;      // 64 bits
 
96
//     typedef long long       *t_pointer;     // 64 bits
 
97
//     const   long long       t_MaxInteger = 0xFFFFFFFFFFFFFFFF;
 
98
// #endif
 
99
 
 
100
 
 
101
 
 
102
 
 
103
// Compile Time
 
104
#if defined(__LP64__) || defined(_LP64) || defined(_WIN64)
 
105
  typedef long long           t_saddress;
 
106
  typedef unsigned long long  t_uaddress;
 
107
  typedef t_u64               NUX_POINTER;
 
108
  typedef long long           t_integer;
 
109
#else
 
110
  typedef int                 t_saddress;
 
111
  typedef unsigned int        t_uaddress;
 
112
  typedef t_uint32            NUX_POINTER;
 
113
  typedef long                t_integer;
 
114
#endif
 
115
 
 
116
  typedef unsigned long            t_addressu32;
 
117
  typedef unsigned long long       t_addressu64;
 
118
 
 
119
#define NUX_ADDRESS_TO_PTR(addr) (void*)(addr)
 
120
#define NUX_PTR_TO_ADDRESS(ptr)  (t_uaddress)(ptr)
 
121
 
 
122
  const t_s8  t_s8_min          =  -128;
 
123
  const t_s8  t_s8_max          =  127;
 
124
  const t_u8  t_u8_min          =  0;
 
125
  const t_u8  t_u8_max          =  255;
 
126
  const t_s16 t_s16_min         =  -32768;
 
127
  const t_s16 t_s16_max         =  32767;
 
128
  const t_u16 t_u16_min         =  0;
 
129
  const t_u16 t_u16_max         =  65535;
 
130
  const t_s32 t_s32_min         =  0x80000000;
 
131
  const t_s32 t_s32_max         =  0x7FFFFFFF;
 
132
  const t_u32 t_u32_min         =  0x00000000;
 
133
  const t_u32 t_u32_max         =  0xFFFFFFFF;
 
134
  const t_s64 t_s64_min         =  0x8000000000000000LL;
 
135
  const t_s64 t_s64_max         =  0x7FFFFFFFFFFFFFFFLL;
 
136
  const t_u64 t_u64_min         =  0x0000000000000000ULL;
 
137
  const t_u64 t_u64_max         =  0xFFFFFFFFFFFFFFFFULL;
 
138
 
 
139
  const t_f32 t_f32_min       =  1.175494351E-38F;
 
140
  const t_f32 t_f32_max         =  3.402823466E+38F;
 
141
  const t_f64 t_f64_min       =  2.2250738585072014E-308;
 
142
  const t_f64 t_f64_max         =  1.7976931348623158E+308;
 
143
 
 
144
  const t_f32 MinFloat        =  1.175494351E-38F;
 
145
  const t_f32 MaxFloat          =  3.402823466E+38F;
 
146
  const t_f64 MinDouble       =  2.2250738585072014E-308;
 
147
  const t_f64 MaxDouble         =  1.7976931348623158E+308;
 
148
 
 
149
//             ILP32    LP64    LLP64   ILP64
 
150
// char         8       8       8       8
 
151
// short            16      16      16      16
 
152
// int          32          32      32      64
 
153
// long         32      64      32      64
 
154
// long long    64          64      64      64
 
155
// pointer          32      64      64      64
 
156
 
 
157
// Window 64-bit supports LLP64
 
158
// Linux 64 bit  supports LP64
 
159
// Mac OS 64 bit  supports LP64
 
160
 
 
161
// The size of  a long integer in particular depends on the operating system and the targeted architecture as follows:
 
162
//
 
163
// OS           arch           size
 
164
// Windows       IA-32        4 bytes
 
165
// Windows       Intel 64     4 bytes
 
166
// Windows       IA-64        4 bytes
 
167
// Linux         IA-32        4 bytes
 
168
// Linux         Intel 64     8 bytes
 
169
// Linux         IA-64        8 bytes
 
170
// Mac OS X      IA-32        4 bytes
 
171
// Mac OS X      Intel 64     8 bytes
 
172
 
 
173
#ifdef _WIN32
 
174
    #define NUX_PTR_TO_INT(ptr) (long)((long)(ptr))
 
175
#elif  _WIN64
 
176
    #define NUX_PTR_TO_INT(ptr) (long long)((long long)(ptr))
 
177
#elif __linux
 
178
    #define NUX_PTR_TO_INT(ptr) (long)((long)(ptr))
 
179
#elif defined(__linux) && (defined(__ia64__) || defined(__amd64__))
 
180
    #define NUX_PTR_TO_INT(ptr) (long long)((long long)(ptr))
 
181
#elif __APPLE__
 
182
    #define NUX_PTR_TO_INT(ptr) (long long)((long long)(ptr))
 
183
#endif
 
184
 
 
185
#define NUX_BYTE_SIZE   1
 
186
#define NUX_WORD_SIZE   2
 
187
#define NUX_FLOAT_SIZE  4
 
188
#define NUX_INT_SIZE    4
 
189
#define NUX_DOUBLE_SIZE 8
 
190
 
 
191
// Polymorphic Types
 
192
#if defined(_WIN32) || defined(_WIN64)
 
193
    #define NUX_PTRSIZE_INT     INT_PTR
 
194
    #define NUX_PTRSIZE_UINT    UINT_PTR
 
195
    #define NUX_PTRSIZE_DWORD   DWORD_PTR
 
196
    #define NUX_PTRSIZE_LONG    LONG_PTR
 
197
    #define NUX_PTRSIZE_ULONG   ULONG_PTR
 
198
    #define NUX_SIZE_T          SIZE_T
 
199
    #define NUX_SSIZE_T         SSIZE_T
 
200
#else
 
201
    #define NUX_PTRSIZE_INT     int
 
202
    #define NUX_PTRSIZE_UINT    unsigned int
 
203
    #define NUX_PTRSIZE_DWORD   unsigned int
 
204
    #define NUX_PTRSIZE_LONG    long
 
205
    #define NUX_PTRSIZE_ULONG   unsigned long
 
206
    #define NUX_SIZE_T          size_t
 
207
    #define NUX_SSIZE_T         int
 
208
#endif
 
209
 
 
210
 
 
211
 
 
212
// #ifdef _WIN32
 
213
//     #define NUX_HARDWARE_BREAK __asm {int 3}
 
214
//     #define NUX_BREAK_ASM_INT3 __asm {int 3}
 
215
// #else
 
216
//     #define NUX_HARDWARE_BREAK
 
217
//     #define NUX_BREAK_ASM_INT3
 
218
// #endif
 
219
 
 
220
#define DEGTORAD(d) (d) * 3.1415927f / 180.0f
 
221
#define RADTODEG(d) (d) * 180.0f / 3.1415927f
 
222
 
 
223
 
 
224
}
 
225
#endif // SYSTEMTYPES_H
 
226
 
 
227
/*
 
228
 
 
229
 C/C++ recognizes the types shown in the table below.
 
230
 
 
231
Type Name               Bytes               Other Names                         Range of Values
 
232
________________________________________________________________________________________________________________________________
 
233
int                     *                   signed,
 
234
                                            signed int                          System dependent
 
235
 
 
236
unsigned int            *                   unsigned                            System dependent
 
237
 
 
238
__int8                  1                   char,
 
239
                                            signed char                         -128 to 127
 
240
 
 
241
__int16                 2                   short,
 
242
                                            short int,
 
243
                                            signed short int                    -32768 to 32767
 
244
 
 
245
__int32                 4                   signed,
 
246
                                            signed int                          -2,147,483,648 to 2,147,483,647
 
247
 
 
248
__int64                 8                   none                                -9,223,372,036,854,775,808
 
249
                                                                                 to 9,223,372,036,854,775,807
 
250
 
 
251
char                    1                   signed char                         -128 to 127
 
252
 
 
253
unsigned char           1                   none                                0 to 255
 
254
 
 
255
short                   2                   short int,
 
256
                                            signed short int                    -32,768 to 32,767
 
257
 
 
258
unsigned short          2                   unsigned short int                  0 to 65,535
 
259
 
 
260
long                    4                   long int,
 
261
                                            signed long int                     -2,147,483,648 to 2,147,483,647
 
262
 
 
263
unsigned long           4                   unsigned long int                   0 to 4,294,967,295
 
264
 
 
265
enum                    *                   none                                Same as int
 
266
 
 
267
float                   4                   none                                3.4E +/- 38 (7 digits)
 
268
 
 
269
double                  8                   none                                1.7E +/- 308 (15 digits)
 
270
 
 
271
long double             10                  none                                1.2E +/- 4932 (19 digits)
 
272
 
 
273
 
 
274
 
 
275
*: OS dependant
 
276
 
 
277
*/