OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
7 | 7 |
8 #include <type_traits> | 8 #include <type_traits> |
9 | 9 |
10 #include "mojo/public/cpp/bindings/lib/template_util.h" | 10 #include "mojo/public/cpp/bindings/lib/template_util.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // TODO(vardhan): Instead of providing |move_only| & |is_union| template | 191 // TODO(vardhan): Instead of providing |move_only| & |is_union| template |
192 // parameters, provide a default "typename Enable = void" template parameter, | 192 // parameters, provide a default "typename Enable = void" template parameter, |
193 // and have specializations define their own Enable expressions (similar to how | 193 // and have specializations define their own Enable expressions (similar to how |
194 // ValueTraits is). | 194 // ValueTraits is). |
195 template <typename T, | 195 template <typename T, |
196 bool move_only = IsMoveOnlyType<T>::value, | 196 bool move_only = IsMoveOnlyType<T>::value, |
197 bool is_union = | 197 bool is_union = |
198 IsUnionWrapperType<typename RemoveStructPtr<T>::type>::value> | 198 IsUnionWrapperType<typename RemoveStructPtr<T>::type>::value> |
199 struct WrapperTraits; | 199 struct WrapperTraits; |
200 | 200 |
| 201 // Catch-all for all mojom types not specialized below. |
201 template <typename T> | 202 template <typename T> |
202 struct WrapperTraits<T, false, false> { | 203 struct WrapperTraits<T, false, false> { |
203 using DataType = T; | 204 using DataType = T; |
204 }; | 205 }; |
205 template <typename H> | 206 template <typename H> |
206 struct WrapperTraits<ScopedHandleBase<H>, true, false> { | 207 struct WrapperTraits<ScopedHandleBase<H>, true, false> { |
207 using DataType = H; | 208 using DataType = H; |
208 }; | 209 }; |
209 template <typename I> | 210 template <typename I> |
210 struct WrapperTraits<InterfaceRequest<I>, true, false> { | 211 struct WrapperTraits<InterfaceRequest<I>, true, false> { |
211 using DataType = MessagePipeHandle; | 212 using DataType = MessagePipeHandle; |
212 }; | 213 }; |
213 template <typename Interface> | 214 template <typename Interface> |
214 struct WrapperTraits<InterfacePtr<Interface>, true, false> { | 215 struct WrapperTraits<InterfacePtr<Interface>, true, false> { |
215 using DataType = Interface_Data; | 216 using DataType = Interface_Data; |
216 }; | 217 }; |
| 218 // Unions. |
217 template <typename U> | 219 template <typename U> |
218 struct WrapperTraits<StructPtr<U>, true, true> { | 220 struct WrapperTraits<StructPtr<U>, true, true> { |
219 using DataType = typename U::Data_; | 221 using DataType = typename U::Data_; |
220 }; | 222 }; |
221 template <typename U> | 223 template <typename U> |
222 struct WrapperTraits<InlinedStructPtr<U>, true, true> { | 224 struct WrapperTraits<InlinedStructPtr<U>, true, true> { |
223 using DataType = typename U::Data_; | 225 using DataType = typename U::Data_; |
224 }; | 226 }; |
| 227 // Catch-all for other pointer types: arrays, maps. |
225 template <typename S> | 228 template <typename S> |
226 struct WrapperTraits<S, true, false> { | 229 struct WrapperTraits<S, true, false> { |
227 using DataType = typename S::Data_*; | 230 using DataType = typename S::Data_*; |
228 }; | 231 }; |
229 | 232 |
230 template <typename T, typename Enable = void> | 233 template <typename T, typename Enable = void> |
231 struct ValueTraits { | 234 struct ValueTraits { |
232 static bool Equals(const T& a, const T& b) { return a == b; } | 235 static bool Equals(const T& a, const T& b) { return a == b; } |
233 }; | 236 }; |
234 | 237 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 static bool Equals(const InterfaceRequest<I>& a, | 269 static bool Equals(const InterfaceRequest<I>& a, |
267 const InterfaceRequest<I>& b) { | 270 const InterfaceRequest<I>& b) { |
268 return (&a == &b) || (!a.is_pending() && !b.is_pending()); | 271 return (&a == &b) || (!a.is_pending() && !b.is_pending()); |
269 } | 272 } |
270 }; | 273 }; |
271 | 274 |
272 } // namespace internal | 275 } // namespace internal |
273 } // namespace mojo | 276 } // namespace mojo |
274 | 277 |
275 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ | 278 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDINGS_INTERNAL_H_ |
OLD | NEW |