summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/goo/GList.cc
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/goo/GList.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/goo/GList.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/goo/GList.cc b/noncore/unsupported/qpdf/goo/GList.cc
new file mode 100644
index 0000000..cfe0a25
--- a/dev/null
+++ b/noncore/unsupported/qpdf/goo/GList.cc
@@ -0,0 +1,91 @@
1//========================================================================
2//
3// GList.cc
4//
5// Copyright 2001 Derek B. Noonburg
6//
7//========================================================================
8
9#ifdef __GNUC__
10#pragma implementation
11#endif
12
13#include <aconf.h>
14#include <string.h>
15#include "gmem.h"
16#include "GList.h"
17
18//------------------------------------------------------------------------
19// GList
20//------------------------------------------------------------------------
21
22GList::GList() {
23 size = 8;
24 data = (void **)gmalloc(size * sizeof(void*));
25 length = 0;
26 inc = 0;
27}
28
29GList::GList(int sizeA) {
30 size = sizeA;
31 data = (void **)gmalloc(size * sizeof(void*));
32 length = 0;
33 inc = 0;
34}
35
36GList::~GList() {
37 gfree(data);
38}
39
40void GList::append(void *p) {
41 if (length >= size) {
42 expand();
43 }
44 data[length++] = p;
45}
46
47void GList::append(GList *list) {
48 int i;
49
50 while (length + list->length > size) {
51 expand();
52 }
53 for (i = 0; i < list->length; ++i) {
54 data[length++] = list->data[i];
55 }
56}
57
58void GList::insert(int i, void *p) {
59 if (length >= size) {
60 expand();
61 }
62 if (i < length) {
63 memmove(data+i+1, data+i, (length - i) * sizeof(void *));
64 }
65 data[i] = p;
66 ++length;
67}
68
69void *GList::del(int i) {
70 void *p;
71
72 p = data[i];
73 if (i < length - 1) {
74 memmove(data+i, data+i+1, (length - i - 1) * sizeof(void *));
75 }
76 --length;
77 if (size - length >= ((inc > 0) ? inc : size/2)) {
78 shrink();
79 }
80 return p;
81}
82
83void GList::expand() {
84 size += (inc > 0) ? inc : size;
85 data = (void **)grealloc(data, size * sizeof(void*));
86}
87
88void GList::shrink() {
89 size -= (inc > 0) ? inc : size/2;
90 data = (void **)grealloc(data, size * sizeof(void*));
91}