1 // Copyright (c) 1994 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8 #include "splib.h"
9 #include "Lpd.h"
10
11 #ifdef SP_NAMESPACE
12 namespace SP_NAMESPACE {
13 #endif
14
Lpd(const StringC & name,Type type,const Location & location,const Ptr<Dtd> & sourceDtd)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)
19 {
20 }
21
~Lpd()22 Lpd::~Lpd()
23 {
24 }
25
SimpleLpd(const StringC & name,const Location & location,const Ptr<Dtd> & sourceDtd)26 SimpleLpd::SimpleLpd(const StringC &name, const Location &location,
27 const Ptr<Dtd> &sourceDtd)
28 : Lpd(name, simpleLink, location, sourceDtd)
29 {
30 }
31
ResultElementSpec()32 ResultElementSpec::ResultElementSpec()
33 : elementType(0)
34 {
35 }
36
swap(ResultElementSpec & to)37 void ResultElementSpec::swap(ResultElementSpec &to)
38 {
39 attributeList.swap(to.attributeList);
40 {
41 const ElementType *tem = to.elementType;
42 to.elementType = elementType;
43 elementType = tem;
44 }
45 }
46
SourceLinkRule()47 SourceLinkRule::SourceLinkRule()
48 : uselink_(0), postlink_(0), postlinkRestore_(0)
49 {
50 }
51
swap(SourceLinkRule & to)52 void SourceLinkRule::swap(SourceLinkRule &to)
53 {
54 linkAttributes_.swap(to.linkAttributes_);
55 resultElementSpec_.swap(to.resultElementSpec_);
56 {
57 const LinkSet *tem = to.uselink_;
58 to.uselink_ = uselink_;
59 uselink_ = tem;
60 }
61 {
62 const LinkSet *tem = to.postlink_;
63 to.postlink_ = postlink_;
64 postlink_ = tem;
65 }
66 {
67 Boolean tem = to.postlinkRestore_;
68 to.postlinkRestore_ = postlinkRestore_;
69 postlinkRestore_ = tem;
70 }
71 }
72
SourceLinkRuleResource()73 SourceLinkRuleResource::SourceLinkRuleResource()
74 {
75 }
76
LinkSet(const StringC & name,const Dtd * dtd)77 LinkSet::LinkSet(const StringC &name, const Dtd *dtd)
78 : Named(name), defined_(0), linkRules_(dtd ? dtd->nElementTypeIndex() : 0)
79 {
80 }
81
addLinkRule(const ElementType * element,const ConstPtr<SourceLinkRuleResource> & rule)82 void LinkSet::addLinkRule(const ElementType *element,
83 const ConstPtr<SourceLinkRuleResource> &rule)
84 {
85 linkRules_[element->index()].push_back(rule);
86 }
87
addImplied(const ElementType * element,AttributeList & attributes)88 void LinkSet::addImplied(const ElementType *element, AttributeList &attributes)
89 {
90 impliedSourceLinkRules_.resize(impliedSourceLinkRules_.size() + 1);
91 ResultElementSpec &result = impliedSourceLinkRules_.back();
92 result.elementType = element;
93 result.attributeList = attributes;
94 }
95
impliedResultAttributes(const ElementType * resultType,const AttributeList * & attributes)96 Boolean LinkSet::impliedResultAttributes(const ElementType *resultType,
97 const AttributeList *&attributes)
98 {
99 for (size_t i = 0; i < impliedSourceLinkRules_.size(); i++)
100 if (impliedSourceLinkRules_[i].elementType == resultType) {
101 attributes = &impliedSourceLinkRules_[i].attributeList;
102 return 1;
103 }
104 return 0;
105 }
106
nLinkRules(const ElementType * e) const107 size_t LinkSet::nLinkRules(const ElementType *e) const
108 {
109 if (e->index() >= linkRules_.size())
110 return 0;
111 return linkRules_[e->index()].size();
112 }
113
IdLinkRule()114 IdLinkRule::IdLinkRule()
115 {
116 }
117
isAssociatedWith(const ElementType * e) const118 Boolean IdLinkRule::isAssociatedWith(const ElementType *e) const
119 {
120 for (size_t i = 0; i < assocElementTypes_.size(); i++)
121 if (assocElementTypes_[i] == e)
122 return 1;
123 return 0;
124 }
125
setAssocElementTypes(Vector<const ElementType * > & v)126 void IdLinkRule::setAssocElementTypes(Vector<const ElementType *> &v)
127 {
128 v.swap(assocElementTypes_);
129 }
130
swap(IdLinkRule & to)131 void IdLinkRule::swap(IdLinkRule &to)
132 {
133 SourceLinkRule::swap(to);
134 assocElementTypes_.swap(to.assocElementTypes_);
135 }
136
IdLinkRuleGroup(const StringC & name)137 IdLinkRuleGroup::IdLinkRuleGroup(const StringC &name)
138 : Named(name)
139 {
140 }
141
addLinkRule(IdLinkRule & rule)142 void IdLinkRuleGroup::addLinkRule(IdLinkRule &rule)
143 {
144 linkRules_.resize(linkRules_.size() + 1);
145 rule.swap(linkRules_.back());
146 }
147
ComplexLpd(const StringC & name,Type type,const Location & location,const Syntax & syntax,const Ptr<Dtd> & sourceDtd,const Ptr<Dtd> & resultDtd)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())
160 {
161 }
162
lookupCreateIdLink(const StringC & id)163 IdLinkRuleGroup *ComplexLpd::lookupCreateIdLink(const StringC &id)
164 {
165 IdLinkRuleGroup *group = idLinkTable_.lookup(id);
166 if (!group) {
167 group = new IdLinkRuleGroup(id);
168 idLinkTable_.insert(group);
169 }
170 return group;
171 }
172
173
174
175 #ifdef SP_NAMESPACE
176 }
177 #endif
178