1 //========================================================================
5 // Copyright 1996-2003 Glyph & Cog, LLC
7 //========================================================================
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
23 //------------------------------------------------------------------------
25 //------------------------------------------------------------------------
27 char *objTypeNames[numObjTypes] = {
45 int Object::numAlloc[numObjTypes] =
46 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
49 Object *Object::initArray(XRef *xref) {
51 array = new Array(xref);
55 Object *Object::initDict(XRef *xref) {
57 dict = new Dict(xref);
61 Object *Object::initDict(Dict *dictA) {
68 Object *Object::initStream(Stream *streamA) {
74 Object *Object::copy(Object *obj) {
78 obj->string = string->copy();
81 obj->name = copyString(name);
93 obj->cmd = copyString(cmd);
104 Object *Object::fetch(XRef *xref, Object *obj) {
105 return (type == objRef && xref) ?
106 xref->fetch(ref.num, ref.gen, obj) : copy(obj);
109 void Object::free() {
118 if (!array->decRef()) {
123 if (!dict->decRef()) {
128 if (!stream->decRef()) {
144 char *Object::getTypeName() {
145 return objTypeNames[type];
148 void Object::print(FILE *f) {
154 fprintf(f, "%s", booln ? "true" : "false");
157 fprintf(f, "%d", intg);
160 fprintf(f, "%g", real);
164 fwrite(string->getCString(), 1, string->getLength(), f);
168 fprintf(f, "/%s", name);
175 for (i = 0; i < arrayGetLength(); ++i) {
186 for (i = 0; i < dictGetLength(); ++i) {
187 fprintf(f, " /%s ", dictGetKey(i));
188 dictGetValNF(i, &obj);
195 fprintf(f, "<stream>");
198 fprintf(f, "%d %d R", ref.num, ref.gen);
201 fprintf(f, "%s", cmd);
204 fprintf(f, "<error>");
210 fprintf(f, "<none>");
215 void Object::memCheck(FILE *f) {
221 for (i = 0; i < numObjTypes; ++i)
224 fprintf(f, "Allocated objects:\n");
225 for (i = 0; i < numObjTypes; ++i) {
227 fprintf(f, " %-20s: %6d\n", objTypeNames[i], numAlloc[i]);