1 //========================================================================
5 // Copyright 2001-2003 Glyph & Cog, LLC
7 //========================================================================
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
20 //------------------------------------------------------------------------
22 //------------------------------------------------------------------------
26 data
= (void **)gmallocn(size
, sizeof(void*));
31 GooList::GooList(int sizeA
) {
32 size
= sizeA
? sizeA
: 8;
33 data
= (void **)gmallocn(size
, sizeof(void*));
42 GooList
*GooList::copy() {
45 ret
= new GooList(length
);
47 memcpy(ret
->data
, data
, length
* sizeof(void *));
52 void GooList::append(void *p
) {
59 void GooList::append(GooList
*list
) {
62 while (length
+ list
->length
> size
) {
65 for (i
= 0; i
< list
->length
; ++i
) {
66 data
[length
++] = list
->data
[i
];
70 void GooList::insert(int i
, void *p
) {
78 memmove(data
+i
+1, data
+i
, (length
- i
) * sizeof(void *));
84 void *GooList::del(int i
) {
89 memmove(data
+i
, data
+i
+1, (length
- i
- 1) * sizeof(void *));
92 if (size
- length
>= ((inc
> 0) ? inc
: size
/2)) {
98 void GooList::sort(int (*cmp
)(const void *obj1
, const void *obj2
)) {
99 qsort(data
, length
, sizeof(void *), cmp
);
102 void GooList::reverse() {
107 for (i
= 0; i
< n
; ++i
) {
109 data
[i
] = data
[length
- 1 - i
];
110 data
[length
- 1 - i
] = t
;
114 void GooList::expand() {
115 size
+= (inc
> 0) ? inc
: size
;
116 data
= (void **)greallocn(data
, size
, sizeof(void*));
119 void GooList::shrink() {
120 size
-= (inc
> 0) ? inc
: size
/2;
121 data
= (void **)greallocn(data
, size
, sizeof(void*));