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

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

Issue 2046563005: Add ArrayTraits<CArray<T>> utility template (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase against SkImageFilter CL 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 | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/lib/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
(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 <vector>
yzshen1 2016/06/07 22:29:29 No need to have this include.
Fady Samuel 2016/06/08 00:50:06 Done.
9
10 #include "mojo/public/cpp/bindings/array_traits.h"
11
12 namespace mojo {
13
14 template <typename T>
15 struct CArray {
16 CArray() : size(0), max_size(0), data(nullptr) {}
17 explicit CArray(size_t max_size)
18 : size(0), max_size(max_size), data(nullptr) {}
19 CArray(size_t size, size_t max_size, T* data)
20 : size(size), max_size(max_size), data(data) {}
21 size_t size;
22 size_t max_size;
yzshen1 2016/06/07 22:29:29 Does it make sense to: - either making this const
Fady Samuel 2016/06/08 00:50:06 Made it const. I'd prefer not to have it in and ou
23 T* data;
24 };
25
26 template <typename T>
27 struct ArrayTraits<CArray<T>> {
28 using Element = T;
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_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/lib/serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698