Home | History | Annotate | Download | only in jbig2
      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 _JBIG2_LIST_H_
      8 #define _JBIG2_LIST_H_
      9 #include "JBig2_Define.h"
     10 #include "JBig2_Object.h"
     11 template <class TYPE>
     12 class CJBig2_List : public CJBig2_Object
     13 {
     14 public:
     15 
     16     CJBig2_List(FX_INT32 nSize = 8)
     17     {
     18         m_nSize = nSize;
     19         m_pArray = (TYPE**)m_pModule->JBig2_Malloc2(sizeof(TYPE*), nSize);
     20         m_nLength = 0;
     21     }
     22 
     23     ~CJBig2_List()
     24     {
     25         clear();
     26         m_pModule->JBig2_Free(m_pArray);
     27     }
     28 
     29     void clear()
     30     {
     31         FX_INT32 i;
     32         for(i = 0; i < m_nLength; i++) {
     33             delete m_pArray[i];
     34         }
     35         m_nLength = 0;
     36     }
     37 
     38     void addItem(TYPE *pItem)
     39     {
     40         if(m_nLength >= m_nSize) {
     41             m_nSize += 8;
     42             m_pArray = (TYPE**)m_pModule->JBig2_Realloc(m_pArray, sizeof(TYPE*)*m_nSize);
     43         }
     44         m_pArray[m_nLength++] = pItem;
     45     }
     46 
     47 
     48     FX_INT32 getLength()
     49     {
     50         return m_nLength;
     51     }
     52 
     53     TYPE *getAt(FX_INT32 nIndex)
     54     {
     55         return m_pArray[nIndex];
     56     }
     57 
     58     TYPE *getLast()
     59     {
     60         return m_pArray[m_nLength - 1];
     61     }
     62 private:
     63     FX_INT32 m_nSize;
     64     TYPE **m_pArray;
     65     FX_INT32 m_nLength;
     66 };
     67 #endif
     68