forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / arospdf / goo / GList.h
blobe4d8ff8f1c28d13d3918f2b62ec479c8462b0e99
1 //========================================================================
2 //
3 // GList.h
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef GLIST_H
10 #define GLIST_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include "gtypes.h"
20 //------------------------------------------------------------------------
21 // GList
22 //------------------------------------------------------------------------
24 class GList {
25 public:
27 // Create an empty list.
28 GList();
30 // Create an empty list with space for <size1> elements.
31 GList(int sizeA);
33 // Destructor - does not free pointed-to objects.
34 ~GList();
36 //----- general
38 // Get the number of elements.
39 int getLength() { return length; }
41 //----- ordered list support
43 // Return the <i>th element.
44 // Assumes 0 <= i < length.
45 void *get(int i) { return data[i]; }
47 // Append an element to the end of the list.
48 void append(void *p);
50 // Append another list to the end of this one.
51 void append(GList *list);
53 // Insert an element at index <i>.
54 // Assumes 0 <= i <= length.
55 void insert(int i, void *p);
57 // Deletes and returns the element at index <i>.
58 // Assumes 0 <= i < length.
59 void *del(int i);
61 // Sort the list accoring to the given comparison function.
62 // NB: this sorts an array of pointers, so the pointer args need to
63 // be double-dereferenced.
64 void sort(int (*cmp)(const void *ptr1, const void *ptr2));
66 //----- control
68 // Set allocation increment to <inc>. If inc > 0, that many
69 // elements will be allocated every time the list is expanded.
70 // If inc <= 0, the list will be doubled in size.
71 void setAllocIncr(int incA) { inc = incA; }
73 private:
75 void expand();
76 void shrink();
78 void **data; // the list elements
79 int size; // size of data array
80 int length; // number of elements on list
81 int inc; // allocation increment
84 #define deleteGList(list, T) \
85 do { \
86 GList *_list = (list); \
87 { \
88 int _i; \
89 for (_i = 0; _i < _list->getLength(); ++_i) { \
90 delete (T*)_list->get(_i); \
91 } \
92 delete _list; \
93 } \
94 } while (0)
96 #endif