OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_ARRAY_SERIALIZATION_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <string.h> // For |memcpy()|. | 9 #include <string.h> // For |memcpy()|. |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 template <typename Traits, | 27 template <typename Traits, |
28 typename MaybeConstUserType, | 28 typename MaybeConstUserType, |
29 bool HasGetBegin = | 29 bool HasGetBegin = |
30 HasGetBeginMethod<Traits, MaybeConstUserType>::value> | 30 HasGetBeginMethod<Traits, MaybeConstUserType>::value> |
31 class ArrayIterator {}; | 31 class ArrayIterator {}; |
32 | 32 |
33 // Used as the UserTypeIterator template parameter of ArraySerializer. | 33 // Used as the UserTypeIterator template parameter of ArraySerializer. |
34 template <typename Traits, typename MaybeConstUserType> | 34 template <typename Traits, typename MaybeConstUserType> |
35 class ArrayIterator<Traits, MaybeConstUserType, true> { | 35 class ArrayIterator<Traits, MaybeConstUserType, true> { |
36 public: | 36 public: |
| 37 using UserType = typename std::remove_const<MaybeConstUserType>::type; |
37 using IteratorType = decltype( | 38 using IteratorType = decltype( |
38 CallGetBeginIfExists<Traits>(std::declval<MaybeConstUserType&>())); | 39 CallGetBeginIfExists<Traits>(std::declval<MaybeConstUserType&>())); |
39 | 40 |
40 explicit ArrayIterator(MaybeConstUserType& input) | 41 explicit ArrayIterator(MaybeConstUserType& input) |
41 : input_(input), iter_(CallGetBeginIfExists<Traits>(input)) {} | 42 : input_(input), iter_(CallGetBeginIfExists<Traits>(input)) {} |
42 ~ArrayIterator() {} | 43 ~ArrayIterator() {} |
43 | 44 |
44 size_t GetSize() const { return Traits::GetSize(input_); } | 45 size_t GetSize() const { return Traits::GetSize(input_); } |
45 | 46 |
46 using GetNextResult = | 47 using GetNextResult = |
47 decltype(Traits::GetValue(std::declval<IteratorType&>())); | 48 decltype(Traits::GetValue(std::declval<MaybeConstUserType&>(), |
| 49 std::declval<IteratorType&>())); |
48 GetNextResult GetNext() { | 50 GetNextResult GetNext() { |
49 auto& value = Traits::GetValue(iter_); | 51 auto& value = Traits::GetValue(input_, iter_); |
50 Traits::AdvanceIterator(iter_); | 52 Traits::AdvanceIterator(input_, iter_); |
51 return value; | 53 return value; |
52 } | 54 } |
53 | 55 |
54 using GetDataIfExistsResult = decltype( | 56 using GetDataIfExistsResult = decltype( |
55 CallGetDataIfExists<Traits>(std::declval<MaybeConstUserType&>())); | 57 CallGetDataIfExists<Traits>(std::declval<MaybeConstUserType&>())); |
56 GetDataIfExistsResult GetDataIfExists() { | 58 GetDataIfExistsResult GetDataIfExists() { |
57 return CallGetDataIfExists<Traits>(input_); | 59 return CallGetDataIfExists<Traits>(input_); |
58 } | 60 } |
59 | 61 |
60 private: | 62 private: |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 if (!input) | 541 if (!input) |
540 return CallSetToNullIfExists<Traits>(output); | 542 return CallSetToNullIfExists<Traits>(output); |
541 return Impl::DeserializeElements(input, output, context); | 543 return Impl::DeserializeElements(input, output, context); |
542 } | 544 } |
543 }; | 545 }; |
544 | 546 |
545 } // namespace internal | 547 } // namespace internal |
546 } // namespace mojo | 548 } // namespace mojo |
547 | 549 |
548 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ | 550 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ |
OLD | NEW |