| 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_FXCODEC_JBIG2_JBIG2_LIST_H_ |
| 8 #define CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ | 8 #define CORE_FXCODEC_JBIG2_JBIG2_LIST_H_ |
| 9 | 9 |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| 11 | 11 |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 // A poor man's ScopedVector for pointers of TYPE. | 14 // A poor man's ScopedVector for pointers of TYPE. |
| 15 // Owns all the pointers contained within and deletes them on destruction. | 15 // Owns all the pointers contained within and deletes them on destruction. |
| 16 template <class TYPE> | 16 template <class TYPE> |
| 17 class CJBig2_List { | 17 class CJBig2_List { |
| 18 public: | 18 public: |
| 19 CJBig2_List() {} | 19 CJBig2_List() {} |
| 20 explicit CJBig2_List(size_t count) { resize(count); } | 20 explicit CJBig2_List(size_t count) { resize(count); } |
| 21 | 21 |
| 22 ~CJBig2_List() { | 22 ~CJBig2_List() { clear(); } |
| 23 clear(); | |
| 24 } | |
| 25 | 23 |
| 26 TYPE* get(size_t index) const { return m_vector[index]; } | 24 TYPE* get(size_t index) const { return m_vector[index]; } |
| 27 TYPE* back() const { return m_vector.back(); } | 25 TYPE* back() const { return m_vector.back(); } |
| 28 size_t size() const { return m_vector.size(); } | 26 size_t size() const { return m_vector.size(); } |
| 29 | 27 |
| 30 // Deletes all the pointers contained within. | 28 // Deletes all the pointers contained within. |
| 31 void clear() { | 29 void clear() { |
| 32 for (size_t i = 0; i < m_vector.size(); ++i) | 30 for (size_t i = 0; i < m_vector.size(); ++i) |
| 33 delete m_vector[i]; | 31 delete m_vector[i]; |
| 34 m_vector.clear(); | 32 m_vector.clear(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 void resize(size_t count) { | 44 void resize(size_t count) { |
| 47 for (size_t i = count; i < size(); ++i) | 45 for (size_t i = count; i < size(); ++i) |
| 48 delete m_vector[i]; | 46 delete m_vector[i]; |
| 49 m_vector.resize(count); | 47 m_vector.resize(count); |
| 50 } | 48 } |
| 51 | 49 |
| 52 private: | 50 private: |
| 53 std::vector<TYPE*> m_vector; | 51 std::vector<TYPE*> m_vector; |
| 54 }; | 52 }; |
| 55 | 53 |
| 56 #endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_ | 54 #endif // CORE_FXCODEC_JBIG2_JBIG2_LIST_H_ |
| OLD | NEW |