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