1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
11 namespace SP_NAMESPACE {
14 Lpd::Lpd(const StringC &name, Type type, const Location &location,
15 const Ptr<Dtd> &sourceDtd)
16 : name_(new StringResource<Char>(name)), type_(type), location_(location),
17 active_(0), sourceDtd_(sourceDtd)
25 SimpleLpd::SimpleLpd(const StringC &name, const Location &location,
26 const Ptr<Dtd> &sourceDtd)
27 : Lpd(name, simpleLink, location, sourceDtd)
31 ResultElementSpec::ResultElementSpec()
36 void ResultElementSpec::swap(ResultElementSpec &to)
38 attributeList.swap(to.attributeList);
40 const ElementType *tem = to.elementType;
41 to.elementType = elementType;
46 SourceLinkRule::SourceLinkRule()
47 : uselink_(0), postlink_(0), postlinkRestore_(0)
51 void SourceLinkRule::swap(SourceLinkRule &to)
53 linkAttributes_.swap(to.linkAttributes_);
54 resultElementSpec_.swap(to.resultElementSpec_);
56 const LinkSet *tem = to.uselink_;
57 to.uselink_ = uselink_;
61 const LinkSet *tem = to.postlink_;
62 to.postlink_ = postlink_;
66 Boolean tem = to.postlinkRestore_;
67 to.postlinkRestore_ = postlinkRestore_;
68 postlinkRestore_ = tem;
72 SourceLinkRuleResource::SourceLinkRuleResource()
76 LinkSet::LinkSet(const StringC &name, const Dtd *dtd)
77 : Named(name), defined_(0), linkRules_(dtd ? dtd->nElementTypeIndex() : 0)
81 LinkSet::~LinkSet() {}
83 void LinkSet::addLinkRule(const ElementType *element,
84 const ConstPtr<SourceLinkRuleResource> &rule)
86 linkRules_[element->index()].push_back(rule);
89 void LinkSet::addImplied(const ElementType *element, AttributeList &attributes)
91 impliedSourceLinkRules_.resize(impliedSourceLinkRules_.size() + 1);
92 ResultElementSpec &result = impliedSourceLinkRules_.back();
93 result.elementType = element;
94 result.attributeList = attributes;
97 Boolean LinkSet::impliedResultAttributes(const ElementType *resultType,
98 const AttributeList *&attributes)
100 for (size_t i = 0; i < impliedSourceLinkRules_.size(); i++)
101 if (impliedSourceLinkRules_[i].elementType == resultType) {
102 attributes = &impliedSourceLinkRules_[i].attributeList;
108 size_t LinkSet::nLinkRules(const ElementType *e) const
110 if (e->index() >= linkRules_.size())
112 return linkRules_[e->index()].size();
115 IdLinkRule::IdLinkRule()
119 Boolean IdLinkRule::isAssociatedWith(const ElementType *e) const
121 for (size_t i = 0; i < assocElementTypes_.size(); i++)
122 if (assocElementTypes_[i] == e)
127 void IdLinkRule::setAssocElementTypes(Vector<const ElementType *> &v)
129 v.swap(assocElementTypes_);
132 void IdLinkRule::swap(IdLinkRule &to)
134 SourceLinkRule::swap(to);
135 assocElementTypes_.swap(to.assocElementTypes_);
138 IdLinkRuleGroup::IdLinkRuleGroup(const StringC &name)
143 void IdLinkRuleGroup::addLinkRule(IdLinkRule &rule)
145 linkRules_.resize(linkRules_.size() + 1);
146 rule.swap(linkRules_.back());
149 ComplexLpd::ComplexLpd(const StringC &name, Type type,
150 const Location &location,
151 const Syntax &syntax,
152 const Ptr<Dtd> &sourceDtd,
153 const Ptr<Dtd> &resultDtd)
154 : Lpd(name, type, location, sourceDtd), resultDtd_(resultDtd),
155 hadIdLinkSet_(0), nAttributeDefinitionList_(0),
156 initialLinkSet_(syntax.rniReservedName(Syntax::rINITIAL),
157 sourceDtd.pointer()),
158 emptyLinkSet_(syntax.rniReservedName(Syntax::rEMPTY),
159 sourceDtd.pointer()),
160 linkAttributeDefs_(sourceDtd.isNull() ? 0 : sourceDtd->nElementTypeIndex())
164 ComplexLpd::~ComplexLpd() {}
166 IdLinkRuleGroup *ComplexLpd::lookupCreateIdLink(const StringC &id)
168 IdLinkRuleGroup *group = idLinkTable_.lookup(id);
170 group = new IdLinkRuleGroup(id);
171 idLinkTable_.insert(group);