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 _JBIG2_LIST_H_ | 7 #ifndef CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ |
8 #define _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. |
| 13 // Owns all the pointers contained within and deletes them on destruction. |
12 template <class TYPE> | 14 template <class TYPE> |
13 class CJBig2_List { | 15 class CJBig2_List { |
14 public: | 16 public: |
15 CJBig2_List() {} | 17 CJBig2_List() {} |
16 | 18 |
17 ~CJBig2_List() { | 19 ~CJBig2_List() { |
18 clear(); | 20 clear(); |
19 } | 21 } |
20 | 22 |
| 23 TYPE* get(size_t index) const { return m_vector[index]; } |
| 24 TYPE* back() const { return m_vector.back(); } |
| 25 size_t size() const { return m_vector.size(); } |
| 26 |
| 27 // Deletes all the pointers contained within. |
21 void clear() { | 28 void clear() { |
22 for (size_t i = 0; i < m_vector.size(); ++i) | 29 for (size_t i = 0; i < m_vector.size(); ++i) |
23 delete m_vector[i]; | 30 delete m_vector[i]; |
24 m_vector.clear(); | 31 m_vector.clear(); |
25 } | 32 } |
26 | 33 |
| 34 // Takes ownership of |pItem|. |
27 void push_back(TYPE* pItem) { m_vector.push_back(pItem); } | 35 void push_back(TYPE* pItem) { m_vector.push_back(pItem); } |
28 | 36 |
29 size_t size() const { return m_vector.size(); } | 37 void resize(size_t count) { |
30 void resize(size_t count) { m_vector.resize(count); } | 38 for (size_t i = count; i < size(); ++i) |
31 | 39 delete m_vector[i]; |
32 TYPE* get(size_t index) { return m_vector[index]; } | 40 m_vector.resize(count); |
33 | 41 } |
34 TYPE* back() { return m_vector.back(); } | |
35 | 42 |
36 private: | 43 private: |
37 std::vector<TYPE*> m_vector; | 44 std::vector<TYPE*> m_vector; |
38 }; | 45 }; |
39 | 46 |
40 #endif | 47 #endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ |
OLD | NEW |