4c52489f35db22acd3103d4862cdbb6144fba8db
[swftools.git] / pdf2swf / xpdf / GList.h
1 //========================================================================
2 //
3 // GList.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef GLIST_H
10 #define GLIST_H
11
12 #include <aconf.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include "gtypes.h"
19
20 //------------------------------------------------------------------------
21 // GList
22 //------------------------------------------------------------------------
23
24 class GList {
25 public:
26
27   // Create an empty list.
28   GList();
29
30   // Create an empty list with space for <size1> elements.
31   GList(int sizeA);
32
33   // Destructor - does not free pointed-to objects.
34   ~GList();
35
36   //----- general
37
38   // Get the number of elements.
39   int getLength() { return length; }
40
41   //----- ordered list support
42
43   // Return the <i>th element.
44   // Assumes 0 <= i < length.
45   void *get(int i) { return data[i]; }
46
47   // Append an element to the end of the list.
48   void append(void *p);
49
50   // Append another list to the end of this one.
51   void append(GList *list);
52
53   // Insert an element at index <i>.
54   // Assumes 0 <= i <= length.
55   void insert(int i, void *p);
56
57   // Deletes and returns the element at index <i>.
58   // Assumes 0 <= i < length.
59   void *del(int i);
60
61   //----- control
62
63   // Set allocation increment to <inc>.  If inc > 0, that many
64   // elements will be allocated every time the list is expanded.
65   // If inc <= 0, the list will be doubled in size.
66   void setAllocIncr(int incA) { inc = incA; }
67
68 private:
69
70   void expand();
71   void shrink();
72
73   void **data;                  // the list elements
74   int size;                     // size of data array
75   int length;                   // number of elements on list
76   int inc;                      // allocation increment
77 };
78
79 #define deleteGList(list, T)                        \
80   do {                                              \
81     GList *_list = (list);                          \
82     {                                               \
83       int _i;                                       \
84       for (_i = 0; _i < _list->getLength(); ++_i) { \
85         delete (T*)_list->get(_i);                  \
86       }                                             \
87       delete _list;                                 \
88     }                                               \
89   } while (0)
90
91 #endif