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: LinkProcess.C /main/1 1996/07/29 16:55:45 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
31 #include "LinkProcess.h"
32 // ParserState is used for access to parser messages
33 #include "ParserState.h"
34 #include "MessageArg.h"
35 #include "ParserMessages.h"
38 namespace SP_NAMESPACE {
41 LinkProcess::LinkProcess()
45 void LinkProcess::init(const ConstPtr<ComplexLpd> &lpd)
49 open_.insert(new LinkProcessOpenElement(lpd_->initialLinkSet()));
52 Boolean LinkProcess::startElement(const ElementType *element,
53 const AttributeList &attributes,
54 const Location &location,
56 const AttributeList *&linkAttributes,
57 const ResultElementSpec *&resultElementSpec)
61 resultElementSpec = 0;
64 const StringC *id = attributes.getId();
66 const IdLinkRuleGroup *p = lpd_->lookupIdLink(*id);
69 if (p->nLinkRules() > 1) {
70 linkAttributes_.resize(p->nLinkRules());
71 for (size_t i = 0; i < linkAttributes_.size(); i++)
72 linkAttributes_[i] = &p->linkRule(i).attributes();
73 if (!selectLinkRule(linkAttributes_,
80 const IdLinkRule &rule = p->linkRule(selected);
81 open_.insert(new LinkProcessOpenElement(open_.head()->current,
83 linkAttributes = &rule.attributes();
84 resultElementSpec = &rule.resultElementSpec();
85 if (!rule.isAssociatedWith(element)) {
86 mgr.setNextLocation(location);
87 mgr.message(ParserMessages::idlinkElementType,
88 StringMessageArg(element->name()),
89 StringMessageArg(*id));
94 const LinkSet *currentLinkSet = open_.head()->current;
95 size_t nRules = currentLinkSet->nLinkRules(element);
99 linkAttributes_.resize(nRules);
100 for (size_t i = 0; i < nRules; i++)
102 = ¤tLinkSet->linkRule(element, i).attributes();
103 if (!selectLinkRule(linkAttributes_,
110 const SourceLinkRule &rule = currentLinkSet->linkRule(element, selected);
111 open_.insert(new LinkProcessOpenElement(open_.head()->current,
113 linkAttributes = &rule.attributes();
114 resultElementSpec = &rule.resultElementSpec();
117 // FIXME construct attributes from attribute definition list
119 resultElementSpec = 0;
120 open_.insert(new LinkProcessOpenElement(open_.head()->current));
125 void LinkProcess::endElement()
129 LinkProcessOpenElement *top = open_.get();
131 open_.head()->current = top->post;
132 else if (top->postRestore)
133 open_.head()->current = open_.head()->restore;
137 void LinkProcess::uselink(const LinkSet *linkSet,
143 if (lpd != lpd_.pointer())
146 open_.head()->current = open_.head()->restore;
148 open_.head()->current = linkSet;
151 size_t LinkProcess::nImpliedLinkRules() const
155 return open_.head()->current->nImpliedLinkRules();
158 const ResultElementSpec &LinkProcess::impliedLinkRule(size_t i) const
160 return open_.head()->current->impliedLinkRule(i);
163 // Usually redefined by application.
165 Boolean LinkProcess::selectLinkRule(const Vector<const AttributeList *> &,
173 void LinkProcess::clear()
177 linkAttributes_.clear();
180 void LinkProcess::swap(LinkProcess &to)
182 open_.swap(to.open_);
184 linkAttributes_.swap(to.linkAttributes_);
187 LinkProcessOpenElement::LinkProcessOpenElement(const LinkSet *cur,
188 const SourceLinkRule &rule)
190 current = rule.uselink();
194 post = rule.postlink();
195 postRestore = rule.postlinkRestore();
198 LinkProcessOpenElement::LinkProcessOpenElement(const LinkSet *cur)
200 restore = current = cur;