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 WebVectorMojoArrayTraits_h |
| 6 #define WebVectorMojoArrayTraits_h |
| 7 |
| 8 #include "WebVector.h" |
| 9 #include "mojo/public/cpp/bindings/array_traits.h" |
| 10 |
| 11 #include <algorithm> |
| 12 #include <vector> |
| 13 |
| 14 namespace mojo { |
| 15 |
| 16 template <typename T> |
| 17 struct ArrayTraits<::blink::WebVector<T>> { |
| 18 using Element = T; |
| 19 |
| 20 static size_t GetSize(const ::blink::WebVector<T>& input) { return input.siz
e(); } |
| 21 static T* GetData(::blink::WebVector<T>& input) { return input.data(); } |
| 22 static const T* GetData(const ::blink::WebVector<T>& input) { return input.d
ata(); } |
| 23 static T& GetAt(::blink::WebVector<T>& input, size_t index) { return input[i
ndex]; } |
| 24 static const T& GetAt(const ::blink::WebVector<T>& input, size_t index) { re
turn input[index]; } |
| 25 |
| 26 static bool Resize(::blink::WebVector<T>& input, size_t size) |
| 27 { |
| 28 ::blink::WebVector<T> new_vector(size); |
| 29 for (size_t i = 0; i < std::min(size, input.size()); ++i) |
| 30 new_vector[i] = input[i]; |
| 31 input = new_vector; |
| 32 return true; |
| 33 } |
| 34 }; |
| 35 |
| 36 } // namespace mojo |
| 37 |
| 38 #endif |
OLD | NEW |