| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_WTF_ARRAY_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // contain any elements. | 81 // contain any elements. |
| 82 DCHECK(!is_null_ || vec_.isEmpty()); | 82 DCHECK(!is_null_ || vec_.isEmpty()); |
| 83 return is_null_; | 83 return is_null_; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Indicates whether the array is empty (which is distinct from null). | 86 // Indicates whether the array is empty (which is distinct from null). |
| 87 bool empty() const { return vec_.isEmpty() && !is_null_; } | 87 bool empty() const { return vec_.isEmpty() && !is_null_; } |
| 88 | 88 |
| 89 // Returns a reference to the first element of the array. Calling this on a | 89 // Returns a reference to the first element of the array. Calling this on a |
| 90 // null or empty array causes undefined behavior. | 90 // null or empty array causes undefined behavior. |
| 91 const T& front() const { return vec_.first(); } | 91 const T& front() const { return vec_.front(); } |
| 92 T& front() { return vec_.first(); } | 92 T& front() { return vec_.front(); } |
| 93 | 93 |
| 94 // Returns the size of the array, which will be zero if the array is null. | 94 // Returns the size of the array, which will be zero if the array is null. |
| 95 size_t size() const { return vec_.size(); } | 95 size_t size() const { return vec_.size(); } |
| 96 | 96 |
| 97 // Returns a reference to the element at zero-based |offset|. Calling this on | 97 // Returns a reference to the element at zero-based |offset|. Calling this on |
| 98 // an array with size less than |offset|+1 causes undefined behavior. | 98 // an array with size less than |offset|+1 causes undefined behavior. |
| 99 const T& at(size_t offset) const { return vec_.at(offset); } | 99 const T& at(size_t offset) const { return vec_.at(offset); } |
| 100 const T& operator[](size_t offset) const { return at(offset); } | 100 const T& operator[](size_t offset) const { return at(offset); } |
| 101 T& at(size_t offset) { return vec_.at(offset); } | 101 T& at(size_t offset) { return vec_.at(offset); } |
| 102 T& operator[](size_t offset) { return at(offset); } | 102 T& operator[](size_t offset) { return at(offset); } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 WTF::Vector<T> vec_; | 189 WTF::Vector<T> vec_; |
| 190 bool is_null_; | 190 bool is_null_; |
| 191 | 191 |
| 192 DISALLOW_COPY_AND_ASSIGN(WTFArray); | 192 DISALLOW_COPY_AND_ASSIGN(WTFArray); |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 } // namespace mojo | 195 } // namespace mojo |
| 196 | 196 |
| 197 #endif // MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ | 197 #endif // MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ |
| OLD | NEW |