synch with TL 38104
[luatex.git] / source / libs / poppler / poppler-0.35.0 / goo / GooList.h
blobc83a0e36a8abc11d481c7eb38ce2d027e5dda58a
1 //========================================================================
2 //
3 // GooList.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2012 Albert Astals Cid <aacid@kde.org>
18 // To see a description of the changes please see the Changelog file that
19 // came with your tarball or type make ChangeLog if you are building from git
21 //========================================================================
23 #ifndef GLIST_H
24 #define GLIST_H
26 #ifdef USE_GCC_PRAGMAS
27 #pragma interface
28 #endif
30 #include "gtypes.h"
32 //------------------------------------------------------------------------
33 // GooList
34 //------------------------------------------------------------------------
36 class GooList {
37 public:
39 // Create an empty list.
40 GooList();
42 // Create an empty list with space for <size1> elements.
43 GooList(int sizeA);
45 // Destructor - does not free pointed-to objects.
46 ~GooList();
48 //----- general
50 // Get the number of elements.
51 int getLength() { return length; }
53 // Returns a (shallow) copy of this list.
54 GooList *copy();
56 //----- ordered list support
58 // Return the <i>th element.
59 // Assumes 0 <= i < length.
60 void *get(int i) { return data[i]; }
62 // Replace the <i>th element.
63 // Assumes 0 <= i < length.
64 void put(int i, void *p) { data[i] = p; }
66 // Append an element to the end of the list.
67 void append(void *p);
69 // Append another list to the end of this one.
70 void append(GooList *list);
72 // Insert an element at index <i>.
73 // Assumes 0 <= i <= length.
74 void insert(int i, void *p);
76 // Deletes and returns the element at index <i>.
77 // Assumes 0 <= i < length.
78 void *del(int i);
80 // Sort the list accoring to the given comparison function.
81 // NB: this sorts an array of pointers, so the pointer args need to
82 // be double-dereferenced.
83 void sort(int (*cmp)(const void *ptr1, const void *ptr2));
85 // Reverse the list.
86 void reverse();
88 //----- control
90 // Set allocation increment to <inc>. If inc > 0, that many
91 // elements will be allocated every time the list is expanded.
92 // If inc <= 0, the list will be doubled in size.
93 void setAllocIncr(int incA) { inc = incA; }
95 private:
96 GooList(const GooList &other);
97 GooList& operator=(const GooList &other);
99 void expand();
100 void shrink();
102 void **data; // the list elements
103 int size; // size of data array
104 int length; // number of elements on list
105 int inc; // allocation increment
108 #define deleteGooList(list, T) \
109 do { \
110 GooList *_list = (list); \
112 int _i; \
113 for (_i = 0; _i < _list->getLength(); ++_i) { \
114 delete (T*)_list->get(_i); \
116 delete _list; \
118 } while (0)
120 #endif