• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Basic integer type definitions.
18 
19 #ifndef LIBTEXTCLASSIFIER_UTILS_BASE_INTEGRAL_TYPES_H_
20 #define LIBTEXTCLASSIFIER_UTILS_BASE_INTEGRAL_TYPES_H_
21 
22 #include "utils/base/config.h"
23 
24 namespace libtextclassifier3 {
25 
26 typedef unsigned int uint;
27 typedef unsigned int uint32;
28 typedef unsigned long long uint64;
29 
30 #ifndef SWIG
31 typedef int int32;
32 typedef unsigned char uint8;    // NOLINT
33 typedef signed char int8;       // NOLINT
34 typedef unsigned short uint16;  // NOLINT
35 typedef signed short int16;     // NOLINT
36 
37 // A type to represent a Unicode code-point value. As of Unicode 4.0,
38 // such values require up to 21 bits.
39 // (For type-checking on pointers, make this explicitly signed,
40 // and it should always be the signed version of whatever int32 is.)
41 typedef signed int char32;
42 #endif  // SWIG
43 
44 #ifdef COMPILER_MSVC
45 typedef __int64 int64;
46 #else
47 typedef long long int64;  // NOLINT
48 #endif  // COMPILER_MSVC
49 
50 // Some compile-time assertions that our new types have the intended size.
51 // static_assert exists only since C++11, so we need an ifdef.
52 #ifdef LANG_CXX11
53 static_assert(sizeof(int) == 4, "Our typedefs depend on int being 32 bits");
54 static_assert(sizeof(uint32) == 4, "wrong size");
55 static_assert(sizeof(int32) == 4, "wrong size");
56 static_assert(sizeof(uint8) == 1, "wrong size");
57 static_assert(sizeof(int8) == 1, "wrong size");
58 static_assert(sizeof(uint16) == 2, "wrong size");
59 static_assert(sizeof(int16) == 2, "wrong size");
60 static_assert(sizeof(char32) == 4, "wrong size");
61 static_assert(sizeof(int64) == 8, "wrong size");
62 #endif  // LANG_CXX11
63 
64 // There are still some requirements that we build these headers in
65 // C-compatibility mode. Unfortunately, -Wall doesn't like c-style
66 // casts, and C doesn't know how to read braced-initialization for
67 // integers.
68 #if defined(__cplusplus)
69 const uint16 kuint16max{0xFFFF};
70 const int16 kint16max{0x7FFF};
71 const int16 kint16min{~0x7FFF};
72 const uint32 kuint32max{0xFFFFFFFF};
73 const int32 kint32max{0x7FFFFFFF};
74 #else   // not __cplusplus, this branch exists only for C-compat
75 static const uint16 kuint16max = ((uint16)0xFFFF);
76 static const int16 kint16min = ((int16)~0x7FFF);
77 static const int16 kint16max = ((int16)0x7FFF);
78 static const uint32 kuint32max = ((uint32)0xFFFFFFFF);
79 static const int32 kint32max = ((int32)0x7FFFFFFF);
80 #endif  // __cplusplus
81 
82 }  // namespace libtextclassifier3
83 
84 #endif  // LIBTEXTCLASSIFIER_UTILS_BASE_INTEGRAL_TYPES_H_
85