b9e192896ea0a7b46fa42a68ae8cc5dbaf7a6888
[oweals/cde.git] / cde / programs / nsgmls / ElementType.h
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 libraries 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: ElementType.h /main/1 1996/07/29 16:49:41 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef ElementType_INCLUDED
28 #define ElementType_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include <stddef.h>
34 #include "Boolean.h"
35 #include "Vector.h"
36 #include "Owner.h"
37 #include "Location.h"
38 #include "Ptr.h"
39 #include "Named.h"
40 #include "Vector.h"
41 #include "Attributed.h"
42 #include "Mode.h"
43 #include "ContentToken.h"
44
45 #ifdef SP_NAMESPACE
46 namespace SP_NAMESPACE {
47 #endif
48
49 class ElementType;
50 class ShortReferenceMap;
51 class RankStem;
52
53 class SP_API ElementDefinition : public Resource {
54 public:
55   enum DeclaredContent { modelGroup, any, cdata, rcdata, empty };
56   enum OmitFlags { omitStart = 01, omitEnd = 02, omitSpec = 04 };
57   enum { undefinedIndex = -1 };
58   ElementDefinition(const Location &location,
59                     size_t index,
60                     unsigned char omitFlags,
61                     DeclaredContent declaredContent);
62   ElementDefinition(const Location &location,
63                     size_t index,
64                     unsigned char omitFlags,
65                     DeclaredContent declaredContent,
66                     Owner<CompiledModelGroup> &modelGroup);
67   const CompiledModelGroup *compiledModelGroup() const;
68   DeclaredContent declaredContent() const;
69   // Was the omitted tag minimization specified?
70   Boolean omittedTagSpec() const;
71   Boolean canOmitStartTag() const;
72   Boolean canOmitEndTag() const;
73   size_t nRankStems() const;
74   const RankStem *rankStem(size_t i) const;
75   const StringC &rankSuffix() const;
76   size_t nInclusions() const;
77   const ElementType *inclusion(size_t) const;
78   size_t nExclusions() const;
79   const ElementType *exclusion(size_t) const;
80   Boolean undefined() const;
81   void setInclusions(Vector<const ElementType *> &inclusions);
82   void setExclusions(Vector<const ElementType *> &exclusions);
83   void setRank(StringC &suffix, Vector<const RankStem *> &rankStems);
84   Mode mode(Boolean netEnabled) const;
85 private:
86   ElementDefinition(const ElementDefinition &); // undefined
87   void operator=(const ElementDefinition &);    // undefined
88   void computeMode();
89
90   Location location_;
91   size_t index_;
92   unsigned char omitFlags_;
93   DeclaredContent declaredContent_;
94   Owner<CompiledModelGroup> modelGroup_;
95   Vector<const ElementType *> inclusions_;
96   Vector<const ElementType *> exclusions_;
97   // rankStems_ contains all the rank stems in the ranked group in this
98   // definition.
99   Vector<const RankStem *> rankStems_;
100   StringC rankSuffix_;
101   Mode mode_;
102   Mode netMode_;
103 };
104
105 class SP_API RankStem : public Named {
106 public:
107   RankStem(const StringC &, size_t);
108   size_t index() const;
109   void addDefinition(const ConstPtr<ElementDefinition> &);
110   size_t nDefinitions() const;
111   const ElementDefinition *definition(size_t) const;
112 private:
113   RankStem(const RankStem &);   // undefined
114   void operator=(const RankStem &); // undefined
115   size_t index_;
116   Vector<ConstPtr<ElementDefinition> > def_;
117 };
118
119 class SP_API ElementType : public Named, public Attributed {
120 public:
121   ElementType(const StringC &, size_t);
122   void setElementDefinition(const ConstPtr<ElementDefinition> &,
123                             size_t defIndex);
124   void setMap(const ShortReferenceMap *);
125   void setRankStem(RankStem *);
126   Boolean undefined() const;
127   const ElementDefinition *definition() const;
128   Boolean isRankedElement() const;
129   const RankStem *rankedElementRankStem() const;
130   size_t index() const;
131   const ShortReferenceMap *map() const;
132   void swap(ElementType &);
133 private:
134   ElementType(const ElementType &); // undefined
135   void operator=(const ElementType &); // undefined
136   size_t index_;
137   size_t defIndex_;             // index in the group having same definition
138   ConstPtr<ElementDefinition> def_;
139   const ShortReferenceMap *map_;
140 };
141
142 inline
143 const CompiledModelGroup *ElementDefinition::compiledModelGroup() const
144 {
145   return modelGroup_.pointer();
146 }
147
148 inline
149 ElementDefinition::DeclaredContent ElementDefinition::declaredContent() const
150 {
151   return declaredContent_;
152 }
153
154 inline
155 Boolean ElementDefinition::canOmitStartTag() const
156 {
157   return (omitFlags_ & omitStart) != 0;
158 }
159
160 inline
161 Boolean ElementDefinition::canOmitEndTag() const
162 {
163   return (omitFlags_ & omitEnd) != 0;
164 }
165
166 inline
167 Boolean ElementDefinition::omittedTagSpec() const
168 {
169   return (omitFlags_ & omitSpec) != 0;
170 }
171
172 inline
173 size_t ElementDefinition::nRankStems() const
174 {
175   return rankStems_.size();
176 }
177
178 inline
179 const StringC &ElementDefinition::rankSuffix() const
180 {
181   return rankSuffix_;
182 }
183
184 inline
185 const RankStem *ElementDefinition::rankStem(size_t i) const
186 {
187   return rankStems_[i];
188 }
189
190 inline
191 const ElementType *ElementDefinition::inclusion(size_t i) const
192 {
193   return inclusions_[i];
194 }
195
196 inline
197 size_t ElementDefinition::nInclusions() const
198 {
199   return inclusions_.size();
200 }
201
202 inline
203 const ElementType *ElementDefinition::exclusion(size_t i) const
204 {
205   return exclusions_[i];
206 }
207
208 inline
209 size_t ElementDefinition::nExclusions() const
210 {
211   return exclusions_.size();
212 }
213
214 inline
215 Boolean ElementDefinition::undefined() const
216 {
217   return index_ == size_t(undefinedIndex);
218 }
219
220 inline
221 void ElementDefinition::setInclusions(Vector<const ElementType *> &inclusions)
222 {
223   inclusions.swap(inclusions_);
224 }
225
226 inline
227 void ElementDefinition::setExclusions(Vector<const ElementType *> &exclusions)
228 {
229   exclusions.swap(exclusions_);
230 }
231
232 inline
233 void ElementDefinition::setRank(StringC &rankSuffix,
234                                 Vector<const RankStem *> &rankStems)
235 {
236   rankStems.swap(rankStems_);
237   rankSuffix.swap(rankSuffix_);
238 }
239
240 inline
241 Boolean ElementType::undefined() const
242 {
243   return def_->undefined();
244 }
245
246 inline
247 Boolean ElementType::isRankedElement() const
248 {
249   return def_->nRankStems() > 0;
250 }
251
252 inline
253 const ElementDefinition *ElementType::definition() const
254 {
255   return def_.pointer();
256 }
257
258 inline
259 void ElementType::setElementDefinition(const ConstPtr<ElementDefinition> &def,
260                                        size_t defIndex)
261 {
262   def_ = def;
263   defIndex_ = defIndex;
264 }
265
266 inline
267 size_t ElementType::index() const
268 {
269   return index_;
270 }
271
272 inline
273 const RankStem *ElementType::rankedElementRankStem() const
274 {
275   return def_->rankStem(defIndex_);
276 }
277
278 inline
279 void ElementType::setMap(const ShortReferenceMap *map)
280 {
281   map_ = map;
282 }
283
284 inline
285 const ShortReferenceMap *ElementType::map() const
286 {
287   return map_;
288 }
289
290 inline 
291 size_t RankStem::index() const
292 {
293   return index_;
294 }
295
296 inline
297 size_t RankStem::nDefinitions() const
298 {
299   return def_.size();
300 }
301
302 inline
303 const ElementDefinition *RankStem::definition(size_t i) const
304 {
305   return def_[i].pointer();
306 }
307
308 inline
309 Mode ElementDefinition::mode(Boolean netEnabled) const
310 {
311   return netEnabled ? netMode_ : mode_;
312 }
313
314 #ifdef SP_NAMESPACE
315 }
316 #endif
317
318 #endif /* not ElementType_INCLUDED */