Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / OpenElement.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 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: OpenElement.h /main/1 1996/07/29 16:59:20 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef OpenElement_INCLUDED
28 #define OpenElement_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "Boolean.h"
34 #include "ContentToken.h"
35 #include "ElementType.h"
36 #include "Link.h"
37 #include "Mode.h"
38 #include "Allocator.h"
39 #include "Location.h"
40
41 #ifdef SP_NAMESPACE
42 namespace SP_NAMESPACE {
43 #endif
44
45 class SP_API OpenElement : public Link {
46 public:
47   void *operator new(size_t sz, Allocator &alloc) { return alloc.alloc(sz); }
48   void *operator new(size_t sz) { return Allocator::allocSimple(sz); }
49   void operator delete(void *p) { Allocator::free(p); }
50   OpenElement(const ElementType *, Boolean net, Boolean included,
51               const ShortReferenceMap *currentMap,
52               const Location &startLocation);
53   Boolean isFinished() const;
54   Boolean tryTransition(const ElementType *);
55   const LeafContentToken *invalidExclusion(const ElementType *) const;
56   // This doesn't handle declared content of EMPTY.
57   // If this situation can arise must use declaredEmpty().
58   Boolean tryTransitionPcdata();
59   const LeafContentToken *impliedStartTag() const;
60   void doRequiredTransition();
61   const ElementType *type() const;
62   Boolean netEnabling() const;
63   Boolean included() const;
64   const MatchState &matchState() const;
65   void setMatchState(const MatchState &);
66   Mode mode(Boolean netEnabled) const;
67   const ShortReferenceMap *map() const;
68   void setMap(const ShortReferenceMap *);
69   Boolean requiresSpecialParse() const;
70   const Location &startLocation() const;
71   const LeafContentToken *currentPosition() const;
72   Boolean declaredEmpty() const;
73   void setConref();
74 private:
75   OpenElement(const OpenElement &); // undefined
76   void operator=(const OpenElement &); // undefined
77   const ElementType *elementType_;
78   PackedBoolean netEnabling_;           // start-tag was net-enabling
79   PackedBoolean included_;
80   MatchState matchState_;
81   ElementDefinition::DeclaredContent declaredContent_;
82   const ShortReferenceMap *map_;
83   Location startLocation_;
84 };
85
86 inline
87 const ElementType *OpenElement::type() const
88 {
89   return elementType_;
90 }
91
92 inline 
93 Boolean OpenElement::netEnabling() const
94 {
95   return netEnabling_;
96 }
97
98 inline
99 Boolean OpenElement::included() const
100 {
101   return included_;
102 }
103
104 inline
105 const MatchState &OpenElement::matchState() const
106 {
107   return matchState_;
108 }
109
110 inline
111 void OpenElement::setMatchState(const MatchState &state)
112 {
113   matchState_ = state;
114 }
115
116 inline
117 Boolean OpenElement::isFinished() const
118 {
119   return (declaredContent_ != ElementDefinition::modelGroup
120           || matchState_.isFinished());
121 }
122   
123 inline
124 Boolean OpenElement::tryTransition(const ElementType *e)
125 {
126   return (declaredContent_ == ElementDefinition::modelGroup
127           ? matchState_.tryTransition(e)
128           : (declaredContent_ == ElementDefinition::any));
129 }
130
131 inline
132 Boolean OpenElement::tryTransitionPcdata()
133 {
134   return (declaredContent_ == ElementDefinition::modelGroup
135           ? matchState_.tryTransitionPcdata()
136           : 1);                 // CDATA, RCDATA, ANY all ok
137 }
138
139 inline
140 const LeafContentToken *OpenElement::invalidExclusion(const ElementType *e)
141      const
142 {
143   return (declaredContent_ == ElementDefinition::modelGroup
144           ? matchState_.invalidExclusion(e)
145           : 0);
146 }
147
148 inline
149 void OpenElement::doRequiredTransition()
150 {
151   matchState_.doRequiredTransition();
152 }
153
154 inline
155 const LeafContentToken *OpenElement::impliedStartTag() const
156 {
157   return (declaredContent_ == ElementDefinition::modelGroup
158           ? matchState_.impliedStartTag()
159           : 0);
160 }
161
162 inline
163 const ShortReferenceMap *OpenElement::map() const
164 {
165   return map_;
166 }
167
168 inline
169 void OpenElement::setMap(const ShortReferenceMap *map)
170 {
171   map_ = map;
172 }
173
174 inline
175 Boolean OpenElement::requiresSpecialParse() const
176 {
177   return (declaredContent_ == ElementDefinition::cdata
178           || declaredContent_ == ElementDefinition::rcdata);
179 }
180
181 inline
182 Mode OpenElement::mode(Boolean netEnabled) const
183 {
184   return elementType_->definition()->mode(netEnabled);
185 }
186
187 inline
188 const Location &OpenElement::startLocation() const
189 {
190   return startLocation_;
191 }
192
193 inline
194 const LeafContentToken *OpenElement::currentPosition() const
195 {
196   return (declaredContent_ == ElementDefinition::modelGroup
197           ? matchState_.currentPosition()
198           : 0);
199 }
200
201 inline
202 Boolean OpenElement::declaredEmpty() const
203 {
204   return declaredContent_ == ElementDefinition::empty;
205 }
206
207 inline
208 void OpenElement::setConref()
209 {
210   declaredContent_ = ElementDefinition::empty;
211 }
212
213 #ifdef SP_NAMESPACE
214 }
215 #endif
216
217 #endif /* not OpenElement_INCLUDED */