Index: third_party/WebKit/public/platform/WebVectorMojoArrayTraits.h |
diff --git a/third_party/WebKit/public/platform/WebVectorMojoArrayTraits.h b/third_party/WebKit/public/platform/WebVectorMojoArrayTraits.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b2a4af43cb16493c2955c04919dc436b7e6fb576 |
--- /dev/null |
+++ b/third_party/WebKit/public/platform/WebVectorMojoArrayTraits.h |
@@ -0,0 +1,38 @@ |
+// 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 WebVectorMojoArrayTraits_h |
+#define WebVectorMojoArrayTraits_h |
+ |
+#include "WebVector.h" |
+#include "mojo/public/cpp/bindings/array_traits.h" |
+ |
+#include <algorithm> |
+#include <vector> |
+ |
+namespace mojo { |
+ |
+template <typename T> |
+struct ArrayTraits<::blink::WebVector<T>> { |
+ using Element = T; |
+ |
+ static size_t GetSize(const ::blink::WebVector<T>& input) { return input.size(); } |
+ static T* GetData(::blink::WebVector<T>& input) { return input.data(); } |
+ static const T* GetData(const ::blink::WebVector<T>& input) { return input.data(); } |
+ static T& GetAt(::blink::WebVector<T>& input, size_t index) { return input[index]; } |
+ static const T& GetAt(const ::blink::WebVector<T>& input, size_t index) { return input[index]; } |
+ |
+ static bool Resize(::blink::WebVector<T>& input, size_t size) |
+ { |
+ ::blink::WebVector<T> new_vector(size); |
+ for (size_t i = 0; i < std::min(size, input.size()); ++i) |
+ new_vector[i] = input[i]; |
+ input = new_vector; |
+ return true; |
+ } |
+}; |
+ |
+} // namespace mojo |
+ |
+#endif |