nsgml: Resolve symbol collision when building with SunStudio 12.1
[oweals/cde.git] / cde / programs / nsgmls / Lpd.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Lpd.h /main/1 1996/07/29 16:56:30 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Lpd_INCLUDED
28 #define Lpd_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "Attribute.h"
34 #include "StringC.h"
35 #include "Ptr.h"
36 #include "Resource.h"
37 #include "Boolean.h"
38 #include "Named.h"
39 #include "NamedTable.h"
40 #include "Syntax.h"
41 #include "Location.h"
42 #include "Dtd.h"
43
44 #ifdef SP_NAMESPACE
45 namespace SP_NAMESPACE {
46 #endif
47
48 class ElementType;
49
50 struct SP_API ResultElementSpec {
51   ResultElementSpec();
52   const ElementType *elementType;
53   AttributeList attributeList;
54   void swap(ResultElementSpec &);
55 };
56
57 class SP_API Lpd : public Resource {
58 public:
59   enum Type { simpleLink, implicitLink, explicitLink };
60   Lpd(const StringC &, Type, const Location &,
61       const Ptr<Dtd> &sourceDtd);
62   virtual ~Lpd();
63   Type type() const;
64   const Location &location() const;
65   const Ptr<Dtd> &sourceDtd();
66   ConstPtr<Dtd> sourceDtd() const;
67   Boolean active() const;
68   void activate();
69   const ConstPtr<StringResource<Char> > &namePointer() const;
70   const StringC &name() const;
71 private:
72   Lpd(const Lpd &);             // undefined
73   void operator=(const Lpd &);  // undefined
74   Type type_;
75   Location location_;
76   Boolean active_;
77   Ptr<Dtd> sourceDtd_;
78   ConstPtr<StringResource<Char> > name_;
79 };
80
81 class SP_API SimpleLpd : public Lpd, public Attributed {
82 public:
83   SimpleLpd(const StringC &, const Location &,
84             const Ptr<Dtd> &sourceDtd);
85 private:
86   SimpleLpd(const SimpleLpd &); // undefined
87   void operator=(const SimpleLpd &); // undefined
88 };
89
90 class LinkSet;
91
92 // A link rule whose source element specification is not implied.
93
94 class SP_API SourceLinkRule {
95 public:
96   SourceLinkRule();
97   void setLinkAttributes(AttributeList &);
98   void setResult(const ElementType *, AttributeList &);
99   void setUselink(const LinkSet *);
100   void setPostlink(const LinkSet *);
101   void setPostlinkRestore();
102   void swap(SourceLinkRule &);
103   const AttributeList &attributes() const;
104   const ResultElementSpec &resultElementSpec() const;
105   const LinkSet *uselink() const;
106   const LinkSet *postlink() const;
107   Boolean postlinkRestore() const;
108 private:
109   const LinkSet *uselink_;
110   const LinkSet *postlink_;
111   Boolean postlinkRestore_;
112   AttributeList linkAttributes_;
113   ResultElementSpec resultElementSpec_;
114 };
115
116 class SP_API SourceLinkRuleResource : public Resource, public SourceLinkRule {
117 public:
118   SourceLinkRuleResource();
119 };
120
121 class SP_API LinkSet : public Named {
122 public:
123   LinkSet(const StringC &, const Dtd *);
124   void setDefined();
125   Boolean defined() const;
126   void addImplied(const ElementType *, AttributeList &);
127   size_t nLinkRules(const ElementType *) const;
128   const SourceLinkRule &linkRule(const ElementType *, size_t) const;
129   void addLinkRule(const ElementType *,
130                    const ConstPtr<SourceLinkRuleResource> &);
131   size_t nImpliedLinkRules() const;
132   const ResultElementSpec &impliedLinkRule(size_t) const;
133   Boolean impliedResultAttributes(const ElementType *,
134                                   const AttributeList *&);
135 private:
136   LinkSet(const LinkSet &);     // undefined
137   void operator=(const LinkSet &); // undefined
138   Boolean defined_;
139   // indexed by typeIndex of source elements
140   Vector<Vector<ConstPtr<SourceLinkRuleResource> > > 
141     linkRules_;
142   Vector<ResultElementSpec> impliedSourceLinkRules_;
143 };
144
145 class SP_API IdLinkRule : public SourceLinkRule {
146 public:
147   IdLinkRule();
148   Boolean isAssociatedWith(const ElementType *) const;
149   void setAssocElementTypes(Vector<const ElementType *> &);
150   void swap(IdLinkRule &);
151 private:
152   Vector<const ElementType *> assocElementTypes_;
153 };
154
155 // A collection of link rules in a ID link set that are
156 // assocated with the same name (unique identifier).
157
158 class SP_API IdLinkRuleGroup : public Named {
159 public:
160   IdLinkRuleGroup(const StringC &);
161   size_t nLinkRules() const;
162   const IdLinkRule &linkRule(size_t) const;
163   void addLinkRule(IdLinkRule &);
164 private:
165   IdLinkRuleGroup(const IdLinkRuleGroup &); // undefined
166   void operator=(const IdLinkRuleGroup &);  // undefined
167   Vector<IdLinkRule> linkRules_;
168 };
169
170 // An implicit or explicit LPD.
171
172 class SP_API ComplexLpd : public Lpd {
173 public:
174   typedef ConstNamedTableIter<LinkSet> ConstLinkSetIter;
175   ComplexLpd(const StringC &, Type,
176              const Location &,
177              const Syntax &syntax,
178              const Ptr<Dtd> &sourceDtd,
179              const Ptr<Dtd> &resultDtd);
180   size_t allocAttributeDefinitionListIndex();
181   size_t nAttributeDefinitionList() const;
182   LinkSet *initialLinkSet();
183   const LinkSet *initialLinkSet() const;
184   const LinkSet *emptyLinkSet() const;
185   const LinkSet *lookupLinkSet(const StringC &) const;
186   const IdLinkRuleGroup *lookupIdLink(const StringC &) const;
187   IdLinkRuleGroup *lookupCreateIdLink(const StringC &);
188   void insertIdLink(IdLinkRuleGroup *);
189   ConstLinkSetIter linkSetIter() const;
190   Boolean hadIdLinkSet() const;
191   void setHadIdLinkSet();
192
193   LinkSet *lookupLinkSet(const StringC &);
194   LinkSet *insertLinkSet(LinkSet *);
195   const Ptr<Dtd> &resultDtd();
196   ConstPtr<Dtd> resultDtd() const;
197   const ConstPtr<AttributeDefinitionList> &
198     attributeDef(const ElementType *) const;
199   void setAttributeDef(const ElementType *,
200                        const ConstPtr<AttributeDefinitionList> &);
201 private:
202   ComplexLpd(const ComplexLpd &); // undefined
203   void operator=(const ComplexLpd &); // undefined
204   Ptr<Dtd> resultDtd_;
205   Vector<ConstPtr<AttributeDefinitionList> > linkAttributeDefs_;
206   NamedTable<LinkSet> linkSetTable_;
207   LinkSet initialLinkSet_;
208   LinkSet emptyLinkSet_;
209   Boolean hadIdLinkSet_;
210   NamedTable<IdLinkRuleGroup> idLinkTable_;
211   size_t nAttributeDefinitionList_;
212 };
213
214 inline
215 Lpd::Type Lpd::type() const
216 {
217   return type_;
218 }
219
220 inline
221 const Location &Lpd::location() const
222 {
223   return location_;
224 }
225
226 inline
227 Boolean Lpd::active() const
228 {
229   return active_;
230 }
231
232 inline
233 void Lpd::activate()
234 {
235   active_ = 1;
236 }
237
238 inline
239 ConstPtr<Dtd> Lpd::sourceDtd() const
240 {
241   return sourceDtd_;
242 }
243
244 inline
245 const Ptr<Dtd> &Lpd::sourceDtd()
246 {
247   return sourceDtd_;
248 }
249
250 inline
251 const ConstPtr<StringResource<Char> > &Lpd::namePointer() const
252 {
253   return name_;
254 }
255
256 inline
257 const StringC &Lpd::name() const
258 {
259   return *name_;
260 }
261
262 inline
263 void SourceLinkRule::setLinkAttributes(AttributeList &attributes)
264 {
265   attributes.swap(linkAttributes_);
266 }
267
268 inline
269 const AttributeList &SourceLinkRule::attributes() const
270 {
271   return linkAttributes_;
272 }
273
274 inline
275 void SourceLinkRule::setResult(const ElementType *element,
276                                AttributeList &attributes)
277 {
278   resultElementSpec_.elementType = element;
279   attributes.swap(resultElementSpec_.attributeList);
280 }
281
282 inline
283 const ResultElementSpec &SourceLinkRule::resultElementSpec() const
284 {
285   return resultElementSpec_;
286 }
287
288 inline
289 void SourceLinkRule::setUselink(const LinkSet *linkSet)
290 {
291   uselink_ = linkSet;
292 }
293
294 inline
295 void SourceLinkRule::setPostlink(const LinkSet *linkSet)
296 {
297   postlink_ = linkSet;
298 }
299
300 inline
301 void SourceLinkRule::setPostlinkRestore()
302 {
303   postlinkRestore_ = 1;
304 }
305
306 inline
307 const LinkSet *SourceLinkRule::uselink() const
308 {
309   return uselink_;
310 }
311
312 inline
313 const LinkSet *SourceLinkRule::postlink() const
314 {
315   return postlink_;
316 }
317
318 inline
319 Boolean SourceLinkRule::postlinkRestore() const
320 {
321   return postlinkRestore_;
322 }
323
324 inline
325 Boolean LinkSet::defined() const
326 {
327   return defined_;
328 }
329
330 inline
331 void LinkSet::setDefined()
332 {
333   defined_ = 1;
334 }
335
336 inline
337 const SourceLinkRule &LinkSet::linkRule(const ElementType *e, size_t i) const
338 {
339   return *linkRules_[e->index()][i];
340 }
341
342 inline
343 size_t LinkSet::nImpliedLinkRules() const
344 {
345   return impliedSourceLinkRules_.size();
346 }
347
348 inline
349 const ResultElementSpec &LinkSet::impliedLinkRule(size_t i) const
350 {
351   return impliedSourceLinkRules_[i];
352 }
353
354 inline
355 const Ptr<Dtd> &ComplexLpd::resultDtd()
356 {
357   return resultDtd_;
358 }
359
360 inline
361 ConstPtr<Dtd> ComplexLpd::resultDtd() const
362 {
363   return resultDtd_;
364 }
365
366 inline
367 LinkSet *ComplexLpd::initialLinkSet()
368 {
369   return &initialLinkSet_;
370 }
371
372 inline
373 const LinkSet *ComplexLpd::initialLinkSet() const
374 {
375   return &initialLinkSet_;
376 }
377
378 inline
379 const LinkSet *ComplexLpd::emptyLinkSet() const
380 {
381   return &emptyLinkSet_;
382 }
383
384 inline
385 const LinkSet *ComplexLpd::lookupLinkSet(const StringC &name) const
386 {
387   return linkSetTable_.lookup(name);
388 }
389
390 inline
391 LinkSet *ComplexLpd::lookupLinkSet(const StringC &name)
392 {
393   return linkSetTable_.lookup(name);
394 }
395
396 inline
397 LinkSet *ComplexLpd::insertLinkSet(LinkSet *e)
398 {
399   return linkSetTable_.insert(e);
400 }
401
402 inline
403 size_t ComplexLpd::nAttributeDefinitionList() const
404 {
405   return nAttributeDefinitionList_;
406 }
407
408 inline
409 size_t ComplexLpd::allocAttributeDefinitionListIndex()
410 {
411   return nAttributeDefinitionList_++;
412 }
413
414 inline
415 ComplexLpd::ConstLinkSetIter ComplexLpd::linkSetIter() const
416 {
417   // Avoid use of typedef to work around MSVC 2.0 bug.
418   return ConstNamedTableIter<LinkSet>(linkSetTable_);
419 }
420
421 inline
422 const ConstPtr<AttributeDefinitionList> &
423 ComplexLpd::attributeDef(const ElementType *e) const
424 {
425   return linkAttributeDefs_[e->index()];
426 }
427
428 inline
429 void ComplexLpd::setAttributeDef(const ElementType *e,
430                                  const ConstPtr<AttributeDefinitionList> &attdef)
431 {
432   linkAttributeDefs_[e->index()] = attdef;
433 }
434
435 inline
436 Boolean ComplexLpd::hadIdLinkSet() const
437 {
438   return hadIdLinkSet_;
439 }
440
441 inline
442 void ComplexLpd::setHadIdLinkSet()
443 {
444   hadIdLinkSet_ = 1;
445 }
446
447 inline
448 const IdLinkRuleGroup *ComplexLpd::lookupIdLink(const StringC &id) const
449 {
450   return idLinkTable_.lookup(id);
451 }
452
453 inline
454 size_t IdLinkRuleGroup::nLinkRules() const
455 {
456   return linkRules_.size();
457 }
458
459 inline
460 const IdLinkRule &IdLinkRuleGroup::linkRule(size_t i) const
461 {
462   return linkRules_[i];
463 }
464
465 #ifdef SP_NAMESPACE
466 }
467 #endif
468
469 #endif /* not Lpd_INCLUDED */