summaryrefslogtreecommitdiff
path: root/core/src/fxcodec/jbig2/JBig2_List.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/fxcodec/jbig2/JBig2_List.h')
-rw-r--r--core/src/fxcodec/jbig2/JBig2_List.h25
1 files changed, 16 insertions, 9 deletions
diff --git a/core/src/fxcodec/jbig2/JBig2_List.h b/core/src/fxcodec/jbig2/JBig2_List.h
index e033eb23ea..ffdd22c3ca 100644
--- a/core/src/fxcodec/jbig2/JBig2_List.h
+++ b/core/src/fxcodec/jbig2/JBig2_List.h
@@ -4,11 +4,13 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _JBIG2_LIST_H_
-#define _JBIG2_LIST_H_
+#ifndef CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_
+#define CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_
#include <vector>
+// A poor man's ScopedVector for pointers of TYPE.
+// Owns all the pointers contained within and deletes them on destruction.
template <class TYPE>
class CJBig2_List {
public:
@@ -18,23 +20,28 @@ class CJBig2_List {
clear();
}
+ TYPE* get(size_t index) const { return m_vector[index]; }
+ TYPE* back() const { return m_vector.back(); }
+ size_t size() const { return m_vector.size(); }
+
+ // Deletes all the pointers contained within.
void clear() {
for (size_t i = 0; i < m_vector.size(); ++i)
delete m_vector[i];
m_vector.clear();
}
+ // Takes ownership of |pItem|.
void push_back(TYPE* pItem) { m_vector.push_back(pItem); }
- size_t size() const { return m_vector.size(); }
- void resize(size_t count) { m_vector.resize(count); }
-
- TYPE* get(size_t index) { return m_vector[index]; }
-
- TYPE* back() { return m_vector.back(); }
+ void resize(size_t count) {
+ for (size_t i = count; i < size(); ++i)
+ delete m_vector[i];
+ m_vector.resize(count);
+ }
private:
std::vector<TYPE*> m_vector;
};
-#endif
+#endif // CORE_SRC_FXCODEC_JBIG2_JBIG2_LIST_H_