| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
| 7 | 7 |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 14 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| 15 #include "mojo/public/cpp/bindings/lib/template_util.h" | 15 #include "mojo/public/cpp/bindings/lib/template_util.h" |
| 16 #include "mojo/public/cpp/bindings/type_converter.h" | 16 #include "mojo/public/cpp/bindings/type_converter.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 | 19 |
| 20 // Provides read-only access to array data. | 20 // Provides read-only access to array data. |
| 21 template <typename T> | 21 template <typename T> |
| 22 class Array { | 22 class Array { |
| 23 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(Array, RValue) | 23 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(Array, RValue) |
| 24 public: | 24 public: |
| 25 typedef internal::ArrayTraits<T, internal::IsMoveOnlyType<T>::value> | 25 typedef internal::ArrayTraits<T, internal::IsMoveOnlyType<T>::value> |
| 26 Traits; | 26 Traits; |
| 27 typedef typename Traits::ConstRefType ConstRefType; | 27 typedef typename Traits::ConstRefType ConstRefType; |
| 28 typedef typename Traits::RefType RefType; | 28 typedef typename Traits::RefType RefType; |
| 29 typedef typename Traits::StorageType StorageType; | 29 typedef typename Traits::StorageType StorageType; |
| 30 typedef typename Traits::SinkType SinkType; |
| 30 | 31 |
| 31 typedef internal::Array_Data<typename internal::WrapperTraits<T>::DataType> | 32 typedef internal::Array_Data<typename internal::WrapperTraits<T>::DataType> |
| 32 Data_; | 33 Data_; |
| 33 | 34 |
| 34 Array() : is_null_(true) {} | 35 Array() : is_null_(true) {} |
| 35 explicit Array(size_t size) : vec_(size), is_null_(false) { | 36 explicit Array(size_t size) : vec_(size), is_null_(false) { |
| 36 Traits::Initialize(&vec_); | 37 Traits::Initialize(&vec_); |
| 37 } | 38 } |
| 38 ~Array() { Traits::Finalize(&vec_); } | 39 ~Array() { Traits::Finalize(&vec_); } |
| 39 | 40 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 bool is_null() const { return is_null_; } | 69 bool is_null() const { return is_null_; } |
| 69 | 70 |
| 70 size_t size() const { return vec_.size(); } | 71 size_t size() const { return vec_.size(); } |
| 71 | 72 |
| 72 ConstRefType at(size_t offset) const { return Traits::at(&vec_, offset); } | 73 ConstRefType at(size_t offset) const { return Traits::at(&vec_, offset); } |
| 73 ConstRefType operator[](size_t offset) const { return at(offset); } | 74 ConstRefType operator[](size_t offset) const { return at(offset); } |
| 74 | 75 |
| 75 RefType at(size_t offset) { return Traits::at(&vec_, offset); } | 76 RefType at(size_t offset) { return Traits::at(&vec_, offset); } |
| 76 RefType operator[](size_t offset) { return at(offset); } | 77 RefType operator[](size_t offset) { return at(offset); } |
| 77 | 78 |
| 79 void push_back(SinkType value) { |
| 80 is_null_ = false; |
| 81 Traits::PushBack(&vec_, value); |
| 82 } |
| 83 |
| 84 void resize(size_t size) { |
| 85 is_null_ = false; |
| 86 Traits::Resize(&vec_, size); |
| 87 } |
| 88 |
| 78 const std::vector<StorageType>& storage() const { | 89 const std::vector<StorageType>& storage() const { |
| 79 return vec_; | 90 return vec_; |
| 80 } | 91 } |
| 81 operator const std::vector<StorageType>&() const { | 92 operator const std::vector<StorageType>&() const { |
| 82 return vec_; | 93 return vec_; |
| 83 } | 94 } |
| 84 | 95 |
| 85 void Swap(Array* other) { | 96 void Swap(Array* other) { |
| 86 std::swap(is_null_, other->is_null_); | 97 std::swap(is_null_, other->is_null_); |
| 87 vec_.swap(other->vec_); | 98 vec_.swap(other->vec_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 for (size_t i = 0; i < input.size(); ++i) | 134 for (size_t i = 0; i < input.size(); ++i) |
| 124 result[i] = TypeConverter<T, E>::ConvertTo(input[i]); | 135 result[i] = TypeConverter<T, E>::ConvertTo(input[i]); |
| 125 } | 136 } |
| 126 return result; | 137 return result; |
| 127 } | 138 } |
| 128 }; | 139 }; |
| 129 | 140 |
| 130 } // namespace mojo | 141 } // namespace mojo |
| 131 | 142 |
| 132 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 143 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
| OLD | NEW |