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/macros.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/clone_equals_util.h" | 19 #include "mojo/public/cpp/bindings/lib/clone_equals_util.h" |
| 20 #include "mojo/public/cpp/bindings/lib/hash_util.h" |
20 #include "mojo/public/cpp/bindings/lib/template_util.h" | 21 #include "mojo/public/cpp/bindings/lib/template_util.h" |
21 #include "mojo/public/cpp/bindings/type_converter.h" | 22 #include "mojo/public/cpp/bindings/type_converter.h" |
22 | 23 |
23 namespace mojo { | 24 namespace mojo { |
24 | 25 |
25 // Represents a moveable array with contents of type |T|. The array can be null, | 26 // Represents a moveable array with contents of type |T|. The array can be null, |
26 // meaning that no value has been assigned to it. Null is distinct from empty. | 27 // meaning that no value has been assigned to it. Null is distinct from empty. |
27 template <typename T> | 28 template <typename T> |
28 class Array { | 29 class Array { |
29 public: | 30 public: |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 176 |
176 // Indicates whether the contents of this array are equal to |other|. A null | 177 // Indicates whether the contents of this array are equal to |other|. A null |
177 // array is only equal to another null array. If the element type defines an | 178 // array is only equal to another null array. If the element type defines an |
178 // Equals() method, it will be used; otherwise == operator will be used. | 179 // Equals() method, it will be used; otherwise == operator will be used. |
179 bool Equals(const Array& other) const { | 180 bool Equals(const Array& other) const { |
180 if (is_null() != other.is_null()) | 181 if (is_null() != other.is_null()) |
181 return false; | 182 return false; |
182 return internal::Equals(vec_, other.vec_); | 183 return internal::Equals(vec_, other.vec_); |
183 } | 184 } |
184 | 185 |
| 186 size_t Hash(size_t seed) const { |
| 187 return is_null() ? seed : internal::Hash(seed, vec_); |
| 188 } |
| 189 |
185 private: | 190 private: |
186 typedef std::vector<T> Array::*Testable; | 191 typedef std::vector<T> Array::*Testable; |
187 | 192 |
188 public: | 193 public: |
189 operator Testable() const { return is_null_ ? 0 : &Array::vec_; } | 194 operator Testable() const { return is_null_ ? 0 : &Array::vec_; } |
190 | 195 |
191 private: | 196 private: |
192 // Forbid the == and != operators explicitly, otherwise Array will be | 197 // Forbid the == and != operators explicitly, otherwise Array will be |
193 // converted to Testable to do == or != comparison. | 198 // converted to Testable to do == or != comparison. |
194 template <typename U> | 199 template <typename U> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 if (a.is_null()) | 275 if (a.is_null()) |
271 return !b.is_null(); | 276 return !b.is_null(); |
272 if (b.is_null()) | 277 if (b.is_null()) |
273 return false; | 278 return false; |
274 return a.storage() < b.storage(); | 279 return a.storage() < b.storage(); |
275 } | 280 } |
276 | 281 |
277 } // namespace mojo | 282 } // namespace mojo |
278 | 283 |
279 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 284 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
OLD | NEW |