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 uint32; 27 typedef unsigned long long uint64; 28 29 #ifndef SWIG 30 typedef int int32; 31 typedef unsigned char uint8; // NOLINT 32 typedef unsigned short uint16; // NOLINT 33 34 // A type to represent a Unicode code-point value. As of Unicode 4.0, 35 // such values require up to 21 bits. 36 // (For type-checking on pointers, make this explicitly signed, 37 // and it should always be the signed version of whatever int32 is.) 38 typedef signed int char32; 39 #endif // SWIG 40 41 #ifdef COMPILER_MSVC 42 typedef __int64 int64; 43 #else 44 typedef long long int64; // NOLINT 45 #endif // COMPILER_MSVC 46 47 // Some compile-time assertions that our new types have the intended size. 48 // static_assert exists only since C++11, so we need an ifdef. 49 #ifdef LANG_CXX11 50 static_assert(sizeof(int) == 4, "Our typedefs depend on int being 32 bits"); 51 static_assert(sizeof(uint32) == 4, "wrong size"); 52 static_assert(sizeof(int32) == 4, "wrong size"); 53 static_assert(sizeof(uint8) == 1, "wrong size"); 54 static_assert(sizeof(uint16) == 2, "wrong size"); 55 static_assert(sizeof(char32) == 4, "wrong size"); 56 static_assert(sizeof(int64) == 8, "wrong size"); 57 #endif // LANG_CXX11 58 59 } // namespace libtextclassifier3 60 61 #endif // LIBTEXTCLASSIFIER_UTILS_BASE_INTEGRAL_TYPES_H_ 62