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/bindings_internal.h" |
15 #include "mojo/public/cpp/bindings/lib/template_util.h" | 16 #include "mojo/public/cpp/bindings/lib/template_util.h" |
16 #include "mojo/public/cpp/bindings/type_converter.h" | 17 #include "mojo/public/cpp/bindings/type_converter.h" |
17 | 18 |
18 namespace mojo { | 19 namespace mojo { |
19 | 20 |
20 template <typename T> | 21 template <typename T> |
21 class Array { | 22 class Array { |
22 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(Array, RValue) | 23 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(Array, RValue) |
23 public: | 24 public: |
24 typedef internal::ArrayTraits<T, internal::IsMoveOnlyType<T>::value> Traits; | 25 typedef internal::ArrayTraits<T, internal::IsMoveOnlyType<T>::value> Traits; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // Please note that calling this method will fail compilation if the element | 101 // Please note that calling this method will fail compilation if the element |
101 // type cannot be cloned (which usually means that it is a Mojo handle type or | 102 // type cannot be cloned (which usually means that it is a Mojo handle type or |
102 // a type contains Mojo handles). | 103 // a type contains Mojo handles). |
103 Array Clone() const { | 104 Array Clone() const { |
104 Array result; | 105 Array result; |
105 result.is_null_ = is_null_; | 106 result.is_null_ = is_null_; |
106 Traits::Clone(vec_, &result.vec_); | 107 Traits::Clone(vec_, &result.vec_); |
107 return result.Pass(); | 108 return result.Pass(); |
108 } | 109 } |
109 | 110 |
| 111 bool Equals(const Array& other) const { |
| 112 if (is_null() != other.is_null()) |
| 113 return false; |
| 114 if (size() != other.size()) |
| 115 return false; |
| 116 for (size_t i = 0; i < size(); ++i) { |
| 117 if (!internal::ValueTraits<T>::Equals(at(i), other.at(i))) |
| 118 return false; |
| 119 } |
| 120 return true; |
| 121 } |
| 122 |
110 private: | 123 private: |
111 typedef std::vector<StorageType> Array::*Testable; | 124 typedef std::vector<StorageType> Array::*Testable; |
112 | 125 |
113 public: | 126 public: |
114 operator Testable() const { return is_null_ ? 0 : &Array::vec_; } | 127 operator Testable() const { return is_null_ ? 0 : &Array::vec_; } |
115 | 128 |
116 private: | 129 private: |
117 void Take(Array* other) { | 130 void Take(Array* other) { |
118 reset(); | 131 reset(); |
119 Swap(other); | 132 Swap(other); |
(...skipping 22 matching lines...) Expand all Loading... |
142 for (size_t i = 0; i < input.size(); ++i) | 155 for (size_t i = 0; i < input.size(); ++i) |
143 result[i] = TypeConverter<E, T>::Convert(input[i]); | 156 result[i] = TypeConverter<E, T>::Convert(input[i]); |
144 } | 157 } |
145 return result; | 158 return result; |
146 } | 159 } |
147 }; | 160 }; |
148 | 161 |
149 } // namespace mojo | 162 } // namespace mojo |
150 | 163 |
151 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 164 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
OLD | NEW |