• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdint.h>
21 
22 #include <cassert>
23 #include <cstddef>
24 #include <set>
25 #include <vector>
26 
27 namespace sfntly {
28 
29 // deprecated
30 typedef uint8_t   byte_t;
31 typedef uint16_t  word_t;
32 typedef uint32_t  dword_t;
33 typedef uint64_t  qword_t;
34 typedef std::vector<uint8_t> ByteVector;
35 typedef std::vector<int32_t> IntegerList;
36 typedef std::set<int32_t> IntegerSet;
37 
38 // A macro to disallow the copy constructor and operator= functions.
39 // This should be used in the private: declarations for a class.
40 #define NO_COPY_AND_ASSIGN(TypeName) \
41   TypeName(const TypeName&);               \
42   void operator=(const TypeName&)
43 
44 }  // namespace sfntly
45 
46 // Make google3 happy since it prohibits RTTI.
47 template<typename To, typename From>
implicit_cast(From const & f)48 inline To implicit_cast(From const &f) {
49   return f;
50 }
51 
52 template<typename To, typename From>     // use like this: down_cast<T*>(foo);
down_cast(From * f)53 inline To down_cast(From* f) {                   // so we only accept pointers
54   // Ensures that To is a sub-type of From *.  This test is here only
55   // for compile-time type checking, and has no overhead in an
56   // optimized build at run-time, as it will be optimized away
57   // completely.
58 #if defined (_MSC_VER)
59   #pragma warning(push)
60   #pragma warning(disable:4127)  // disable "conditional expression is constant"
61 #endif
62   if (false) {
63     implicit_cast<From*, To>(0);
64   }
65 #if defined (_MSC_VER)
66   #pragma warning(pop)
67 #endif
68 
69 // The following code is the only place for RTTI.  It is done so to allow
70 // additional type checking when SFNTLY_TYPE_VERIFICATION is defined.
71 #if defined (SFNTLY_TYPE_VERIFICATION)
72   assert(f == NULL || dynamic_cast<To>(f) != NULL);
73 #endif
74   return static_cast<To>(f);
75 }
76 
77 #if !defined(WIN32)
78   #define UNREFERENCED_PARAMETER(p) do { (void)p; } while (0)
79 #endif
80 
81 #endif  // SFNTLY_CPP_SRC_SFNTLY_PORT_TYPE_H_
82