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

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

Issue 2379993003: Mojo C++ bindings: make String16 and gfx::Size available in Blink (Closed)
Patch Set: trying to fix Windows build Created 4 years, 2 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 "mojo/public/cpp/bindings/array_traits.h" 8 #include "mojo/public/cpp/bindings/array_traits.h"
9 9
10 namespace mojo { 10 namespace mojo {
11 11
12 template <typename T> 12 template <typename T>
13 struct CArray { 13 struct CArray {
14 CArray() : size(0), max_size(0), data(nullptr) {} 14 CArray() : size(0), max_size(0), data(nullptr) {}
15 CArray(size_t size, size_t max_size, T* data) 15 CArray(size_t size, size_t max_size, T* data)
16 : size(size), max_size(max_size), data(data) {} 16 : size(size), max_size(max_size), data(data) {}
17 size_t size; 17 size_t size;
18 const size_t max_size; 18 const size_t max_size;
19 T* data; 19 T* data;
20 }; 20 };
21 21
22 template <typename T> 22 template <typename T>
23 struct ConstCArray {
24 ConstCArray() : size(0), data(nullptr) {}
25 ConstCArray(size_t size, const T* data) : size(size), data(data) {}
26 size_t size;
Ken Rockot(use gerrit already) 2016/10/05 17:47:55 nit: These fields could be const size_t and const
27 const T* data;
28 };
29
30 template <typename T>
23 struct ArrayTraits<CArray<T>> { 31 struct ArrayTraits<CArray<T>> {
24 using Element = T; 32 using Element = T;
25 33
26 static bool IsNull(const CArray<T>& input) { return !input.data; } 34 static bool IsNull(const CArray<T>& input) { return !input.data; }
27 35
28 static void SetToNull(CArray<T>* output) { output->data = nullptr; } 36 static void SetToNull(CArray<T>* output) { output->data = nullptr; }
29 37
30 static size_t GetSize(const CArray<T>& input) { return input.size; } 38 static size_t GetSize(const CArray<T>& input) { return input.size; }
31 39
32 static T* GetData(CArray<T>& input) { return input.data; } 40 static T* GetData(CArray<T>& input) { return input.data; }
33 41
34 static const T* GetData(const CArray<T>& input) { return input.data; } 42 static const T* GetData(const CArray<T>& input) { return input.data; }
35 43
36 static T& GetAt(CArray<T>& input, size_t index) { return input.data[index]; } 44 static T& GetAt(CArray<T>& input, size_t index) { return input.data[index]; }
37 45
38 static const T& GetAt(const CArray<T>& input, size_t index) { 46 static const T& GetAt(const CArray<T>& input, size_t index) {
39 return input.data[index]; 47 return input.data[index];
40 } 48 }
41 49
42 static bool Resize(CArray<T>& input, size_t size) { 50 static bool Resize(CArray<T>& input, size_t size) {
43 if (size > input.max_size) 51 if (size > input.max_size)
44 return false; 52 return false;
45 53
46 input.size = size; 54 input.size = size;
47 return true; 55 return true;
48 } 56 }
49 }; 57 };
50 58
59 template <typename T>
60 struct ArrayTraits<ConstCArray<T>> {
61 using Element = T;
62
63 static bool IsNull(const ConstCArray<T>& input) { return !input.data; }
64
65 static size_t GetSize(const ConstCArray<T>& input) { return input.size; }
66
67 static const T* GetData(const ConstCArray<T>& input) { return input.data; }
68
69 static const T& GetAt(const ConstCArray<T>& input, size_t index) {
70 return input.data[index];
71 }
72 };
73
51 } // namespace mojo 74 } // namespace mojo
52 75
53 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ 76 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698