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_SERIALIZATION_UTIL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_UTIL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_UTIL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_UTIL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return f(std::forward<InputUserType>(input), context); | 220 return f(std::forward<InputUserType>(input), context); |
221 } | 221 } |
222 | 222 |
223 template <typename ReturnType, typename ParamType, typename InputUserType> | 223 template <typename ReturnType, typename ParamType, typename InputUserType> |
224 ReturnType CallWithContext(ReturnType (*f)(ParamType), | 224 ReturnType CallWithContext(ReturnType (*f)(ParamType), |
225 InputUserType&& input, | 225 InputUserType&& input, |
226 void* context) { | 226 void* context) { |
227 return f(std::forward<InputUserType>(input)); | 227 return f(std::forward<InputUserType>(input)); |
228 } | 228 } |
229 | 229 |
| 230 template <typename T, typename MaybeConstUserType> |
| 231 struct HasGetDataMethod { |
| 232 template <typename U> |
| 233 static char Test(decltype(U::GetData(std::declval<MaybeConstUserType&>()))*); |
| 234 template <typename U> |
| 235 static int Test(...); |
| 236 static const bool value = sizeof(Test<T>(0)) == sizeof(char); |
| 237 |
| 238 private: |
| 239 EnsureTypeIsComplete<T> check_t_; |
| 240 }; |
| 241 |
| 242 template < |
| 243 typename Traits, |
| 244 typename MaybeConstUserType, |
| 245 typename std::enable_if< |
| 246 HasGetDataMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> |
| 247 decltype(Traits::GetData(std::declval<MaybeConstUserType&>())) |
| 248 CallGetDataIfExists(MaybeConstUserType& input) { |
| 249 return Traits::GetData(input); |
| 250 } |
| 251 |
| 252 template < |
| 253 typename Traits, |
| 254 typename MaybeConstUserType, |
| 255 typename std::enable_if< |
| 256 !HasGetDataMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> |
| 257 void* CallGetDataIfExists(MaybeConstUserType& input) { |
| 258 return nullptr; |
| 259 } |
| 260 |
230 } // namespace internal | 261 } // namespace internal |
231 } // namespace mojo | 262 } // namespace mojo |
232 | 263 |
233 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_UTIL_H_ | 264 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_UTIL_H_ |
OLD | NEW |