OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ | |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ | |
7 | |
8 #include "mojo/public/cpp/bindings/array_traits.h" | |
9 | |
10 namespace mojo { | |
11 | |
12 template <typename T> | |
13 struct CArray { | |
14 CArray() : size(0), max_size(0), data(nullptr) {} | |
15 explicit CArray(size_t max_size) | |
16 : size(0), max_size(max_size), data(nullptr) {} | |
17 CArray(size_t size, size_t max_size, T* data) | |
18 : size(size), max_size(max_size), data(data) {} | |
19 size_t size; | |
20 const size_t max_size; | |
21 T* const data; | |
22 }; | |
23 | |
24 template <typename T> | |
25 struct ArrayTraits<CArray<T>> { | |
26 using Element = T; | |
27 | |
28 static bool IsNull(const CArray<T>& input) { return !input.data; } | |
Fady Samuel
2016/06/08 00:51:20
Note, I need this for my cc::FilterOperation patch
| |
29 | |
30 static size_t GetSize(const CArray<T>& input) { return input.size; } | |
31 | |
32 static T* GetData(CArray<T>& input) { return input.data; } | |
33 | |
34 static const T* GetData(const CArray<T>& input) { return input.data; } | |
35 | |
36 static T& GetAt(CArray<T>& input, size_t index) { return input.data[index]; } | |
37 | |
38 static const T& GetAt(const CArray<T>& input, size_t index) { | |
39 return input.data[index]; | |
40 } | |
41 | |
42 static bool Resize(CArray<T>& input, size_t size) { | |
43 if (size > input.max_size) | |
44 return false; | |
45 | |
46 input.size = size; | |
47 return true; | |
48 } | |
49 }; | |
50 | |
51 } // namespace mojo | |
52 | |
53 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_ | |
OLD | NEW |