1 /* $XConsortium: Lpd.C /main/1 1996/07/29 16:56:26 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
12 namespace SP_NAMESPACE {
15 Lpd::Lpd(const StringC &name, Type type, const Location &location,
16 const Ptr<Dtd> &sourceDtd)
17 : name_(new StringResource<Char>(name)), type_(type), location_(location),
18 active_(0), sourceDtd_(sourceDtd)
26 SimpleLpd::SimpleLpd(const StringC &name, const Location &location,
27 const Ptr<Dtd> &sourceDtd)
28 : Lpd(name, simpleLink, location, sourceDtd)
32 ResultElementSpec::ResultElementSpec()
37 void ResultElementSpec::swap(ResultElementSpec &to)
39 attributeList.swap(to.attributeList);
41 const ElementType *tem = to.elementType;
42 to.elementType = elementType;
47 SourceLinkRule::SourceLinkRule()
48 : uselink_(0), postlink_(0), postlinkRestore_(0)
52 void SourceLinkRule::swap(SourceLinkRule &to)
54 linkAttributes_.swap(to.linkAttributes_);
55 resultElementSpec_.swap(to.resultElementSpec_);
57 const LinkSet *tem = to.uselink_;
58 to.uselink_ = uselink_;
62 const LinkSet *tem = to.postlink_;
63 to.postlink_ = postlink_;
67 Boolean tem = to.postlinkRestore_;
68 to.postlinkRestore_ = postlinkRestore_;
69 postlinkRestore_ = tem;
73 SourceLinkRuleResource::SourceLinkRuleResource()
77 LinkSet::LinkSet(const StringC &name, const Dtd *dtd)
78 : Named(name), defined_(0), linkRules_(dtd ? dtd->nElementTypeIndex() : 0)
82 void LinkSet::addLinkRule(const ElementType *element,
83 const ConstPtr<SourceLinkRuleResource> &rule)
85 linkRules_[element->index()].push_back(rule);
88 void LinkSet::addImplied(const ElementType *element, AttributeList &attributes)
90 impliedSourceLinkRules_.resize(impliedSourceLinkRules_.size() + 1);
91 ResultElementSpec &result = impliedSourceLinkRules_.back();
92 result.elementType = element;
93 result.attributeList = attributes;
96 Boolean LinkSet::impliedResultAttributes(const ElementType *resultType,
97 const AttributeList *&attributes)
99 for (size_t i = 0; i < impliedSourceLinkRules_.size(); i++)
100 if (impliedSourceLinkRules_[i].elementType == resultType) {
101 attributes = &impliedSourceLinkRules_[i].attributeList;
107 size_t LinkSet::nLinkRules(const ElementType *e) const
109 if (e->index() >= linkRules_.size())
111 return linkRules_[e->index()].size();
114 IdLinkRule::IdLinkRule()
118 Boolean IdLinkRule::isAssociatedWith(const ElementType *e) const
120 for (size_t i = 0; i < assocElementTypes_.size(); i++)
121 if (assocElementTypes_[i] == e)
126 void IdLinkRule::setAssocElementTypes(Vector<const ElementType *> &v)
128 v.swap(assocElementTypes_);
131 void IdLinkRule::swap(IdLinkRule &to)
133 SourceLinkRule::swap(to);
134 assocElementTypes_.swap(to.assocElementTypes_);
137 IdLinkRuleGroup::IdLinkRuleGroup(const StringC &name)
142 void IdLinkRuleGroup::addLinkRule(IdLinkRule &rule)
144 linkRules_.resize(linkRules_.size() + 1);
145 rule.swap(linkRules_.back());
148 ComplexLpd::ComplexLpd(const StringC &name, Type type,
149 const Location &location,
150 const Syntax &syntax,
151 const Ptr<Dtd> &sourceDtd,
152 const Ptr<Dtd> &resultDtd)
153 : Lpd(name, type, location, sourceDtd), resultDtd_(resultDtd),
154 hadIdLinkSet_(0), nAttributeDefinitionList_(0),
155 initialLinkSet_(syntax.rniReservedName(Syntax::rINITIAL),
156 sourceDtd.pointer()),
157 emptyLinkSet_(syntax.rniReservedName(Syntax::rEMPTY),
158 sourceDtd.pointer()),
159 linkAttributeDefs_(sourceDtd.isNull() ? 0 : sourceDtd->nElementTypeIndex())
163 IdLinkRuleGroup *ComplexLpd::lookupCreateIdLink(const StringC &id)
165 IdLinkRuleGroup *group = idLinkTable_.lookup(id);
167 group = new IdLinkRuleGroup(id);
168 idLinkTable_.insert(group);