Home | History | Annotate | Download | only in port
      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 SFNTLY_CPP_SRC_SFNTLY_PORT_TYPE_H_
     18 #define SFNTLY_CPP_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 
     48 namespace sfntly {
     49 
     50 typedef uint8_t   byte_t;
     51 typedef uint16_t  word_t;
     52 typedef uint32_t  dword_t;
     53 typedef uint64_t  qword_t;
     54 
     55 typedef std::vector<byte_t> ByteVector;
     56 typedef std::vector<int32_t> IntegerList;
     57 typedef std::set<int32_t> IntegerSet;
     58 
     59 // A macro to disallow the copy constructor and operator= functions.
     60 // This should be used in the private: declarations for a class.
     61 #define NO_COPY_AND_ASSIGN(TypeName) \
     62   TypeName(const TypeName&);               \
     63   void operator=(const TypeName&)
     64 
     65 }  // namespace sfntly
     66 
     67 // Make google3 happy since it prohibits RTTI.
     68 template<typename To, typename From>
     69 inline To implicit_cast(From const &f) {
     70   return f;
     71 }
     72 
     73 template<typename To, typename From>     // use like this: down_cast<T*>(foo);
     74 inline To down_cast(From* f) {                   // so we only accept pointers
     75   // Ensures that To is a sub-type of From *.  This test is here only
     76   // for compile-time type checking, and has no overhead in an
     77   // optimized build at run-time, as it will be optimized away
     78   // completely.
     79 #if defined (_MSC_VER)
     80   #pragma warning(push)
     81   #pragma warning(disable:4127)  // disable "conditional expression is constant"
     82 #endif
     83   if (false) {
     84     implicit_cast<From*, To>(0);
     85   }
     86 #if defined (_MSC_VER)
     87   #pragma warning(pop)
     88 #endif
     89 
     90 // The following code is the only place for RTTI.  It is done so to allow
     91 // additional type checking when SFNTLY_TYPE_VERIFICATION is defined.
     92 #if defined (SFNTLY_TYPE_VERIFICATION)
     93   assert(f == NULL || dynamic_cast<To>(f) != NULL);
     94 #endif
     95   return static_cast<To>(f);
     96 }
     97 
     98 #if !defined(WIN32)
     99   #define UNREFERENCED_PARAMETER(p) do { (void)p; } while (0)
    100 #endif
    101 
    102 #endif  // SFNTLY_CPP_SRC_SFNTLY_PORT_TYPE_H_
    103