Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: mojo/public/cpp/bindings/lib/serialization_util.h

Issue 2058633002: mojo::ArrayTraits: Add Support for Iterators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
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> 230 template <typename T, typename MaybeConstUserType>
231 struct HasGetBeginMethod {
232 template <typename U>
233 static char Test(decltype(U::GetBegin(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 HasGetBeginMethod<Traits, MaybeConstUserType>::value>::type* = nullptr>
247 decltype(Traits::GetBegin(std::declval<MaybeConstUserType&>()))
248 CallGetBeginIfExists(MaybeConstUserType& input) {
249 return Traits::GetBegin(input);
250 }
251
252 template <
253 typename Traits,
254 typename MaybeConstUserType,
255 typename std::enable_if<
256 !HasGetBeginMethod<Traits, MaybeConstUserType>::value>::type* = nullptr>
257 size_t CallGetBeginIfExists(MaybeConstUserType& input) {
258 return 0;
259 }
260
261 template <typename T, typename MaybeConstUserType>
231 struct HasGetDataMethod { 262 struct HasGetDataMethod {
232 template <typename U> 263 template <typename U>
233 static char Test(decltype(U::GetData(std::declval<MaybeConstUserType&>()))*); 264 static char Test(decltype(U::GetData(std::declval<MaybeConstUserType&>()))*);
234 template <typename U> 265 template <typename U>
235 static int Test(...); 266 static int Test(...);
236 static const bool value = sizeof(Test<T>(0)) == sizeof(char); 267 static const bool value = sizeof(Test<T>(0)) == sizeof(char);
237 268
238 private: 269 private:
239 EnsureTypeIsComplete<T> check_t_; 270 EnsureTypeIsComplete<T> check_t_;
240 }; 271 };
(...skipping 14 matching lines...) Expand all
255 typename std::enable_if< 286 typename std::enable_if<
256 !HasGetDataMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> 287 !HasGetDataMethod<Traits, MaybeConstUserType>::value>::type* = nullptr>
257 void* CallGetDataIfExists(MaybeConstUserType& input) { 288 void* CallGetDataIfExists(MaybeConstUserType& input) {
258 return nullptr; 289 return nullptr;
259 } 290 }
260 291
261 } // namespace internal 292 } // namespace internal
262 } // namespace mojo 293 } // namespace mojo
263 294
264 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_UTIL_H_ 295 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SERIALIZATION_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698