1 //========================================================================
5 // Copyright 1996-2002 Glyph & Cog, LLC
7 //========================================================================
10 #pragma implementation
22 //------------------------------------------------------------------------
24 //------------------------------------------------------------------------
26 char *objTypeNames[numObjTypes] = {
44 int Object::numAlloc[numObjTypes] =
45 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
48 Object *Object::initArray(XRef *xref) {
50 array = new Array(xref);
54 Object *Object::initDict(XRef *xref) {
56 dict = new Dict(xref);
60 Object *Object::initStream(Stream *streamA) {
66 Object *Object::copy(Object *obj) {
70 obj->string = string->copy();
73 obj->name = copyString(name);
85 obj->cmd = copyString(cmd);
96 Object *Object::fetch(XRef *xref, Object *obj) {
97 return (type == objRef && xref) ?
98 xref->fetch(ref.num, ref.gen, obj) : copy(obj);
101 void Object::free() {
110 if (!array->decRef()) {
115 if (!dict->decRef()) {
120 if (!stream->decRef()) {
136 char *Object::getTypeName() {
137 return objTypeNames[type];
140 void Object::print(FILE *f) {
146 fprintf(f, "%s", booln ? "true" : "false");
149 fprintf(f, "%d", intg);
152 fprintf(f, "%g", real);
156 fwrite(string->getCString(), 1, string->getLength(), stdout);
160 fprintf(f, "/%s", name);
167 for (i = 0; i < arrayGetLength(); ++i) {
178 for (i = 0; i < dictGetLength(); ++i) {
179 fprintf(f, " /%s ", dictGetKey(i));
180 dictGetValNF(i, &obj);
187 fprintf(f, "<stream>");
190 fprintf(f, "%d %d R", ref.num, ref.gen);
193 fprintf(f, "%s", cmd);
196 fprintf(f, "<error>");
202 fprintf(f, "<none>");
207 void Object::memCheck(FILE *f) {
213 for (i = 0; i < numObjTypes; ++i)
216 fprintf(f, "Allocated objects:\n");
217 for (i = 0; i < numObjTypes; ++i) {
219 fprintf(f, " %-20s: %6d\n", objTypeNames[i], numAlloc[i]);