| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ | 7 #ifndef CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ |
| 8 #define CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ | 8 #define CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 // A poor man's ScopedVector for pointers of TYPE. | 12 // A poor man's ScopedVector for pointers of TYPE. |
| 13 // Owns all the pointers contained within and deletes them on destruction. | 13 // Owns all the pointers contained within and deletes them on destruction. |
| 14 template <class TYPE> | 14 template <class TYPE> |
| 15 class CJBig2_List { | 15 class CJBig2_List { |
| 16 public: | 16 public: |
| 17 CJBig2_List() {} | 17 CJBig2_List() {} |
| 18 explicit CJBig2_List(size_t count) { resize(count); } |
| 18 | 19 |
| 19 ~CJBig2_List() { | 20 ~CJBig2_List() { |
| 20 clear(); | 21 clear(); |
| 21 } | 22 } |
| 22 | 23 |
| 23 TYPE* get(size_t index) const { return m_vector[index]; } | 24 TYPE* get(size_t index) const { return m_vector[index]; } |
| 24 TYPE* back() const { return m_vector.back(); } | 25 TYPE* back() const { return m_vector.back(); } |
| 25 size_t size() const { return m_vector.size(); } | 26 size_t size() const { return m_vector.size(); } |
| 26 | 27 |
| 27 // Deletes all the pointers contained within. | 28 // Deletes all the pointers contained within. |
| 28 void clear() { | 29 void clear() { |
| 29 for (size_t i = 0; i < m_vector.size(); ++i) | 30 for (size_t i = 0; i < m_vector.size(); ++i) |
| 30 delete m_vector[i]; | 31 delete m_vector[i]; |
| 31 m_vector.clear(); | 32 m_vector.clear(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 // Takes ownership of |pItem|. | 35 // Takes ownership of |pItem|. |
| 35 void push_back(TYPE* pItem) { m_vector.push_back(pItem); } | 36 void push_back(TYPE* pItem) { m_vector.push_back(pItem); } |
| 36 | 37 |
| 38 // Takes ownership of |pItem|. |
| 39 void set(size_t index, TYPE* pItem) { |
| 40 delete m_vector[index]; |
| 41 m_vector[index] = pItem; |
| 42 } |
| 43 |
| 37 void resize(size_t count) { | 44 void resize(size_t count) { |
| 38 for (size_t i = count; i < size(); ++i) | 45 for (size_t i = count; i < size(); ++i) |
| 39 delete m_vector[i]; | 46 delete m_vector[i]; |
| 40 m_vector.resize(count); | 47 m_vector.resize(count); |
| 41 } | 48 } |
| 42 | 49 |
| 43 private: | 50 private: |
| 44 std::vector<TYPE*> m_vector; | 51 std::vector<TYPE*> m_vector; |
| 45 }; | 52 }; |
| 46 | 53 |
| 47 #endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ | 54 #endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ |
| OLD | NEW |