source: trunk/poppler/mypoppler/poppler/Array.cc @ 2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 16 years ago

First import

File size: 1.6 KB
Line 
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 "goo/gmem.h"
18#include "Object.h"
19#include "Array.h"
20
21//------------------------------------------------------------------------
22// Array
23//------------------------------------------------------------------------
24
25Array::Array(XRef *xrefA) {
26  xref = xrefA;
27  elems = NULL;
28  size = length = 0;
29  ref = 1;
30}
31
32Array::~Array() {
33  int i;
34
35  for (i = 0; i < length; ++i)
36    elems[i].free();
37  gfree(elems);
38}
39
40void 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
53Object *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
64Object *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}
74
75GBool Array::getString(int i, GooString *string)
76{
77  Object obj;
78
79  if (getNF(i, &obj)->isString()) {
80    string->clear();
81    string->append(obj.getString());
82    obj.free();
83    return gTrue;
84  } else {
85    obj.free();
86    return gFalse;
87  }
88}
Note: See TracBrowser for help on using the repository browser.