1
// Copyright 2006, Google Inc.
3
// Redistribution and use in source and binary forms, with or without
4
// modification, are permitted provided that the following conditions are met:
6
// 1. Redistributions of source code must retain the above copyright notice,
7
// this list of conditions and the following disclaimer.
8
// 2. Redistributions in binary form must reproduce the above copyright notice,
9
// this list of conditions and the following disclaimer in the documentation
10
// and/or other materials provided with the distribution.
11
// 3. Neither the name of Google Inc. nor the names of its contributors may be
12
// used to endorse or promote products derived from this software without
13
// specific prior written permission.
15
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
#ifndef GEARS_BASE_COMMON_BASICTYPES_H__
27
#define GEARS_BASE_COMMON_BASICTYPES_H__
29
#include <stddef.h> // for NULL, size_t
32
#include <float.h> // for _isnan() on VC++
33
#define isnan(x) _isnan(x) // VC++ uses _isnan() instead of isnan()
35
#include <math.h> // for isnan() everywhere else
39
//------------------------------------------------------------------------------
41
//------------------------------------------------------------------------------
42
#include <WebKit/npapi.h>
43
typedef signed char int8;
45
typedef long long int64;
47
// Unsigned integer types
48
typedef unsigned char uint8;
49
typedef unsigned short uint16;
50
typedef unsigned long long uint64;
52
//------------------------------------------------------------------------------
54
//------------------------------------------------------------------------------
57
// prtypes.h (really gecko_sdk/include/obsolete/protypes.h) defines int32
58
// except when _WINSOCK2API_ is defined because it incorrectly says that
59
// winsock defines int32. To fix problem, we define int32 for this case.
61
// For gecko 1.9, it got fixed.
62
#if BROWSER_FF2 && defined(WIN32) && defined(_WINSOCK2API_)
64
#endif // BROWSER_FF2 && defined(WIN32) && defined(_WINSOCK2API_)
66
// NSPR defines these integer types
67
#include <gecko_sdk/include/prtypes.h>
69
//------------------------------------------------------------------------------
70
// BROWSER_IE || BROWSER_IEMOBILE || BROWSER_NPAPI
71
//------------------------------------------------------------------------------
72
// Signed integer types
73
typedef signed char int8;
76
#ifdef _MSC_VER //_MSC_VER is defined iff the code is compiled by MSVC
77
typedef __int64 int64;
79
typedef long long int64;
82
// Unsigned integer types
83
typedef unsigned char uint8;
84
typedef unsigned short uint16;
85
typedef unsigned int uint32;
87
typedef unsigned __int64 uint64;
89
typedef unsigned long long uint64;
93
#include "gears/base/chrome/static_lib.h"
96
#endif /* BROWSER_* */
98
//------------------------------------------------------------------------------
99
// Defined for all browsers
100
//------------------------------------------------------------------------------
103
// VC++ long long suffixes
104
#define GG_LONGLONG(x) x##I64
105
#define GG_ULONGLONG(x) x##UI64
107
#define GG_LONGLONG(x) x##LL
108
#define GG_ULONGLONG(x) x##ULL
109
#endif /* _MSC_VER */
111
const uint8 kuint8max = (( uint8) 0xFF);
112
const uint16 kuint16max = ((uint16) 0xFFFF);
113
const uint32 kuint32max = ((uint32) 0xFFFFFFFF);
114
const uint64 kuint64max = ((uint64) GG_ULONGLONG(0xFFFFFFFFFFFFFFFF));
115
const int8 kint8min = (( int8) 0x80);
116
const int8 kint8max = (( int8) 0x7F);
117
const int16 kint16min = (( int16) 0x8000);
118
const int16 kint16max = (( int16) 0x7FFF);
119
const int32 kint32min = (( int32) 0x80000000);
120
const int32 kint32max = (( int32) 0x7FFFFFFF);
121
const int64 kint64min = (( int64) GG_LONGLONG(0x8000000000000000));
122
const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF));
124
// A macro to disallow the evil copy constructor and operator= functions.
125
// This should be used in the private: declaration for a class.
126
#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
127
TypeName(const TypeName&); \
128
void operator=(const TypeName&)
130
// ARRAYSIZE performs essentially the same calculation as arraysize,
131
// but can be used on anonymous types or types defined inside
132
// functions. It's less safe than arraysize as it accepts some
133
// (although not all) pointers. Therefore, you should use arraysize
134
// whenever possible.
136
// The expression ARRAYSIZE(a) is a compile-time constant of type
139
// ARRAYSIZE catches a few type errors. If you see a compiler error
141
// "warning: division by zero in ..."
143
// when using ARRAYSIZE, you are (wrongfully) giving it a pointer.
144
// You should only use ARRAYSIZE on statically allocated arrays.
146
// The following comments are on the implementation details, and can
147
// be ignored by the users.
149
// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in
150
// the array) and sizeof(*(arr)) (the # of bytes in one array
151
// element). If the former is divisible by the latter, perhaps arr is
152
// indeed an array, in which case the division result is the # of
153
// elements in the array. Otherwise, arr cannot possibly be an array,
154
// and we generate a compiler error to prevent the code from
157
// Since the size of bool is implementation-defined, we need to cast
158
// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final
159
// result has type size_t.
161
// This macro is not perfect as it wrongfully accepts certain
162
// pointers, namely where the pointer size is divisible by the pointee
163
// size. Since all our code has to go through a 32-bit compiler,
164
// where a pointer is 4 bytes, this means all pointers to a type whose
165
// size is 3 or greater than 4 will be (righteously) rejected.
167
// Kudos to Jorg Brown for this simple and elegant implementation.
171
// Starting with Visual C++ 2005, ARRAYSIZE is defined in WinNT.h
172
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(OS_WINCE)
175
#define ARRAYSIZE(a) \
176
((sizeof(a) / sizeof(*(a))) / \
177
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
181
#endif // GEARS_BASE_COMMON_BASICTYPES_H__