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

Unified Diff: mojo/public/cpp/bindings/array_traits_wtf_vector.h

Issue 1979513004: Add array traits for WTF::Vector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@28_array_native
Patch Set: Created 4 years, 7 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/wtf_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_wtf_vector.h
diff --git a/mojo/public/cpp/bindings/array_traits_wtf_vector.h b/mojo/public/cpp/bindings/array_traits_wtf_vector.h
new file mode 100644
index 0000000000000000000000000000000000000000..9b3755ad4f161be04e67371a140b9da80a8d8f39
--- /dev/null
+++ b/mojo/public/cpp/bindings/array_traits_wtf_vector.h
@@ -0,0 +1,44 @@
+// 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_WTF_VECTOR_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_WTF_VECTOR_H_
+
+#include "mojo/public/cpp/bindings/array_traits.h"
+#include "third_party/WebKit/Source/wtf/Vector.h"
+
+namespace mojo {
+
+template <typename U>
+struct ArrayTraits<WTF::Vector<U>> {
+ using Element = U;
+
+ static bool IsNull(const WTF::Vector<U>& input) {
+ // WTF::Vector<> is always converted to non-null mojom array.
+ return false;
+ }
+
+ static void SetToNull(WTF::Vector<U>* output) {
+ // WTF::Vector<> doesn't support null state. Set it to empty instead.
+ output->clear();
+ }
+
+ static size_t GetSize(const WTF::Vector<U>& input) { return input.size(); }
+
+ static U* GetData(WTF::Vector<U>& input) { return input.data(); }
+
+ static const U* GetData(const WTF::Vector<U>& input) { return input.data(); }
+
+ static U& GetAt(WTF::Vector<U>& input, size_t index) { return input[index]; }
+
+ static const U& GetAt(const WTF::Vector<U>& input, size_t index) {
+ return input[index];
+ }
+
+ static void Resize(WTF::Vector<U>& input, size_t size) { input.resize(size); }
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_WTF_VECTOR_H_
« no previous file with comments | « mojo/public/cpp/bindings/BUILD.gn ('k') | mojo/public/cpp/bindings/lib/wtf_serialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698