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