summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/xpdf/Object.h
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/Object.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/Object.h299
1 files changed, 299 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/Object.h b/noncore/unsupported/qpdf/xpdf/Object.h
new file mode 100644
index 0000000..000ffa0
--- a/dev/null
+++ b/noncore/unsupported/qpdf/xpdf/Object.h
@@ -0,0 +1,299 @@
1//========================================================================
2//
3// Object.h
4//
5// Copyright 1996 Derek B. Noonburg
6//
7//========================================================================
8
9#ifndef OBJECT_H
10#define OBJECT_H
11
12#ifdef __GNUC__
13#pragma interface
14#endif
15
16#include <stdio.h>
17#include <string.h>
18#include "gtypes.h"
19#include "gmem.h"
20#include "GString.h"
21
22class XRef;
23class Array;
24class Dict;
25class Stream;
26
27//------------------------------------------------------------------------
28// Ref
29//------------------------------------------------------------------------
30
31struct Ref {
32 int num; // object number
33 int gen; // generation number
34};
35
36//------------------------------------------------------------------------
37// object types
38//------------------------------------------------------------------------
39
40enum ObjType {
41 // simple objects
42 objBool, // boolean
43 objInt, // integer
44 objReal, // real
45 objString, // string
46 objName, // name
47 objNull, // null
48
49 // complex objects
50 objArray, // array
51 objDict, // dictionary
52 objStream, // stream
53 objRef, // indirect reference
54
55 // special objects
56 objCmd, // command name
57 objError, // error return from Lexer
58 objEOF, // end of file return from Lexer
59 objNone // uninitialized object
60};
61
62 #define numObjTypes 14 // total number of object types
63
64//------------------------------------------------------------------------
65// Object
66//------------------------------------------------------------------------
67
68#ifdef DEBUG_MEM
69#define initObj(t) ++numAlloc[type = t]
70#else
71#define initObj(t) type = t
72#endif
73
74class Object {
75public:
76
77 // Default constructor.
78 Object():
79 type(objNone) {}
80
81 // Initialize an object.
82 Object *initBool(GBool boolnA)
83 { initObj(objBool); booln = boolnA; return this; }
84 Object *initInt(int intgA)
85 { initObj(objInt); intg = intgA; return this; }
86 Object *initReal(fouble realA)
87 { initObj(objReal); real = realA; return this; }
88 Object *initString(GString *stringA)
89 { initObj(objString); string = stringA; return this; }
90 Object *initName(char *nameA)
91 { initObj(objName); name = copyString(nameA); return this; }
92 Object *initNull()
93 { initObj(objNull); return this; }
94 Object *initArray(XRef *xref);
95 Object *initDict(XRef *xref);
96 Object *initStream(Stream *streamA);
97 Object *initRef(int numA, int genA)
98 { initObj(objRef); ref.num = numA; ref.gen = genA; return this; }
99 Object *initCmd(char *cmdA)
100 { initObj(objCmd); cmd = copyString(cmdA); return this; }
101 Object *initError()
102 { initObj(objError); return this; }
103 Object *initEOF()
104 { initObj(objEOF); return this; }
105
106 // Copy an object.
107 Object *copy(Object *obj);
108
109 // If object is a Ref, fetch and return the referenced object.
110 // Otherwise, return a copy of the object.
111 Object *fetch(XRef *xref, Object *obj);
112
113 // Free object contents.
114 void free();
115
116 // Type checking.
117 ObjType getType() { return type; }
118 GBool isBool() { return type == objBool; }
119 GBool isInt() { return type == objInt; }
120 GBool isReal() { return type == objReal; }
121 GBool isNum() { return type == objInt || type == objReal; }
122 GBool isString() { return type == objString; }
123 GBool isName() { return type == objName; }
124 GBool isNull() { return type == objNull; }
125 GBool isArray() { return type == objArray; }
126 GBool isDict() { return type == objDict; }
127 GBool isStream() { return type == objStream; }
128 GBool isRef() { return type == objRef; }
129 GBool isCmd() { return type == objCmd; }
130 GBool isError() { return type == objError; }
131 GBool isEOF() { return type == objEOF; }
132 GBool isNone() { return type == objNone; }
133
134 // Special type checking.
135 GBool isName(char *nameA)
136 { return type == objName && !strcmp(name, nameA); }
137 GBool isDict(char *dictType);
138 GBool isStream(char *dictType);
139 GBool isCmd(char *cmdA)
140 { return type == objCmd && !strcmp(cmd, cmdA); }
141
142 // Accessors. NB: these assume object is of correct type.
143 GBool getBool() { return booln; }
144 int getInt() { return intg; }
145 fouble getReal() { return real; }
146 fouble getNum() { return type == objInt ? (fouble)intg : real; }
147 GString *getString() { return string; }
148 char *getName() { return name; }
149 Array *getArray() { return array; }
150 Dict *getDict() { return dict; }
151 Stream *getStream() { return stream; }
152 Ref getRef() { return ref; }
153 int getRefNum() { return ref.num; }
154 int getRefGen() { return ref.gen; }
155
156 // Array accessors.
157 int arrayGetLength();
158 void arrayAdd(Object *elem);
159 Object *arrayGet(int i, Object *obj);
160 Object *arrayGetNF(int i, Object *obj);
161
162 // Dict accessors.
163 int dictGetLength();
164 void dictAdd(char *key, Object *val);
165 GBool dictIs(char *dictType);
166 Object *dictLookup(char *key, Object *obj);
167 Object *dictLookupNF(char *key, Object *obj);
168 char *dictGetKey(int i);
169 Object *dictGetVal(int i, Object *obj);
170 Object *dictGetValNF(int i, Object *obj);
171
172 // Stream accessors.
173 GBool streamIs(char *dictType);
174 void streamReset();
175 void streamClose();
176 int streamGetChar();
177 int streamLookChar();
178 char *streamGetLine(char *buf, int size);
179 int streamGetPos();
180 void streamSetPos(int pos);
181 Dict *streamGetDict();
182
183 // Output.
184 char *getTypeName();
185 void print(FILE *f = stdout);
186
187 // Memory testing.
188 static void memCheck(FILE *f);
189
190private:
191
192 ObjType type; // object type
193 fouble real; // real
194 union { // value for each type:
195 GBool booln; // boolean
196 int intg; // integer
197 GString *string; // string
198 char *name; // name
199 Array *array; // array
200 Dict *dict; // dictionary
201 Stream *stream; // stream
202 Ref ref; // indirect reference
203 char *cmd; // command
204 };
205
206#ifdef DEBUG_MEM
207 static int // number of each type of object
208 numAlloc[numObjTypes];// currently allocated
209#endif
210};
211
212//------------------------------------------------------------------------
213// Array accessors.
214//------------------------------------------------------------------------
215
216#include "Array.h"
217
218inline int Object::arrayGetLength()
219 { return array->getLength(); }
220
221inline void Object::arrayAdd(Object *elem)
222 { array->add(elem); }
223
224inline Object *Object::arrayGet(int i, Object *obj)
225 { return array->get(i, obj); }
226
227inline Object *Object::arrayGetNF(int i, Object *obj)
228 { return array->getNF(i, obj); }
229
230//------------------------------------------------------------------------
231// Dict accessors.
232//------------------------------------------------------------------------
233
234#include "Dict.h"
235
236inline int Object::dictGetLength()
237 { return dict->getLength(); }
238
239inline void Object::dictAdd(char *key, Object *val)
240 { dict->add(key, val); }
241
242inline GBool Object::dictIs(char *dictType)
243 { return dict->is(dictType); }
244
245inline GBool Object::isDict(char *dictType)
246 { return type == objDict && dictIs(dictType); }
247
248inline Object *Object::dictLookup(char *key, Object *obj)
249 { return dict->lookup(key, obj); }
250
251inline Object *Object::dictLookupNF(char *key, Object *obj)
252 { return dict->lookupNF(key, obj); }
253
254inline char *Object::dictGetKey(int i)
255 { return dict->getKey(i); }
256
257inline Object *Object::dictGetVal(int i, Object *obj)
258 { return dict->getVal(i, obj); }
259
260inline Object *Object::dictGetValNF(int i, Object *obj)
261 { return dict->getValNF(i, obj); }
262
263//------------------------------------------------------------------------
264// Stream accessors.
265//------------------------------------------------------------------------
266
267#include "Stream.h"
268
269inline GBool Object::streamIs(char *dictType)
270 { return stream->getDict()->is(dictType); }
271
272inline GBool Object::isStream(char *dictType)
273 { return type == objStream && streamIs(dictType); }
274
275inline void Object::streamReset()
276 { stream->reset(); }
277
278inline void Object::streamClose()
279 { stream->close(); }
280
281inline int Object::streamGetChar()
282 { return stream->getChar(); }
283
284inline int Object::streamLookChar()
285 { return stream->lookChar(); }
286
287inline char *Object::streamGetLine(char *buf, int size)
288 { return stream->getLine(buf, size); }
289
290inline int Object::streamGetPos()
291 { return stream->getPos(); }
292
293inline void Object::streamSetPos(int pos)
294 { stream->setPos(pos); }
295
296inline Dict *Object::streamGetDict()
297 { return stream->getDict(); }
298
299#endif