1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2008, 2010, 2012 Albert Astals Cid <aacid@kde.org>
17 // Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
19 // To see a description of the changes please see the Changelog file that
20 // came with your tarball or type make ChangeLog if you are building from git
22 //========================================================================
26 #ifdef USE_GCC_PRAGMAS
27 #pragma implementation
38 //------------------------------------------------------------------------
40 //------------------------------------------------------------------------
42 static const char *objTypeNames
[numObjTypes
] = {
61 int Object::numAlloc
[numObjTypes
] =
62 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
65 Object
*Object::initArray(XRef
*xref
) {
67 array
= new Array(xref
);
71 Object
*Object::initDict(XRef
*xref
) {
73 dict
= new Dict(xref
);
77 Object
*Object::initDict(Dict
*dictA
) {
84 Object
*Object::initStream(Stream
*streamA
) {
90 Object
*Object::copy(Object
*obj
) {
94 obj
->string
= string
->copy();
97 obj
->name
= copyString(name
);
109 obj
->cmd
= copyString(cmd
);
120 Object
*Object::fetch(XRef
*xref
, Object
*obj
, int recursion
) {
121 return (type
== objRef
&& xref
) ?
122 xref
->fetch(ref
.num
, ref
.gen
, obj
, recursion
) : copy(obj
);
125 void Object::free() {
134 if (!array
->decRef()) {
139 if (!dict
->decRef()) {
144 if (!stream
->decRef()) {
160 const char *Object::getTypeName() {
161 return objTypeNames
[type
];
164 void Object::print(FILE *f
) {
170 fprintf(f
, "%s", booln
? "true" : "false");
173 fprintf(f
, "%d", intg
);
176 fprintf(f
, "%g", real
);
180 fwrite(string
->getCString(), 1, string
->getLength(), f
);
184 fprintf(f
, "/%s", name
);
191 for (i
= 0; i
< arrayGetLength(); ++i
) {
202 for (i
= 0; i
< dictGetLength(); ++i
) {
203 fprintf(f
, " /%s ", dictGetKey(i
));
204 dictGetValNF(i
, &obj
);
211 fprintf(f
, "<stream>");
214 fprintf(f
, "%d %d R", ref
.num
, ref
.gen
);
217 fprintf(f
, "%s", cmd
);
220 fprintf(f
, "<error>");
226 fprintf(f
, "<none>");
229 fprintf(f
, "%lld", int64g
);
234 void Object::memCheck(FILE *f
) {
240 for (i
= 0; i
< numObjTypes
; ++i
)
243 fprintf(f
, "Allocated objects:\n");
244 for (i
= 0; i
< numObjTypes
; ++i
) {
246 fprintf(f
, " %-20s: %6d\n", objTypeNames
[i
], numAlloc
[i
]);