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

Side by Side Diff: mojo/public/cpp/bindings/array_traits.h

Issue 2058633002: mojo::ArrayTraits: Add Support for Iterators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nit 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
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/array_serialization.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_ARRAY_TRAITS_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_
7 7
8 namespace mojo { 8 namespace mojo {
9 9
10 // This must be specialized for any type |T| to be serialized/deserialized as 10 // This must be specialized for any type |T| to be serialized/deserialized as
11 // a mojom array. 11 // a mojom array.
12 // 12 //
13 // Usually you would like to do a partial specialization for an array/vector 13 // Usually you would like to do a partial specialization for a container (e.g.
14 // template. Imagine you want to specialize it for CustomArray<>, you need to 14 // vector) template. Imagine you want to specialize it for Container<>, you need
15 // implement: 15 // to implement:
16 // 16 //
17 // template <typename T> 17 // template <typename T>
18 // struct ArrayTraits<CustomArray<T>> { 18 // struct ArrayTraits<Container<T>> {
19 // using Element = T; 19 // using Element = T;
20 // // These two statements are optional. Use them if you'd like to serialize
21 // // a container that supports iterators but does not support O(1) random
22 // // access and so GetAt(...) would be expensive.
23 // // using Iterator = T::iterator;
24 // // using ConstIterator = T::const_iterator;
20 // 25 //
21 // // These two methods are optional. Please see comments in struct_traits.h 26 // // These two methods are optional. Please see comments in struct_traits.h
22 // static bool IsNull(const CustomArray<T>& input); 27 // static bool IsNull(const Container<T>& input);
23 // static void SetToNull(CustomArray<T>* output); 28 // static void SetToNull(Container<T>* output);
24 // 29 //
25 // static size_t GetSize(const CustomArray<T>& input); 30 // static size_t GetSize(const Container<T>& input);
26 // 31 //
27 // // These two methods are optional. They are used to access the 32 // // These two methods are optional. They are used to access the
28 // // underlying storage of the array to speed up copy of POD types. 33 // // underlying storage of the array to speed up copy of POD types.
29 // static T* GetData(CustomArray<T>& input); 34 // static T* GetData(Container<T>& input);
30 // static const T* GetData(const CustomArray<T>& input); 35 // static const T* GetData(const Container<T>& input);
31 // 36 //
32 // static T& GetAt(CustomArray<T>& input, size_t index); 37 // // The following six methods are optional if the GetAt(...) methods are
33 // static const T& GetAt(const CustomArray<T>& input, size_t index); 38 // // implemented. These methods specify how to read the elements of
39 // // Container in some sequential order specified by the iterator.
40 // //
41 // // Acquires an iterator positioned at the first element in the container.
42 // static ConstIterator GetBegin(const Container<T>& input);
43 // static Iterator GetBegin(Container<T>& input);
44 //
45 // // Advances |iterator| to the next position within the container.
46 // static void AdvanceIterator(ConstIterator& iterator);
47 // static void AdvanceIterator(Iterator& iterator);
48 //
49 // // Returns a reference to the value at the current position of
50 // // |iterator|.
51 // static const T& GetValue(ConstIterator& iterator);
52 // static T& GetValue(Iterator& iterator);
53 //
54 // // These two methods are optional if the iterator methods are
55 // // implemented.
56 // static T& GetAt(Container<T>& input, size_t index);
57 // static const T& GetAt(const Container<T>& input, size_t index);
34 // 58 //
35 // // Returning false results in deserialization failure and causes the 59 // // Returning false results in deserialization failure and causes the
36 // // message pipe receiving it to be disconnected. 60 // // message pipe receiving it to be disconnected.
37 // static bool Resize(CustomArray<T>& input, size_t size); 61 // static bool Resize(Container<T>& input, size_t size);
38 // }; 62 // };
39 // 63 //
40 template <typename T> 64 template <typename T>
41 struct ArrayTraits; 65 struct ArrayTraits;
42 66
43 } // namespace mojo 67 } // namespace mojo
44 68
45 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_ 69 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/array_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698