]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/Array.cc
Reused eog HIG dialog in GPdf.
[evince.git] / pdf / xpdf / Array.cc
1 //========================================================================
2 //
3 // Array.cc
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <aconf.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 + 1 > size) {
42     size += 8;
43     elems = (Object *)grealloc(elems, size * sizeof(Object));
44   }
45   elems[length] = *elem;
46   ++length;
47 }
48
49 Object *Array::get(int i, Object *obj) {
50   if (i < 0 || i >= length) {
51 #ifdef DEBUG_MEM
52     abort();
53 #else
54     return obj->initNull();
55 #endif
56   }
57   return elems[i].fetch(xref, obj);
58 }
59
60 Object *Array::getNF(int i, Object *obj) {
61   if (i < 0 || i >= length) {
62 #ifdef DEBUG_MEM
63     abort();
64 #else
65     return obj->initNull();
66 #endif
67   }
68   return elems[i].copy(obj);
69 }