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 <stddef.h> | 8 #include <stddef.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/macros.h" | 16 #include "base/move.h" |
17 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 17 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
18 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 18 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
19 #include "mojo/public/cpp/bindings/lib/template_util.h" | 19 #include "mojo/public/cpp/bindings/lib/template_util.h" |
20 #include "mojo/public/cpp/bindings/type_converter.h" | 20 #include "mojo/public/cpp/bindings/type_converter.h" |
21 | 21 |
22 namespace mojo { | 22 namespace mojo { |
23 | 23 |
24 // Represents a moveable array with contents of type |T|. The array can be null, | 24 // Represents a moveable array with contents of type |T|. The array can be null, |
25 // meaning that no value has been assigned to it. Null is distinct from empty. | 25 // meaning that no value has been assigned to it. Null is distinct from empty. |
26 template <typename T> | 26 template <typename T> |
27 class Array { | 27 class Array { |
| 28 MOVE_ONLY_TYPE_FOR_CPP_03(Array); |
| 29 |
28 public: | 30 public: |
29 using ConstRefType = typename std::vector<T>::const_reference; | 31 using ConstRefType = typename std::vector<T>::const_reference; |
30 using RefType = typename std::vector<T>::reference; | 32 using RefType = typename std::vector<T>::reference; |
31 | 33 |
32 using Element = T; | 34 using Element = T; |
33 using Data_ = internal::Array_Data< | 35 using Data_ = internal::Array_Data< |
34 typename internal::GetDataTypeAsArrayElement<T>::Data>; | 36 typename internal::GetDataTypeAsArrayElement<T>::Data>; |
35 | 37 |
36 using iterator = typename std::vector<T>::iterator; | 38 using iterator = typename std::vector<T>::iterator; |
37 using const_iterator = typename std::vector<T>::const_iterator; | 39 using const_iterator = typename std::vector<T>::const_iterator; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 template <typename U> | 208 template <typename U> |
207 bool operator!=(const Array<U>& other) const = delete; | 209 bool operator!=(const Array<U>& other) const = delete; |
208 | 210 |
209 void Take(Array* other) { | 211 void Take(Array* other) { |
210 operator=(nullptr); | 212 operator=(nullptr); |
211 Swap(other); | 213 Swap(other); |
212 } | 214 } |
213 | 215 |
214 std::vector<T> vec_; | 216 std::vector<T> vec_; |
215 bool is_null_; | 217 bool is_null_; |
216 | |
217 DISALLOW_COPY_AND_ASSIGN(Array); | |
218 }; | 218 }; |
219 | 219 |
220 // A |TypeConverter| that will create an |Array<T>| containing a copy of the | 220 // A |TypeConverter| that will create an |Array<T>| containing a copy of the |
221 // contents of an |std::vector<E>|, using |TypeConverter<T, E>| to copy each | 221 // contents of an |std::vector<E>|, using |TypeConverter<T, E>| to copy each |
222 // element. The returned array will always be non-null. | 222 // element. The returned array will always be non-null. |
223 template <typename T, typename E> | 223 template <typename T, typename E> |
224 struct TypeConverter<Array<T>, std::vector<E>> { | 224 struct TypeConverter<Array<T>, std::vector<E>> { |
225 static Array<T> Convert(const std::vector<E>& input) { | 225 static Array<T> Convert(const std::vector<E>& input) { |
226 Array<T> result(input.size()); | 226 Array<T> result(input.size()); |
227 for (size_t i = 0; i < input.size(); ++i) | 227 for (size_t i = 0; i < input.size(); ++i) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (a.is_null()) | 280 if (a.is_null()) |
281 return !b.is_null(); | 281 return !b.is_null(); |
282 if (b.is_null()) | 282 if (b.is_null()) |
283 return false; | 283 return false; |
284 return a.storage() < b.storage(); | 284 return a.storage() < b.storage(); |
285 } | 285 } |
286 | 286 |
287 } // namespace mojo | 287 } // namespace mojo |
288 | 288 |
289 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 289 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
OLD | NEW |