]> git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/Array.cxx
Load cups into easysw/current.
[thirdparty/cups.git] / pdftops / Array.cxx
1 //========================================================================
2 //
3 // Array.cc
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <config.h>
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <stdlib.h>
16 #include <stddef.h>
17 #include "gmem.h"
18 #include "Object.h"
19 #include "Array.h"
20
21 //------------------------------------------------------------------------
22 // Array
23 //------------------------------------------------------------------------
24
25 Array::Array(XRef *xrefA) {
26 xref = xrefA;
27 elems = NULL;
28 size = length = 0;
29 ref = 1;
30 }
31
32 Array::~Array() {
33 int i;
34
35 for (i = 0; i < length; ++i)
36 elems[i].free();
37 gfree(elems);
38 }
39
40 void Array::add(Object *elem) {
41 if (length == size) {
42 if (length == 0) {
43 size = 8;
44 } else {
45 size *= 2;
46 }
47 elems = (Object *)greallocn(elems, size, sizeof(Object));
48 }
49 elems[length] = *elem;
50 ++length;
51 }
52
53 Object *Array::get(int i, Object *obj) {
54 if (i < 0 || i >= length) {
55 #ifdef DEBUG_MEM
56 abort();
57 #else
58 return obj->initNull();
59 #endif
60 }
61 return elems[i].fetch(xref, obj);
62 }
63
64 Object *Array::getNF(int i, Object *obj) {
65 if (i < 0 || i >= length) {
66 #ifdef DEBUG_MEM
67 abort();
68 #else
69 return obj->initNull();
70 #endif
71 }
72 return elems[i].copy(obj);
73 }