| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 RefVector_h | 5 #include "platform/wtf/RefVector.h" |
| 6 #define RefVector_h | |
| 7 | 6 |
| 8 #include "wtf/RefCounted.h" | 7 // The contents of this header was moved to platform/wtf as part of |
| 9 #include "wtf/RefPtr.h" | 8 // WTF migration project. See the following post for details: |
| 10 #include "wtf/Vector.h" | 9 // https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gY
CAAJ |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 template <typename T> | |
| 15 class RefVector : public RefCounted<RefVector<T>> { | |
| 16 public: | |
| 17 static PassRefPtr<RefVector> create() { return adoptRef(new RefVector<T>); } | |
| 18 static PassRefPtr<RefVector> create(const Vector<T>& vector) { | |
| 19 return adoptRef(new RefVector<T>(vector)); | |
| 20 } | |
| 21 static PassRefPtr<RefVector> create(Vector<T>&& vector) { | |
| 22 return adoptRef(new RefVector<T>(vector)); | |
| 23 } | |
| 24 PassRefPtr<RefVector> copy() { return create(vector()); } | |
| 25 | |
| 26 const T& operator[](size_t i) const { return m_vector[i]; } | |
| 27 T& operator[](size_t i) { return m_vector[i]; } | |
| 28 const T& at(size_t i) const { return m_vector.at(i); } | |
| 29 T& at(size_t i) { return m_vector.at(i); } | |
| 30 | |
| 31 bool operator==(const RefVector& o) const { return m_vector == o.m_vector; } | |
| 32 bool operator!=(const RefVector& o) const { return m_vector != o.m_vector; } | |
| 33 | |
| 34 size_t size() const { return m_vector.size(); } | |
| 35 bool isEmpty() const { return !size(); } | |
| 36 void append(const T& decoration) { m_vector.push_back(decoration); } | |
| 37 const Vector<T>& vector() const { return m_vector; } | |
| 38 | |
| 39 private: | |
| 40 Vector<T> m_vector; | |
| 41 RefVector() {} | |
| 42 RefVector(const Vector<T>& vector) : m_vector(vector) {} | |
| 43 RefVector(Vector<T>&& vector) : m_vector(vector) {} | |
| 44 }; | |
| 45 | |
| 46 } // namespace blink | |
| 47 | |
| 48 #endif // RefVector_h | |
| OLD | NEW |