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