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

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

Issue 2042413003: Implement cc::FilterOperation StructTraits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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_CARRAY_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "mojo/public/cpp/bindings/array_traits.h" 10 #include "mojo/public/cpp/bindings/array_traits.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 13
14 template <typename T> 14 template <typename T>
15 struct CArray { 15 struct CArray {
16 CArray() : size(0), max_size(0), data(nullptr) {} 16 CArray() : size(0), max_size(0), data(nullptr) {}
17 explicit CArray(size_t max_size) 17 explicit CArray(size_t max_size)
18 : size(0), max_size(max_size), data(nullptr) {} 18 : size(0), max_size(max_size), data(nullptr) {}
19 CArray(size_t size, size_t max_size, T* data) 19 CArray(size_t size, size_t max_size, T* data)
20 : size(size), max_size(max_size), data(data) {} 20 : size(size), max_size(max_size), data(data) {}
21 size_t size; 21 size_t size;
22 size_t max_size; 22 size_t max_size;
23 T* data; 23 T* data;
24 }; 24 };
25 25
26 template <typename T> 26 template <typename T>
27 struct ArrayTraits<CArray<T>> { 27 struct ArrayTraits<CArray<T>> {
28 using Element = T; 28 using Element = T;
29 29
30 static bool IsNull(const CArray<T>& input) { return !input.data; }
31
30 static size_t GetSize(const CArray<T>& input) { return input.size; } 32 static size_t GetSize(const CArray<T>& input) { return input.size; }
31 33
32 static T* GetData(CArray<T>& input) { return input.data; } 34 static T* GetData(CArray<T>& input) { return input.data; }
33 35
34 static const T* GetData(const CArray<T>& input) { return input.data; } 36 static const T* GetData(const CArray<T>& input) { return input.data; }
35 37
36 static T& GetAt(CArray<T>& input, size_t index) { return input.data[index]; } 38 static T& GetAt(CArray<T>& input, size_t index) { return input.data[index]; }
37 39
38 static const T& GetAt(const CArray<T>& input, size_t index) { 40 static const T& GetAt(const CArray<T>& input, size_t index) {
39 return input.data[index]; 41 return input.data[index];
40 } 42 }
41 43
42 static bool Resize(CArray<T>& input, size_t size) { 44 static bool Resize(CArray<T>& input, size_t size) {
43 if (size > input.max_size) 45 if (size > input.max_size)
44 return false; 46 return false;
45 47
46 input.size = size; 48 input.size = size;
47 return true; 49 return true;
48 } 50 }
49 }; 51 };
50 52
51 } // namespace mojo 53 } // namespace mojo
52 54
53 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ 55 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698