summaryrefslogtreecommitdiffstats
path: root/kpdf/xpdf/xpdf/Array.cc
diff options
context:
space:
mode:
Diffstat (limited to 'kpdf/xpdf/xpdf/Array.cc')
-rw-r--r--kpdf/xpdf/xpdf/Array.cc88
1 files changed, 88 insertions, 0 deletions
diff --git a/kpdf/xpdf/xpdf/Array.cc b/kpdf/xpdf/xpdf/Array.cc
new file mode 100644
index 00000000..8232037b
--- /dev/null
+++ b/kpdf/xpdf/xpdf/Array.cc
@@ -0,0 +1,88 @@
+//========================================================================
+//
+// 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 "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);
+}
+
+GBool Array::getString(int i, GString *string)
+{
+ Object obj;
+
+ if (getNF(i, &obj)->isString()) {
+ string->clear();
+ string->append(obj.getString());
+ obj.free();
+ return gTrue;
+ } else {
+ obj.free();
+ return gFalse;
+ }
+}