71#define initObj(t) zeroUnion(); ++numAlloc[type = t]
73#define initObj(t) zeroUnion(); type = t
79 void zeroUnion() { this->name = NULL; }
82 type(objNone) { zeroUnion(); }
85 Object *initBool(GBool boolnA)
86 { initObj(objBool); booln = boolnA;
return this; }
87 Object *initInt(
int intgA)
88 { initObj(objInt); intg = intgA;
return this; }
89 Object *initReal(
double realA)
90 { initObj(objReal); real = realA;
return this; }
91 Object *initString(GString *stringA)
92 { initObj(objString);
string = stringA;
return this; }
93 Object *initName(
const char *nameA)
94 { initObj(objName); name = copyString(nameA);
return this; }
96 { initObj(objNull);
return this; }
97 Object *initArray(XRef *xref);
98 Object *initDict(XRef *xref);
99 Object *initStream(Stream *streamA);
100 Object *initRef(
int numA,
int genA)
101 { initObj(objRef); ref.num = numA; ref.gen = genA;
return this; }
102 Object *initCmd(
const char *cmdA)
103 { initObj(objCmd); cmd = copyString(cmdA);
return this; }
105 { initObj(objError);
return this; }
107 { initObj(objEOF);
return this; }
110 Object *copy(Object *obj);
114 Object *fetch(XRef *xref, Object *obj);
120 ObjType getType() {
return type; }
121 GBool isBool() {
return type == objBool; }
122 GBool isInt() {
return type == objInt; }
123 GBool isReal() {
return type == objReal; }
124 GBool isNum() {
return type == objInt || type == objReal; }
125 GBool isString() {
return type == objString; }
126 GBool isName() {
return type == objName; }
127 GBool isNull() {
return type == objNull; }
128 GBool isArray() {
return type == objArray; }
129 GBool isDict() {
return type == objDict; }
130 GBool isStream() {
return type == objStream; }
131 GBool isRef() {
return type == objRef; }
132 GBool isCmd() {
return type == objCmd; }
133 GBool isError() {
return type == objError; }
134 GBool isEOF() {
return type == objEOF; }
135 GBool isNone() {
return type == objNone; }
138 GBool isName(
const char *nameA)
139 {
return type == objName && !strcmp(name, nameA); }
140 GBool isDict(
const char *dictType);
141 GBool isStream(
const char *dictType);
142 GBool isCmd(
const char *cmdA)
143 {
return type == objCmd && !strcmp(cmd, cmdA); }
146 GBool getBool() {
return booln; }
147 int getInt() {
return intg; }
148 double getReal() {
return real; }
149 double getNum() {
return type == objInt ? (double)intg : real; }
150 GString *getString() {
return string; }
151 char *getName() {
return name; }
152 Array *getArray() {
return array; }
153 Dict *getDict() {
return dict; }
154 Stream *getStream() {
return stream; }
155 Ref getRef() {
return ref; }
156 int getRefNum() {
return ref.num; }
157 int getRefGen() {
return ref.gen; }
158 const char *getCmd() {
return cmd; }
161 int arrayGetLength();
162 void arrayAdd(Object *elem);
163 Object *arrayGet(
int i, Object *obj);
164 Object *arrayGetNF(
int i, Object *obj);
168 void dictAdd(
char *key, Object *val);
169 GBool dictIs(
const char *dictType);
170 Object *dictLookup(
const char *key, Object *obj);
171 Object *dictLookupNF(
const char *key, Object *obj);
172 char *dictGetKey(
int i);
173 Object *dictGetVal(
int i, Object *obj);
174 Object *dictGetValNF(
int i, Object *obj);
177 GBool streamIs(
const char *dictType);
181 int streamLookChar();
182 char *streamGetLine(
char *buf,
int size);
183 Guint streamGetPos();
184 void streamSetPos(Guint pos,
int dir = 0);
185 Dict *streamGetDict();
188 const char *getTypeName();
189 void print(FILE *f = stdout);
192 static void memCheck(FILE *f);
212 numAlloc[numObjTypes];
222inline int Object::arrayGetLength()
223 {
if (type != objArray)
return 0;
return array->getLength(); }
225inline void Object::arrayAdd(Object *elem)
226 {
if (type == objArray) array->add(elem); }
228inline Object *Object::arrayGet(
int i, Object *obj)
229 {
if (type != objArray)
return obj->initNull();
return array->get(i, obj); }
231inline Object *Object::arrayGetNF(
int i, Object *obj)
232 {
if (type != objArray)
return obj->initNull();
return array->getNF(i, obj); }
240inline int Object::dictGetLength()
241 {
if (type != objDict)
return 0;
return dict->getLength(); }
243inline void Object::dictAdd(
char *key, Object *val)
244 {
if (type == objDict) dict->add(key, val); }
246inline GBool Object::dictIs(
const char *dictType)
247 {
return (type == objDict) && dict->is(dictType); }
249inline GBool Object::isDict(
const char *dictType)
250 {
return (type == objDict) && dictIs(dictType); }
252inline Object *Object::dictLookup(
const char *key, Object *obj)
253 {
if (type != objDict)
return obj->initNull();
return dict->lookup(key, obj); }
255inline Object *Object::dictLookupNF(
const char *key, Object *obj)
256 {
if (type != objDict)
return obj->initNull();
return dict->lookupNF(key, obj); }
258inline char *Object::dictGetKey(
int i)
259 {
if (type != objDict)
return NULL;
return dict->getKey(i); }
261inline Object *Object::dictGetVal(
int i, Object *obj)
262 {
if (type != objDict)
return obj->initNull();
return dict->getVal(i, obj); }
264inline Object *Object::dictGetValNF(
int i, Object *obj)
265 {
if (type != objDict)
return obj->initNull();
return dict->getValNF(i, obj); }
273inline GBool Object::streamIs(
const char *dictType)
274 {
return (type == objStream) && stream->getDict()->is(dictType); }
276inline GBool Object::isStream(
const char *dictType)
277 {
return (type == objStream) && streamIs(dictType); }
279inline void Object::streamReset()
280 {
if (type == objStream) stream->reset(); }
282inline void Object::streamClose()
283 {
if (type == objStream) stream->close(); }
285inline int Object::streamGetChar()
286 {
if (type != objStream)
return EOF;
return stream->getChar(); }
288inline int Object::streamLookChar()
289 {
if (type != objStream)
return EOF;
return stream->lookChar(); }
291inline char *Object::streamGetLine(
char *buf,
int size)
292 {
if (type != objStream)
return NULL;
return stream->getLine(buf, size); }
294inline Guint Object::streamGetPos()
295 {
if (type != objStream)
return 0;
return stream->getPos(); }
297inline void Object::streamSetPos(Guint pos,
int dir)
298 {
if (type == objStream) stream->setPos(pos, dir); }
300inline Dict *Object::streamGetDict()
301 {
if (type != objStream)
return NULL;
return stream->getDict(); }