/Users/deen/code/yugabyte-db/src/yb/gutil/integral_types.h
Line | Count | Source |
1 | | // Copyright 2010 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // The following only applies to changes made to this file as part of YugaByte development. |
4 | | // |
5 | | // Portions Copyright (c) YugaByte, Inc. |
6 | | // |
7 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
8 | | // in compliance with the License. You may obtain a copy of the License at |
9 | | // |
10 | | // http://www.apache.org/licenses/LICENSE-2.0 |
11 | | // |
12 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
13 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
14 | | // or implied. See the License for the specific language governing permissions and limitations |
15 | | // under the License. |
16 | | // |
17 | | // Basic integer type definitions for various platforms |
18 | | // |
19 | | // This code is compiled directly on many platforms, including client |
20 | | // platforms like Windows, Mac, and embedded systems. Before making |
21 | | // any changes here, make sure that you're not breaking any platforms. |
22 | | // |
23 | | |
24 | | #ifndef BASE_INTEGRAL_TYPES_H_ |
25 | | #define BASE_INTEGRAL_TYPES_H_ |
26 | | |
27 | | #include <inttypes.h> |
28 | | |
29 | | // These typedefs are also defined in base/google.swig. In the |
30 | | // SWIG environment, we use those definitions and avoid duplicate |
31 | | // definitions here with an ifdef. The definitions should be the |
32 | | // same in both files, and ideally be only defined in this file. |
33 | | #ifndef SWIG |
34 | | // Standard typedefs |
35 | | // All Google2 code is compiled with -funsigned-char to make "char" |
36 | | // unsigned. Google2 code therefore doesn't need a "uchar" type. |
37 | | typedef int8_t schar; |
38 | | typedef int8_t int8; |
39 | | typedef int16_t int16; |
40 | | typedef int32_t int32; |
41 | | #ifdef _MSC_VER |
42 | | typedef __int64 int64; |
43 | | #else |
44 | | typedef int64_t int64; |
45 | | #endif /* _MSC_VER */ |
46 | | |
47 | | // NOTE: unsigned types are DANGEROUS in loops and other arithmetical |
48 | | // places. Use the signed types unless your variable represents a bit |
49 | | // pattern (eg a hash value) or you really need the extra bit. Do NOT |
50 | | // use 'unsigned' to express "this value should always be positive"; |
51 | | // use assertions for this. |
52 | | |
53 | | typedef uint8_t uint8; |
54 | | typedef uint16_t uint16; |
55 | | typedef uint32_t uint32; |
56 | | #ifdef _MSC_VER |
57 | | typedef unsigned __int64 uint64; |
58 | | #else |
59 | | typedef uint64_t uint64; |
60 | | #endif /* _MSC_VER */ |
61 | | |
62 | | // A type to represent a Unicode code-point value. As of Unicode 4.0, |
63 | | // such values require up to 21 bits. |
64 | | // (For type-checking on pointers, make this explicitly signed, |
65 | | // and it should always be the signed version of whatever int32 is.) |
66 | | typedef signed int char32; |
67 | | |
68 | | // A type to represent a natural machine word (for e.g. efficiently |
69 | | // scanning through memory for checksums or index searching). Don't use |
70 | | // this for storing normal integers. Ideally this would be just |
71 | | // unsigned int, but our 64-bit architectures use the LP64 model |
72 | | // (http://www.opengroup.org/public/tech/aspen/lp64_wp.htm), hence |
73 | | // their ints are only 32 bits. We want to use the same fundamental |
74 | | // type on all archs if possible to preserve *printf() compatability. |
75 | | typedef unsigned long uword_t; |
76 | | |
77 | | #endif /* SWIG */ |
78 | | |
79 | | // long long macros to be used because gcc and vc++ use different suffixes, |
80 | | // and different size specifiers in format strings |
81 | | #undef GG_LONGLONG |
82 | | #undef GG_ULONGLONG |
83 | | #undef GG_LL_FORMAT |
84 | | |
85 | | #ifdef _MSC_VER /* if Visual C++ */ |
86 | | |
87 | | // VC++ long long suffixes |
88 | | #define GG_LONGLONG(x) x##I64 |
89 | | #define GG_ULONGLONG(x) x##UI64 |
90 | | |
91 | | #else /* not Visual C++ */ |
92 | | |
93 | 3.31k | #define GG_LONGLONG(x) x##LL |
94 | 16.7M | #define GG_ULONGLONG(x) x##ULL |
95 | | |
96 | | #endif // _MSC_VER |
97 | | |
98 | | |
99 | | static const uint8 kuint8max = (( uint8) 0xFF); |
100 | | static const uint16 kuint16max = ((uint16) 0xFFFF); |
101 | | static const uint32 kuint32max = ((uint32) 0xFFFFFFFF); |
102 | | static const uint64 kuint64max = ((uint64) GG_LONGLONG(0xFFFFFFFFFFFFFFFF)); |
103 | | static const int8 kint8min = (( int8) ~0x7F); |
104 | | static const int8 kint8max = (( int8) 0x7F); |
105 | | static const int16 kint16min = (( int16) ~0x7FFF); |
106 | | static const int16 kint16max = (( int16) 0x7FFF); |
107 | | static const int32 kint32min = (( int32) ~0x7FFFFFFF); |
108 | | static const int32 kint32max = (( int32) 0x7FFFFFFF); |
109 | | static const int64 kint64min = (( int64) GG_LONGLONG(~0x7FFFFFFFFFFFFFFF)); |
110 | | static const int64 kint64max = (( int64) GG_LONGLONG(0x7FFFFFFFFFFFFFFF)); |
111 | | |
112 | | // TODO(user): remove this eventually. |
113 | | // No object has kIllegalFprint as its Fingerprint. |
114 | | typedef uint64 Fprint; |
115 | | static const Fprint kIllegalFprint = 0; |
116 | | static const Fprint kMaxFprint = GG_ULONGLONG(0xFFFFFFFFFFFFFFFF); |
117 | | |
118 | | #endif // BASE_INTEGRAL_TYPES_H_ |