2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
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.
28 #define Lpd_INCLUDED 1
33 #include "Attribute.h"
39 #include "NamedTable.h"
45 namespace SP_NAMESPACE {
50 struct SP_API ResultElementSpec {
52 const ElementType *elementType;
53 AttributeList attributeList;
54 void swap(ResultElementSpec &);
57 class SP_API Lpd : public Resource {
59 enum Type { simpleLink, implicitLink, explicitLink };
60 Lpd(const StringC &, Type, const Location &,
61 const Ptr<Dtd> &sourceDtd);
64 const Location &location() const;
65 const Ptr<Dtd> &sourceDtd();
66 ConstPtr<Dtd> sourceDtd() const;
67 Boolean active() const;
69 const ConstPtr<StringResource<Char> > &namePointer() const;
70 const StringC &name() const;
72 Lpd(const Lpd &); // undefined
73 void operator=(const Lpd &); // undefined
78 ConstPtr<StringResource<Char> > name_;
81 class SP_API SimpleLpd : public Lpd, public Attributed {
83 SimpleLpd(const StringC &, const Location &,
84 const Ptr<Dtd> &sourceDtd);
86 SimpleLpd(const SimpleLpd &); // undefined
87 void operator=(const SimpleLpd &); // undefined
92 // A link rule whose source element specification is not implied.
94 class SP_API 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;
109 const LinkSet *uselink_;
110 const LinkSet *postlink_;
111 Boolean postlinkRestore_;
112 AttributeList linkAttributes_;
113 ResultElementSpec resultElementSpec_;
116 class SP_API SourceLinkRuleResource : public Resource, public SourceLinkRule {
118 SourceLinkRuleResource();
121 class SP_API LinkSet : public Named {
123 LinkSet(const StringC &, const Dtd *);
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 *&);
136 LinkSet(const LinkSet &); // undefined
137 void operator=(const LinkSet &); // undefined
139 // indexed by typeIndex of source elements
140 Vector<Vector<ConstPtr<SourceLinkRuleResource> > >
142 Vector<ResultElementSpec> impliedSourceLinkRules_;
145 class SP_API IdLinkRule : public SourceLinkRule {
148 Boolean isAssociatedWith(const ElementType *) const;
149 void setAssocElementTypes(Vector<const ElementType *> &);
150 void swap(IdLinkRule &);
152 Vector<const ElementType *> assocElementTypes_;
155 // A collection of link rules in a ID link set that are
156 // assocated with the same name (unique identifier).
158 class SP_API IdLinkRuleGroup : public Named {
160 IdLinkRuleGroup(const StringC &);
161 size_t nLinkRules() const;
162 const IdLinkRule &linkRule(size_t) const;
163 void addLinkRule(IdLinkRule &);
165 IdLinkRuleGroup(const IdLinkRuleGroup &); // undefined
166 void operator=(const IdLinkRuleGroup &); // undefined
167 Vector<IdLinkRule> linkRules_;
170 // An implicit or explicit LPD.
172 class SP_API ComplexLpd : public Lpd {
174 typedef ConstNamedTableIter<LinkSet> ConstLinkSetIter;
175 ComplexLpd(const StringC &, Type,
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();
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> &);
202 ComplexLpd(const ComplexLpd &); // undefined
203 void operator=(const ComplexLpd &); // undefined
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_;
215 Lpd::Type Lpd::type() const
221 const Location &Lpd::location() const
227 Boolean Lpd::active() const
239 ConstPtr<Dtd> Lpd::sourceDtd() const
245 const Ptr<Dtd> &Lpd::sourceDtd()
251 const ConstPtr<StringResource<Char> > &Lpd::namePointer() const
257 const StringC &Lpd::name() const
263 void SourceLinkRule::setLinkAttributes(AttributeList &attributes)
265 attributes.swap(linkAttributes_);
269 const AttributeList &SourceLinkRule::attributes() const
271 return linkAttributes_;
275 void SourceLinkRule::setResult(const ElementType *element,
276 AttributeList &attributes)
278 resultElementSpec_.elementType = element;
279 attributes.swap(resultElementSpec_.attributeList);
283 const ResultElementSpec &SourceLinkRule::resultElementSpec() const
285 return resultElementSpec_;
289 void SourceLinkRule::setUselink(const LinkSet *linkSet)
295 void SourceLinkRule::setPostlink(const LinkSet *linkSet)
301 void SourceLinkRule::setPostlinkRestore()
303 postlinkRestore_ = 1;
307 const LinkSet *SourceLinkRule::uselink() const
313 const LinkSet *SourceLinkRule::postlink() const
319 Boolean SourceLinkRule::postlinkRestore() const
321 return postlinkRestore_;
325 Boolean LinkSet::defined() const
331 void LinkSet::setDefined()
337 const SourceLinkRule &LinkSet::linkRule(const ElementType *e, size_t i) const
339 return *linkRules_[e->index()][i];
343 size_t LinkSet::nImpliedLinkRules() const
345 return impliedSourceLinkRules_.size();
349 const ResultElementSpec &LinkSet::impliedLinkRule(size_t i) const
351 return impliedSourceLinkRules_[i];
355 const Ptr<Dtd> &ComplexLpd::resultDtd()
361 ConstPtr<Dtd> ComplexLpd::resultDtd() const
367 LinkSet *ComplexLpd::initialLinkSet()
369 return &initialLinkSet_;
373 const LinkSet *ComplexLpd::initialLinkSet() const
375 return &initialLinkSet_;
379 const LinkSet *ComplexLpd::emptyLinkSet() const
381 return &emptyLinkSet_;
385 const LinkSet *ComplexLpd::lookupLinkSet(const StringC &name) const
387 return linkSetTable_.lookup(name);
391 LinkSet *ComplexLpd::lookupLinkSet(const StringC &name)
393 return linkSetTable_.lookup(name);
397 LinkSet *ComplexLpd::insertLinkSet(LinkSet *e)
399 return linkSetTable_.insert(e);
403 size_t ComplexLpd::nAttributeDefinitionList() const
405 return nAttributeDefinitionList_;
409 size_t ComplexLpd::allocAttributeDefinitionListIndex()
411 return nAttributeDefinitionList_++;
415 ComplexLpd::ConstLinkSetIter ComplexLpd::linkSetIter() const
417 // Avoid use of typedef to work around MSVC 2.0 bug.
418 return ConstNamedTableIter<LinkSet>(linkSetTable_);
422 const ConstPtr<AttributeDefinitionList> &
423 ComplexLpd::attributeDef(const ElementType *e) const
425 return linkAttributeDefs_[e->index()];
429 void ComplexLpd::setAttributeDef(const ElementType *e,
430 const ConstPtr<AttributeDefinitionList> &attdef)
432 linkAttributeDefs_[e->index()] = attdef;
436 Boolean ComplexLpd::hadIdLinkSet() const
438 return hadIdLinkSet_;
442 void ComplexLpd::setHadIdLinkSet()
448 const IdLinkRuleGroup *ComplexLpd::lookupIdLink(const StringC &id) const
450 return idLinkTable_.lookup(id);
454 size_t IdLinkRuleGroup::nLinkRules() const
456 return linkRules_.size();
460 const IdLinkRule &IdLinkRuleGroup::linkRule(size_t i) const
462 return linkRules_[i];
469 #endif /* not Lpd_INCLUDED */