]> git.sesse.net Git - casparcg/blob - dependencies64/cef/include/base/cef_template_util.h
* Merged html producer and updated to latest CEF version (does not have satisfactory...
[casparcg] / dependencies64 / cef / include / base / cef_template_util.h
1 // Copyright (c) 2014 Marshall A. Greenblatt. Portions copyright (c) 2011
2 // Google Inc. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //    * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //    * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //    * Neither the name of Google Inc. nor the name Chromium Embedded
15 // Framework nor the names of its contributors may be used to endorse
16 // or promote products derived from this software without specific prior
17 // written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #ifndef CEF_INCLUDE_BASE_CEF_TEMPLATE_UTIL_H_
32 #define CEF_INCLUDE_BASE_CEF_TEMPLATE_UTIL_H_
33 #pragma once
34
35 #if defined(BASE_TEMPLATE_UTIL_H_)
36 // Do nothing if the Chromium header has already been included.
37 // This can happen in cases where Chromium code is used directly by the
38 // client application. When using Chromium code directly always include
39 // the Chromium header first to avoid type conflicts.
40 #elif defined(BUILDING_CEF_SHARED)
41 // When building CEF include the Chromium header directly.
42 #include "base/template_util.h"
43 #else  // !BUILDING_CEF_SHARED
44 // The following is substantially similar to the Chromium implementation.
45 // If the Chromium implementation diverges the below implementation should be
46 // updated to match.
47
48 #include <cstddef>  // For size_t.
49
50 #include "include/base/cef_build.h"
51
52 namespace base {
53
54 // template definitions from tr1
55
56 template<class T, T v>
57 struct integral_constant {
58   static const T value = v;
59   typedef T value_type;
60   typedef integral_constant<T, v> type;
61 };
62
63 template <class T, T v> const T integral_constant<T, v>::value;
64
65 typedef integral_constant<bool, true> true_type;
66 typedef integral_constant<bool, false> false_type;
67
68 template <class T> struct is_pointer : false_type {};
69 template <class T> struct is_pointer<T*> : true_type {};
70
71 // Member function pointer detection up to four params. Add more as needed
72 // below. This is built-in to C++ 11, and we can remove this when we switch.
73 template<typename T>
74 struct is_member_function_pointer : false_type {};
75
76 template <typename R, typename Z>
77 struct is_member_function_pointer<R(Z::*)()> : true_type {};
78 template <typename R, typename Z>
79 struct is_member_function_pointer<R(Z::*)() const> : true_type {};
80
81 template <typename R, typename Z, typename A>
82 struct is_member_function_pointer<R(Z::*)(A)> : true_type {};
83 template <typename R, typename Z, typename A>
84 struct is_member_function_pointer<R(Z::*)(A) const> : true_type {};
85
86 template <typename R, typename Z, typename A, typename B>
87 struct is_member_function_pointer<R(Z::*)(A, B)> : true_type {};
88 template <typename R, typename Z, typename A, typename B>
89 struct is_member_function_pointer<R(Z::*)(A, B) const> : true_type {};
90
91 template <typename R, typename Z, typename A, typename B, typename C>
92 struct is_member_function_pointer<R(Z::*)(A, B, C)> : true_type {};
93 template <typename R, typename Z, typename A, typename B, typename C>
94 struct is_member_function_pointer<R(Z::*)(A, B, C) const> : true_type {};
95
96 template <typename R, typename Z, typename A, typename B, typename C,
97           typename D>
98 struct is_member_function_pointer<R(Z::*)(A, B, C, D)> : true_type {};
99 template <typename R, typename Z, typename A, typename B, typename C,
100           typename D>
101 struct is_member_function_pointer<R(Z::*)(A, B, C, D) const> : true_type {};
102
103
104 template <class T, class U> struct is_same : public false_type {};
105 template <class T> struct is_same<T,T> : true_type {};
106
107 template<class> struct is_array : public false_type {};
108 template<class T, size_t n> struct is_array<T[n]> : public true_type {};
109 template<class T> struct is_array<T[]> : public true_type {};
110
111 template <class T> struct is_non_const_reference : false_type {};
112 template <class T> struct is_non_const_reference<T&> : true_type {};
113 template <class T> struct is_non_const_reference<const T&> : false_type {};
114
115 template <class T> struct is_const : false_type {};
116 template <class T> struct is_const<const T> : true_type {};
117
118 template <class T> struct is_void : false_type {};
119 template <> struct is_void<void> : true_type {};
120
121 namespace cef_internal {
122
123 // Types YesType and NoType are guaranteed such that sizeof(YesType) <
124 // sizeof(NoType).
125 typedef char YesType;
126
127 struct NoType {
128   YesType dummy[2];
129 };
130
131 // This class is an implementation detail for is_convertible, and you
132 // don't need to know how it works to use is_convertible. For those
133 // who care: we declare two different functions, one whose argument is
134 // of type To and one with a variadic argument list. We give them
135 // return types of different size, so we can use sizeof to trick the
136 // compiler into telling us which function it would have chosen if we
137 // had called it with an argument of type From.  See Alexandrescu's
138 // _Modern C++ Design_ for more details on this sort of trick.
139
140 struct ConvertHelper {
141   template <typename To>
142   static YesType Test(To);
143
144   template <typename To>
145   static NoType Test(...);
146
147   template <typename From>
148   static From& Create();
149 };
150
151 // Used to determine if a type is a struct/union/class. Inspired by Boost's
152 // is_class type_trait implementation.
153 struct IsClassHelper {
154   template <typename C>
155   static YesType Test(void(C::*)(void));
156
157   template <typename C>
158   static NoType Test(...);
159 };
160
161 }  // namespace cef_internal
162
163 // Inherits from true_type if From is convertible to To, false_type otherwise.
164 //
165 // Note that if the type is convertible, this will be a true_type REGARDLESS
166 // of whether or not the conversion would emit a warning.
167 template <typename From, typename To>
168 struct is_convertible
169     : integral_constant<bool,
170                         sizeof(cef_internal::ConvertHelper::Test<To>(
171                                    cef_internal::ConvertHelper::Create<From>())) ==
172                         sizeof(cef_internal::YesType)> {
173 };
174
175 template <typename T>
176 struct is_class
177     : integral_constant<bool,
178                         sizeof(cef_internal::IsClassHelper::Test<T>(0)) ==
179                             sizeof(cef_internal::YesType)> {
180 };
181
182 template<bool B, class T = void>
183 struct enable_if {};
184
185 template<class T>
186 struct enable_if<true, T> { typedef T type; };
187
188 }  // namespace base
189
190 #endif  // !BUILDING_CEF_SHARED
191
192 #endif  // CEF_INCLUDE_BASE_CEF_TEMPLATE_UTIL_H_