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

Unified 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: Remove unnecessary constructor 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/array_traits_carray.h
diff --git a/mojo/public/cpp/bindings/array_traits_carray.h b/mojo/public/cpp/bindings/array_traits_carray.h
new file mode 100644
index 0000000000000000000000000000000000000000..26f3374a5ec5473afecfa8c4e255ab933f094ad8
--- /dev/null
+++ b/mojo/public/cpp/bindings/array_traits_carray.h
@@ -0,0 +1,51 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_
+
+#include "mojo/public/cpp/bindings/array_traits.h"
+
+namespace mojo {
+
+template <typename T>
+struct CArray {
+ CArray() : size(0), max_size(0), data(nullptr) {}
+ CArray(size_t size, size_t max_size, T* data)
+ : size(size), max_size(max_size), data(data) {}
+ size_t size;
+ const size_t max_size;
+ T* const data;
+};
+
+template <typename T>
+struct ArrayTraits<CArray<T>> {
+ using Element = T;
+
+ static bool IsNull(const CArray<T>& input) { return !input.data; }
yzshen1 2016/06/08 16:09:17 SetToNull() is also needed. That means we either n
+
+ static size_t GetSize(const CArray<T>& input) { return input.size; }
+
+ static T* GetData(CArray<T>& input) { return input.data; }
+
+ static const T* GetData(const CArray<T>& input) { return input.data; }
+
+ static T& GetAt(CArray<T>& input, size_t index) { return input.data[index]; }
+
+ static const T& GetAt(const CArray<T>& input, size_t index) {
+ return input.data[index];
+ }
+
+ static bool Resize(CArray<T>& input, size_t size) {
+ if (size > input.max_size)
+ return false;
+
+ input.size = size;
+ return true;
+ }
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_CARRAY_H_
« 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