1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
4
5 #ifndef Dtd_INCLUDED
6 #define Dtd_INCLUDED 1
7 #ifdef __GNUG__
8 #pragma interface
9 #endif
10
11 #include "NamedTable.h"
12 #include "NamedResourceTable.h"
13 #include "ElementType.h"
14 #include "Notation.h"
15 #include "Entity.h"
16 #include "ShortReferenceMap.h"
17 #include "Resource.h"
18 #include "StringC.h"
19 #include "StringResource.h"
20 #include "Boolean.h"
21 #include "Vector.h"
22 #include "HashTable.h"
23
24 #ifdef SP_NAMESPACE
25 namespace SP_NAMESPACE {
26 #endif
27
28 class Syntax;
29 class ParserState;
30
31 class SP_API Dtd : public Resource {
32 public:
33 typedef NamedTableIter<ElementType> ElementTypeIter;
34 typedef ConstNamedTableIter<ElementType> ConstElementTypeIter;
35 typedef NamedTableIter<ShortReferenceMap> ShortReferenceMapIter;
36 typedef ConstNamedResourceTableIter<Notation> ConstNotationIter;
37 typedef NamedResourceTableIter<Notation> NotationIter;
38 typedef ConstNamedResourceTableIter<Entity> ConstEntityIter;
39 typedef NamedResourceTableIter<Entity> EntityIter;
40 Dtd(const StringC &name, Boolean isBase);
41 ConstPtr<Entity> lookupEntity(Boolean isParameter, const StringC &) const;
42 const Entity *lookupEntityTemp(Boolean isParameter, const StringC &) const;
43 Ptr<Entity> lookupEntity(Boolean isParameter, const StringC &);
44 Ptr<Entity> insertEntity(const Ptr<Entity> &, Boolean replace = 0);
45 Ptr<Entity> removeEntity(Boolean isParameter, const StringC &);
46 ConstEntityIter generalEntityIter() const;
47 EntityIter generalEntityIter();
48 ConstEntityIter parameterEntityIter() const;
49 EntityIter parameterEntityIter();
50
51 ConstPtr<Entity> defaultEntity() const;
52 const Entity *defaultEntityTemp() const;
53 void setDefaultEntity(const Ptr<Entity> &, ParserState &);
54 const ConstPtr<StringResource<Char> > &namePointer() const;
55 const StringC &name() const;
56
57 const ElementType *lookupElementType(const StringC &) const;
58 ElementType *lookupElementType(const StringC &);
59 ElementType *removeElementType(const StringC &);
60 ElementType *insertElementType(ElementType *);
61 ElementType *insertUndefinedElementType(ElementType *);
62 size_t nElementTypeIndex() const;
63 size_t allocElementTypeIndex();
64 ConstElementTypeIter elementTypeIter() const;
65 ElementTypeIter elementTypeIter();
66
67 const RankStem *lookupRankStem(const StringC &) const;
68 RankStem *lookupRankStem(const StringC &);
69 RankStem *insertRankStem(RankStem *);
70 size_t nRankStem() const;
71
72 const ShortReferenceMap *lookupShortReferenceMap(const StringC &) const;
73 ShortReferenceMap *lookupShortReferenceMap(const StringC &);
74 ShortReferenceMap *insertShortReferenceMap(ShortReferenceMap *);
75 ShortReferenceMapIter shortReferenceMapIter();
76
77 Boolean shortrefIndex(const StringC &, const Syntax &, size_t &index);
78 size_t nShortref() const;
79 const StringC &shortref(size_t i) const;
80 void addNeededShortref(const StringC &);
81
82 ConstPtr<Notation> lookupNotation(const StringC &) const;
83 const Notation *lookupNotationTemp(const StringC &) const;
84 Ptr<Notation> lookupNotation(const StringC &);
85 Ptr<Notation> insertNotation(const Ptr<Notation> &);
86 Ptr<Notation> removeNotation(const StringC &);
87 ConstNotationIter notationIter() const;
88 NotationIter notationIter();
89
90 size_t allocCurrentAttributeIndex();
91 size_t nCurrentAttribute() const;
92 size_t allocElementDefinitionIndex();
93 size_t nElementDefinition() const;
94 size_t allocAttributeDefinitionListIndex();
95 size_t nAttributeDefinitionList() const;
96 const ElementType *documentElementType() const;
97 Boolean isBase() const;
98
99 Ptr<AttributeDefinitionList> &implicitElementAttributeDef();
100 void setImplicitElementAttributeDef(const Ptr<AttributeDefinitionList> &);
101 Ptr<AttributeDefinitionList> &implicitNotationAttributeDef();
102 void setImplicitNotationAttributeDef(const Ptr<AttributeDefinitionList> &);
103 private:
104 Dtd(const Dtd &); // undefined
105 void operator=(const Dtd &); // undefined
106 NamedResourceTable<Entity> generalEntityTable_;
107 NamedResourceTable<Entity> parameterEntityTable_;
108 ConstPtr<Entity> defaultEntity_;
109 ConstPtr<StringResource<Char> > name_;
110 NamedTable<ElementType> elementTypeTable_;
111 NamedTable<ElementType> undefinedElementTypeTable_;
112 NamedTable<RankStem> rankStemTable_;
113 NamedTable<ShortReferenceMap> shortReferenceMapTable_;
114 NamedResourceTable<Notation> notationTable_;
115 size_t nCurrentAttribute_;
116 size_t nElementDefinition_;
117 size_t nAttributeDefinitionList_;
118 size_t nElementType_;
119 ElementType *documentElementType_;
120 Vector<StringC> shortrefs_;
121 HashTable<StringC,int> shortrefTable_;
122 Boolean isBase_;
123 Ptr<AttributeDefinitionList> implicitElementAttributeDef_;
124 Ptr<AttributeDefinitionList> implicitNotationAttributeDef_;
125 };
126
127 inline
lookupEntity(Boolean isParameter,const StringC & name)128 ConstPtr<Entity> Dtd::lookupEntity(Boolean isParameter, const StringC &name)
129 const
130 {
131 return (isParameter
132 ? ¶meterEntityTable_
133 : &generalEntityTable_)->lookupConst(name);
134 }
135
136 inline
lookupEntityTemp(Boolean isParameter,const StringC & name)137 const Entity *Dtd::lookupEntityTemp(Boolean isParameter, const StringC &name)
138 const
139 {
140 return (isParameter
141 ? ¶meterEntityTable_
142 : &generalEntityTable_)->lookupTemp(name);
143 }
144
145 inline
lookupEntity(Boolean isParameter,const StringC & name)146 Ptr<Entity> Dtd::lookupEntity(Boolean isParameter, const StringC &name)
147 {
148 return (isParameter
149 ? ¶meterEntityTable_
150 : &generalEntityTable_)->lookup(name);
151 }
152
153 inline
154 Ptr<Entity>
insertEntity(const Ptr<Entity> & entity,Boolean replace)155 Dtd::insertEntity(const Ptr<Entity> &entity, Boolean replace)
156 {
157 return (entity->declType() == Entity::parameterEntity
158 ? ¶meterEntityTable_
159 : &generalEntityTable_)->insert(entity, replace);
160 }
161
162 inline
removeEntity(Boolean isParameter,const StringC & name)163 Ptr<Entity> Dtd::removeEntity(Boolean isParameter, const StringC &name)
164 {
165 return (isParameter
166 ? ¶meterEntityTable_
167 : &generalEntityTable_)->remove(name);
168 }
169
170 inline
generalEntityIter()171 Dtd::ConstEntityIter Dtd::generalEntityIter() const
172 {
173 // Avoid use of typedef to work around MSVC 2.0 bug.
174 return ConstNamedResourceTableIter<Entity>(generalEntityTable_);
175 }
176
177 inline
generalEntityIter()178 Dtd::EntityIter Dtd::generalEntityIter()
179 {
180 // Avoid use of typedef to work around MSVC 2.0 bug.
181 return NamedResourceTableIter<Entity>(generalEntityTable_);
182 }
183
184 inline
parameterEntityIter()185 Dtd::ConstEntityIter Dtd::parameterEntityIter() const
186 {
187 // Avoid use of typedef to work around MSVC 2.0 bug.
188 return ConstNamedResourceTableIter<Entity>(parameterEntityTable_);
189 }
190
191 inline
parameterEntityIter()192 Dtd::EntityIter Dtd::parameterEntityIter()
193 {
194 // Avoid use of typedef to work around MSVC 2.0 bug.
195 return NamedResourceTableIter<Entity>(parameterEntityTable_);
196 }
197
198 inline
defaultEntity()199 ConstPtr<Entity> Dtd::defaultEntity() const
200 {
201 return defaultEntity_;
202 }
203
204 inline
defaultEntityTemp()205 const Entity *Dtd::defaultEntityTemp() const
206 {
207 return defaultEntity_.pointer();
208 }
209
210 inline
namePointer()211 const ConstPtr<StringResource<Char> > &Dtd::namePointer() const
212 {
213 return name_;
214 }
215
216 inline
name()217 const StringC &Dtd::name() const
218 {
219 return *name_;
220 }
221
222 inline
allocCurrentAttributeIndex()223 size_t Dtd::allocCurrentAttributeIndex()
224 {
225 return nCurrentAttribute_++;
226 }
227
228 inline
nCurrentAttribute()229 size_t Dtd::nCurrentAttribute() const
230 {
231 return nCurrentAttribute_;
232 }
233
234 inline
allocElementDefinitionIndex()235 size_t Dtd::allocElementDefinitionIndex()
236 {
237 return nElementDefinition_++;
238 }
239
240 inline
nElementDefinition()241 size_t Dtd::nElementDefinition() const
242 {
243 return nElementDefinition_;
244 }
245
246 inline
allocAttributeDefinitionListIndex()247 size_t Dtd::allocAttributeDefinitionListIndex()
248 {
249 return nAttributeDefinitionList_++;
250 }
251
252 inline
nAttributeDefinitionList()253 size_t Dtd::nAttributeDefinitionList() const
254 {
255 return nAttributeDefinitionList_;
256 }
257
258 inline
lookupElementType(const StringC & name)259 const ElementType *Dtd::lookupElementType(const StringC &name) const
260 {
261 const ElementType *e = elementTypeTable_.lookup(name);
262 if (e)
263 return e;
264 else
265 return undefinedElementTypeTable_.lookup(name);
266 }
267
268 inline
lookupElementType(const StringC & name)269 ElementType *Dtd::lookupElementType(const StringC &name)
270 {
271 ElementType *e = elementTypeTable_.lookup(name);
272 if (e)
273 return e;
274 else
275 return undefinedElementTypeTable_.lookup(name);
276 }
277
278 inline
insertElementType(ElementType * e)279 ElementType *Dtd::insertElementType(ElementType *e)
280 {
281 return elementTypeTable_.insert(e);
282 }
283
284 inline
insertUndefinedElementType(ElementType * e)285 ElementType *Dtd::insertUndefinedElementType(ElementType *e)
286 {
287 return undefinedElementTypeTable_.insert(e);
288 }
289
290 inline
elementTypeIter()291 Dtd::ElementTypeIter Dtd::elementTypeIter()
292 {
293 // Avoid use of typedef to work around MSVC 2.0 bug.
294 return NamedTableIter<ElementType>(elementTypeTable_);
295 }
296
297 inline
elementTypeIter()298 Dtd::ConstElementTypeIter Dtd::elementTypeIter() const
299 {
300 // Avoid use of typedef to work around MSVC 2.0 bug.
301 return ConstNamedTableIter<ElementType>(elementTypeTable_);
302 }
303
304 inline
removeElementType(const StringC & name)305 ElementType *Dtd::removeElementType(const StringC &name)
306 {
307 return elementTypeTable_.remove(name);
308 }
309
310 inline
nElementTypeIndex()311 size_t Dtd::nElementTypeIndex() const
312 {
313 // index 0 is reserved for #pcdata
314 return 1 + nElementType_;
315 }
316
317 inline
allocElementTypeIndex()318 size_t Dtd::allocElementTypeIndex()
319 {
320 return 1 + nElementType_++;
321 }
322
323 inline
lookupRankStem(const StringC & name)324 const RankStem *Dtd::lookupRankStem(const StringC &name) const
325 {
326 return rankStemTable_.lookup(name);
327 }
328
329 inline
lookupRankStem(const StringC & name)330 RankStem *Dtd::lookupRankStem(const StringC &name)
331 {
332 return rankStemTable_.lookup(name);
333 }
334
335 inline
insertRankStem(RankStem * e)336 RankStem *Dtd::insertRankStem(RankStem *e)
337 {
338 return rankStemTable_.insert(e);
339 }
340
341 inline
nRankStem()342 size_t Dtd::nRankStem() const
343 {
344 return rankStemTable_.count();
345 }
346
347 inline
lookupNotation(const StringC & name)348 ConstPtr<Notation> Dtd::lookupNotation(const StringC &name) const
349 {
350 return notationTable_.lookupConst(name);
351 }
352
353 inline
lookupNotationTemp(const StringC & name)354 const Notation *Dtd::lookupNotationTemp(const StringC &name) const
355 {
356 return notationTable_.lookupTemp(name);
357 }
358
359 inline
lookupNotation(const StringC & name)360 Ptr<Notation> Dtd::lookupNotation(const StringC &name)
361 {
362 return notationTable_.lookup(name);
363 }
364
365 inline
insertNotation(const Ptr<Notation> & nt)366 Ptr<Notation> Dtd::insertNotation(const Ptr<Notation> &nt)
367 {
368 return notationTable_.insert(nt);
369 }
370
371 inline
notationIter()372 Dtd::ConstNotationIter Dtd::notationIter() const
373 {
374 // Avoid use of typedef to work around MSVC 2.0 bug.
375 return ConstNamedResourceTableIter<Notation>(notationTable_);
376 }
377
378 inline
notationIter()379 Dtd::NotationIter Dtd::notationIter()
380 {
381 // Avoid use of typedef to work around MSVC 2.0 bug.
382 return NamedResourceTableIter<Notation>(notationTable_);
383 }
384
385 inline
removeNotation(const StringC & name)386 Ptr<Notation> Dtd::removeNotation(const StringC &name)
387 {
388 return notationTable_.remove(name);
389 }
390
391 inline
documentElementType()392 const ElementType *Dtd::documentElementType() const
393 {
394 return documentElementType_;
395 }
396
397 inline
lookupShortReferenceMap(const StringC & name)398 const ShortReferenceMap *Dtd::lookupShortReferenceMap(const StringC &name) const
399 {
400 return shortReferenceMapTable_.lookup(name);
401 }
402
403 inline
lookupShortReferenceMap(const StringC & name)404 ShortReferenceMap *Dtd::lookupShortReferenceMap(const StringC &name)
405 {
406 return shortReferenceMapTable_.lookup(name);
407 }
408
409 inline
insertShortReferenceMap(ShortReferenceMap * map)410 ShortReferenceMap *Dtd::insertShortReferenceMap(ShortReferenceMap *map)
411 {
412 return shortReferenceMapTable_.insert(map);
413 }
414
415 inline
shortReferenceMapIter()416 Dtd::ShortReferenceMapIter Dtd::shortReferenceMapIter()
417 {
418 // Avoid use of typedef to work around MSVC 2.0 bug.
419 return NamedTableIter<ShortReferenceMap>(shortReferenceMapTable_);
420 }
421
422 inline
isBase()423 Boolean Dtd::isBase() const
424 {
425 return isBase_;
426 }
427
428 inline
nShortref()429 size_t Dtd::nShortref() const
430 {
431 return shortrefs_.size();
432 }
433
434 inline
shortref(size_t i)435 const StringC &Dtd::shortref(size_t i) const
436 {
437 return shortrefs_[i];
438 }
439
440 inline
implicitElementAttributeDef()441 Ptr<AttributeDefinitionList> &Dtd::implicitElementAttributeDef()
442 {
443 return implicitElementAttributeDef_;
444 }
445
446 inline
setImplicitElementAttributeDef(const Ptr<AttributeDefinitionList> & def)447 void Dtd::setImplicitElementAttributeDef(const Ptr<AttributeDefinitionList> &def)
448 {
449 implicitElementAttributeDef_ = def;
450 }
451
452 inline
implicitNotationAttributeDef()453 Ptr<AttributeDefinitionList> &Dtd::implicitNotationAttributeDef()
454 {
455 return implicitNotationAttributeDef_;
456 }
457
458 inline
setImplicitNotationAttributeDef(const Ptr<AttributeDefinitionList> & def)459 void Dtd::setImplicitNotationAttributeDef(const Ptr<AttributeDefinitionList> &def)
460 {
461 implicitNotationAttributeDef_ = def;
462 }
463
464 #ifdef SP_NAMESPACE
465 }
466 #endif
467
468 #endif /* not Dtd_INCLUDED */
469