~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to gears/base/common/basictypes.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2006, Google Inc.
 
2
//
 
3
// Redistribution and use in source and binary forms, with or without 
 
4
// modification, are permitted provided that the following conditions are met:
 
5
//
 
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.
 
14
//
 
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.
 
25
 
 
26
#ifndef GEARS_BASE_COMMON_BASICTYPES_H__
 
27
#define GEARS_BASE_COMMON_BASICTYPES_H__
 
28
 
 
29
#include <stddef.h>  // for NULL, size_t
 
30
 
 
31
#ifdef _MSC_VER
 
32
#include <float.h>  // for _isnan() on VC++
 
33
#define isnan(x) _isnan(x)  // VC++ uses _isnan() instead of isnan()
 
34
#else
 
35
#include <math.h>  // for isnan() everywhere else
 
36
#endif
 
37
 
 
38
#if BROWSER_WEBKIT
 
39
//------------------------------------------------------------------------------
 
40
// WebKit on OSX
 
41
//------------------------------------------------------------------------------
 
42
#include <WebKit/npapi.h>
 
43
typedef signed char         int8;
 
44
typedef short               int16;
 
45
typedef long long           int64;
 
46
 
 
47
// Unsigned integer types
 
48
typedef unsigned char      uint8;
 
49
typedef unsigned short     uint16;
 
50
typedef unsigned long long uint64;
 
51
#elif BROWSER_FF
 
52
//------------------------------------------------------------------------------
 
53
// BROWSER_FF
 
54
//------------------------------------------------------------------------------
 
55
 
 
56
// For gecko 1.8,
 
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.
 
60
//
 
61
// For gecko 1.9, it got fixed.
 
62
#if BROWSER_FF2 && defined(WIN32) && defined(_WINSOCK2API_)
 
63
typedef int int32;
 
64
#endif  // BROWSER_FF2 && defined(WIN32) && defined(_WINSOCK2API_)
 
65
 
 
66
// NSPR defines these integer types
 
67
#include <gecko_sdk/include/prtypes.h>
 
68
#else
 
69
//------------------------------------------------------------------------------
 
70
// BROWSER_IE || BROWSER_IEMOBILE || BROWSER_NPAPI
 
71
//------------------------------------------------------------------------------
 
72
// Signed integer types
 
73
typedef signed char         int8;
 
74
typedef short               int16;
 
75
typedef int                 int32;
 
76
#ifdef _MSC_VER  //_MSC_VER is defined iff the code is compiled by MSVC
 
77
typedef __int64             int64;
 
78
#else
 
79
typedef long long           int64;
 
80
#endif /* _MSC_VER */
 
81
 
 
82
// Unsigned integer types
 
83
typedef unsigned char      uint8;
 
84
typedef unsigned short     uint16;
 
85
typedef unsigned int       uint32;
 
86
#ifdef _MSC_VER
 
87
typedef unsigned __int64   uint64;
 
88
#else
 
89
typedef unsigned long long uint64;
 
90
#endif /* _MSC_VER */
 
91
 
 
92
#if GEARS_STATIC_LIB
 
93
#include "gears/base/chrome/static_lib.h"
 
94
#endif
 
95
 
 
96
#endif /* BROWSER_* */
 
97
 
 
98
//------------------------------------------------------------------------------
 
99
// Defined for all browsers
 
100
//------------------------------------------------------------------------------
 
101
 
 
102
#ifdef _MSC_VER
 
103
// VC++ long long suffixes
 
104
#define GG_LONGLONG(x) x##I64
 
105
#define GG_ULONGLONG(x) x##UI64
 
106
#else
 
107
#define GG_LONGLONG(x) x##LL
 
108
#define GG_ULONGLONG(x) x##ULL
 
109
#endif /* _MSC_VER */
 
110
 
 
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));
 
123
 
 
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&)
 
129
 
 
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.
 
135
//
 
136
// The expression ARRAYSIZE(a) is a compile-time constant of type
 
137
// size_t.
 
138
//
 
139
// ARRAYSIZE catches a few type errors.  If you see a compiler error
 
140
//
 
141
//   "warning: division by zero in ..."
 
142
//
 
143
// when using ARRAYSIZE, you are (wrongfully) giving it a pointer.
 
144
// You should only use ARRAYSIZE on statically allocated arrays.
 
145
//
 
146
// The following comments are on the implementation details, and can
 
147
// be ignored by the users.
 
148
//
 
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
 
155
// compiling.
 
156
//
 
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.
 
160
//
 
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.
 
166
//
 
167
// Kudos to Jorg Brown for this simple and elegant implementation.
 
168
//
 
169
// - wan 2005-11-16
 
170
// 
 
171
// Starting with Visual C++ 2005, ARRAYSIZE is defined in WinNT.h
 
172
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(OS_WINCE)
 
173
#include <windows.h>
 
174
#else
 
175
#define ARRAYSIZE(a) \
 
176
  ((sizeof(a) / sizeof(*(a))) / \
 
177
   static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
 
178
#endif
 
179
 
 
180
 
 
181
#endif // GEARS_BASE_COMMON_BASICTYPES_H__