source: trunk/poppler/mypoppler/goo/GooList.h @ 515

Last change on this file since 515 was 515, checked in by Silvan Scherrer, 9 years ago

updated poppler to 0.20.3

File size: 2.7 KB
Line 
1//========================================================================
2//
3// GooList.h
4//
5// Copyright 2001-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9#ifndef GLIST_H
10#define GLIST_H
11
12#ifdef USE_GCC_PRAGMAS
13#pragma interface
14#endif
15
16#include "gtypes.h"
17
18//------------------------------------------------------------------------
19// GooList
20//------------------------------------------------------------------------
21
22class GooList {
23public:
24
25  // Create an empty list.
26  GooList();
27
28  // Create an empty list with space for <size1> elements.
29  GooList(int sizeA);
30
31  // Destructor - does not free pointed-to objects.
32  ~GooList();
33
34  //----- general
35
36  // Get the number of elements.
37  int getLength() { return length; }
38
39  // Returns a (shallow) copy of this list.
40  GooList *copy();
41
42  //----- ordered list support
43
44  // Return the <i>th element.
45  // Assumes 0 <= i < length.
46  void *get(int i) { return data[i]; }
47
48  // Replace the <i>th element.
49  // Assumes 0 <= i < length.
50  void put(int i, void *p) { data[i] = p; }
51
52  // Append an element to the end of the list.
53  void append(void *p);
54
55  // Append another list to the end of this one.
56  void append(GooList *list);
57
58  // Insert an element at index <i>.
59  // Assumes 0 <= i <= length.
60  void insert(int i, void *p);
61
62  // Deletes and returns the element at index <i>.
63  // Assumes 0 <= i < length.
64  void *del(int i);
65
66  // Sort the list accoring to the given comparison function.
67  // NB: this sorts an array of pointers, so the pointer args need to
68  // be double-dereferenced.
69  void sort(int (*cmp)(const void *ptr1, const void *ptr2));
70
71  // Reverse the list.
72  void reverse();
73
74  //----- control
75
76  // Set allocation increment to <inc>.  If inc > 0, that many
77  // elements will be allocated every time the list is expanded.
78  // If inc <= 0, the list will be doubled in size.
79  void setAllocIncr(int incA) { inc = incA; }
80
81private:
82
83  void expand();
84  void shrink();
85
86  void **data;                  // the list elements
87  int size;                     // size of data array
88  int length;                   // number of elements on list
89  int inc;                      // allocation increment
90};
91
92#define deleteGooList(list, T)                        \
93  do {                                              \
94    GooList *_list = (list);                          \
95    {                                               \
96      int _i;                                       \
97      for (_i = 0; _i < _list->getLength(); ++_i) { \
98        delete (T*)_list->get(_i);                  \
99      }                                             \
100      delete _list;                                 \
101    }                                               \
102  } while (0)
103
104#endif
Note: See TracBrowser for help on using the repository browser.