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