type.h revision 74dd654d997383188b37566661cbce34a8b82154
1/* 2 * Copyright 2011 Google Inc. All Rights Reserved. 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#ifndef TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_TYPE_H_ 18#define TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_TYPE_H_ 19 20#include <assert.h> 21 22#if defined (_MSC_VER) && (_MSC_VER < 1600) 23 typedef unsigned char uint8_t; 24 typedef signed char int8_t; 25 typedef unsigned __int16 uint16_t; 26 typedef signed __int16 int16_t; 27 typedef unsigned __int32 uint32_t; 28 typedef signed __int32 int32_t; 29 typedef unsigned __int64 uint64_t; 30 typedef signed __int64 int64_t; 31 // Definitions to avoid ICU redefinition issue 32 #define U_HAVE_INT8_T 1 33 #define U_HAVE_UINT8_T 1 34 #define U_HAVE_INT16_T 1 35 #define U_HAVE_UINT16_T 1 36 #define U_HAVE_INT32_T 1 37 #define U_HAVE_UINT32_T 1 38 #define U_HAVE_INT64_T 1 39 #define U_HAVE_UINT64_T 1 40#else 41 #include <stdint.h> 42#endif 43 44#include <cstddef> 45#include <vector> 46#include <set> 47 48namespace sfntly { 49 50typedef uint8_t byte_t; 51typedef uint16_t word_t; 52typedef uint32_t dword_t; 53typedef uint64_t qword_t; 54 55typedef std::vector<byte_t> ByteVector; 56typedef std::vector<int32_t> IntegerList; 57typedef std::set<int32_t> IntegerSet; 58 59} // namespace sfntly 60 61// Make google3 happy since it prohibits RTTI. 62template<typename To, typename From> 63inline To implicit_cast(From const &f) { 64 return f; 65} 66 67template<typename To, typename From> // use like this: down_cast<T*>(foo); 68inline To down_cast(From* f) { // so we only accept pointers 69 // Ensures that To is a sub-type of From *. This test is here only 70 // for compile-time type checking, and has no overhead in an 71 // optimized build at run-time, as it will be optimized away 72 // completely. 73#if defined (_MSC_VER) 74 #pragma warning(push) 75 #pragma warning(disable:4127) // disable "conditional expression is constant" 76#endif 77 if (false) { 78 implicit_cast<From*, To>(0); 79 } 80#if defined (_MSC_VER) 81 #pragma warning(pop) 82#endif 83 84// The following code is the only place for RTTI. It is done so to allow VC++ 85// to perform additional type checking in DEBUG builds. 86#if defined (_MSC_VER) && !defined(NDEBUG) 87 assert(f == NULL || dynamic_cast<To>(f) != NULL); // RTTI: debug mode only! 88#endif 89 return static_cast<To>(f); 90} 91 92#if !defined(WIN32) 93 #define UNREFERENCED_PARAMETER(p) do { (void)p; } while (0) 94#endif 95 96#endif // TYPOGRAPHY_FONT_SFNTLY_SRC_SFNTLY_PORT_TYPE_H_ 97