What's new? | Help | Directory | Sign in
Google
             
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
// Copyright 2006, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GEARS_BASE_COMMON_BASICTYPES_H__
#define GEARS_BASE_COMMON_BASICTYPES_H__

#include <stddef.h> // for NULL, size_t

#ifdef _MSC_VER
#include <float.h> // for _isnan() on VC++
#define isnan(x) _isnan(x) // VC++ uses _isnan() instead of isnan()
#else
#include <math.h> // for isnan() everywhere else
#endif

#if BROWSER_WEBKIT
//------------------------------------------------------------------------------
// WebKit on OSX
//------------------------------------------------------------------------------
#include <WebKit/npapi.h>
typedef signed char int8;
typedef short int16;
typedef long long int64;

// Unsigned integer types
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long long uint64;
#elif BROWSER_FF
//------------------------------------------------------------------------------
// BROWSER_FF
//------------------------------------------------------------------------------

// For gecko 1.8,
// prtypes.h (really gecko_sdk/include/obsolete/protypes.h) defines int32
// except when _WINSOCK2API_ is defined because it incorrectly says that
// winsock defines int32. To fix problem, we define int32 for this case.
//
// For gecko 1.9, it got fixed.
#if BROWSER_FF2 && defined(WIN32) && defined(_WINSOCK2API_)
typedef int int32;
#endif // BROWSER_FF2 && defined(WIN32) && defined(_WINSOCK2API_)

// NSPR defines these integer types
#include <gecko_sdk/include/prtypes.h>
#else
//------------------------------------------------------------------------------
// BROWSER_IE || BROWSER_NPAPI
//------------------------------------------------------------------------------
// Signed integer types
typedef signed char int8;
typedef short int16;
typedef int int32;
#ifdef _MSC_VER //_MSC_VER is defined iff the code is compiled by MSVC
typedef __int64 int64;
#else
typedef long long int64;
#endif /* _MSC_VER */

// Unsigned integer types
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
#ifdef _MSC_VER
typedef unsigned __int64 uint64;
#else
typedef unsigned long long uint64;
#endif /* _MSC_VER */
#endif /* BROWSER_* */

//------------------------------------------------------------------------------
// Defined for all browsers
//------------------------------------------------------------------------------

#ifdef _MSC_VER
// VC++ long long suffixes
#define GG_LONGLONG(x) x##I64
#define GG_ULONGLONG(x) x##UI64
#else
#define GG_LONGLONG(x) x##LL
#define GG_ULONGLONG(x) x##ULL
#endif /* _MSC_VER */

const uint8 kuint8max = (( uint8) 0xFF);
const uint16 kuint16max = ((uint16) 0xFFFF);
const uint32 kuint32max = ((uint32) 0xFFFFFFFF);
const uint64 kuint64max = ((uint64) GG_ULONGLONG(0xFFFFFFFFFFFFFFFF));
const int8 kint8min = (( int8) 0x80);
const int8 kint8max = (( int8) 0x7F);
const int16 kint16min = (( int16) 0x8000);
const int16 kint16max = (( int16) 0x7FFF);
const int32 kint32min = (( int32) 0x80000000);
const int32 kint32max = (( int32) 0x7FFFFFFF);
const int64 kint64min = (( int64) GG_LONGLONG(0x8000000000000000));
const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF));

// A macro to disallow the evil copy constructor and operator= functions.
// This should be used in the private: declaration for a class.
#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)

// ARRAYSIZE performs essentially the same calculation as arraysize,
// but can be used on anonymous types or types defined inside
// functions. It's less safe than arraysize as it accepts some
// (although not all) pointers. Therefore, you should use arraysize
// whenever possible.
//
// The expression ARRAYSIZE(a) is a compile-time constant of type
// size_t.
//
// ARRAYSIZE catches a few type errors. If you see a compiler error
//
// "warning: division by zero in ..."
//
// when using ARRAYSIZE, you are (wrongfully) giving it a pointer.
// You should only use ARRAYSIZE on statically allocated arrays.
//
// The following comments are on the implementation details, and can
// be ignored by the users.
//
// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in
// the array) and sizeof(*(arr)) (the # of bytes in one array
// element). If the former is divisible by the latter, perhaps arr is
// indeed an array, in which case the division result is the # of
// elements in the array. Otherwise, arr cannot possibly be an array,
// and we generate a compiler error to prevent the code from
// compiling.
//
// Since the size of bool is implementation-defined, we need to cast
// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final
// result has type size_t.
//
// This macro is not perfect as it wrongfully accepts certain
// pointers, namely where the pointer size is divisible by the pointee
// size. Since all our code has to go through a 32-bit compiler,
// where a pointer is 4 bytes, this means all pointers to a type whose
// size is 3 or greater than 4 will be (righteously) rejected.
//
// Kudos to Jorg Brown for this simple and elegant implementation.
//
// - wan 2005-11-16
//
// Starting with Visual C++ 2005, ARRAYSIZE is defined in WinNT.h
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(WINCE)
#include <windows.h>
#else
#define ARRAYSIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
#endif


#endif // GEARS_BASE_COMMON_BASICTYPES_H__
Show details Hide details

Change log

r2132 by gears.daemon on Jun 26, 2008   Diff
[Author: levin]

Fix windows build.

PRESUBMIT=passed
R=jripley
CC=gears-eng@googlegroups.com
DELTA=17  (13 added, 0 deleted, 4 changed)
OCL=7551466
SCL=7552159
Go to: 
Project members, sign in to write a code review

Older revisions

r1354 by gears.daemon on Apr 11, 2008   Diff
[Author: cprince]

Adds support for OS-specific (browser-
agnostic) EXE targets.
Also adds a small tool to help measure
...
All revisions of this file

File info

Size: 7058 bytes, 176 lines