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

Last change on this file since 461 was 257, checked in by Eugene Romanenko, 13 years ago

PDF plugin: Poppler library updated to version 0.10.0

File size: 2.1 KB
Line 
1//========================================================================
2//
3// Array.cc
4//
5// Copyright 1996-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2005 Kristian HÞgsberg <krh@redhat.com>
17//
18// To see a description of the changes please see the Changelog file that
19// came with your tarball or type make ChangeLog if you are building from git
20//
21//========================================================================
22
23#include <config.h>
24
25#ifdef USE_GCC_PRAGMAS
26#pragma implementation
27#endif
28
29#include <stdlib.h>
30#include <stddef.h>
31#include "goo/gmem.h"
32#include "Object.h"
33#include "Array.h"
34
35//------------------------------------------------------------------------
36// Array
37//------------------------------------------------------------------------
38
39Array::Array(XRef *xrefA) {
40  xref = xrefA;
41  elems = NULL;
42  size = length = 0;
43  ref = 1;
44}
45
46Array::~Array() {
47  int i;
48
49  for (i = 0; i < length; ++i)
50    elems[i].free();
51  gfree(elems);
52}
53
54void Array::add(Object *elem) {
55  if (length == size) {
56    if (length == 0) {
57      size = 8;
58    } else {
59      size *= 2;
60    }
61    elems = (Object *)greallocn(elems, size, sizeof(Object));
62  }
63  elems[length] = *elem;
64  ++length;
65}
66
67Object *Array::get(int i, Object *obj) {
68  if (i < 0 || i >= length) {
69#ifdef DEBUG_MEM
70    abort();
71#else
72    return obj->initNull();
73#endif
74  }
75  return elems[i].fetch(xref, obj);
76}
77
78Object *Array::getNF(int i, Object *obj) {
79  if (i < 0 || i >= length) {
80#ifdef DEBUG_MEM
81    abort();
82#else
83    return obj->initNull();
84#endif
85  }
86  return elems[i].copy(obj);
87}
88
89GBool Array::getString(int i, GooString *string)
90{
91  Object obj;
92
93  if (getNF(i, &obj)->isString()) {
94    string->clear();
95    string->append(obj.getString());
96    obj.free();
97    return gTrue;
98  } else {
99    obj.free();
100    return gFalse;
101  }
102}
Note: See TracBrowser for help on using the repository browser.