Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / InputSource.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: InputSource.h /main/1 1996/07/29 16:55:17 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef InputSource_INCLUDED
28 #define InputSource_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "types.h"
34 #include "Link.h"
35 #include "Ptr.h"
36 #include "Location.h"
37 #include "XcharMap.h"
38 #include <stddef.h>
39
40 #ifdef SP_NAMESPACE
41 namespace SP_NAMESPACE {
42 #endif
43
44 class Messenger;
45 class NamedCharRef;
46
47 class SP_API InputSource : public Link {
48 public:
49   enum { eE = -1 };             // end of entity signal
50
51   virtual ~InputSource();
52   Xchar get(Messenger &);
53   virtual void pushCharRef(Char ch, const NamedCharRef &) = 0;
54   const Location &currentLocation() const;
55   const Char *currentTokenStart() const;
56   size_t currentTokenLength() const;
57   const Char *currentTokenEnd() const;
58   Index nextIndex() const;
59   // Discard all but the last character of the current token.
60   void discardInitial();
61   void startToken();
62   void startTokenNoMulticode();
63   void endToken(size_t length);
64   Xchar tokenChar(Messenger &);
65   void ungetToken();
66   void setMarkupScanTable(const XcharMap<unsigned char> &);
67   Boolean scanSuppress() const;
68   void extendToBufferEnd();
69   virtual void willNotRewind();
70   virtual Boolean rewind(Messenger &) = 0;
71   Boolean accessError() const;
72 protected:
73   InputSource(InputSourceOrigin *origin, const Char *start, const Char *end);
74   void reset(const Char *start, const Char *end);
75   InputSourceOrigin *inputSourceOrigin();
76   void noteCharRef(Index replacementIndex, const NamedCharRef &);
77   const Char *cur();
78   const Char *start();
79   const Char *end();
80   Index startIndex();
81   void changeBuffer(const Char *newBase, const Char *oldBase);
82   void advanceEnd(const Char *newEnd);
83   void moveLeft();
84   void moveStart(const Char *newStart);
85   Char nextChar();
86   void setAccessError();
87 private:
88   InputSource(const InputSource &); // undefined
89   void operator=(const InputSource &); // undefined
90   virtual Xchar fill(Messenger &) = 0;
91   void advanceStart(const Char *to);
92   void advanceStartMulticode(const Char *to);
93   
94   const Char *cur_;
95   const Char *start_;
96   const Char *end_;
97   Location startLocation_;
98   Ptr<InputSourceOrigin> origin_;
99   Boolean accessError_;
100   Boolean scanSuppress_;
101   Boolean scanSuppressSingle_;
102   Index scanSuppressIndex_;
103   Boolean multicode_;
104   XcharMap<unsigned char> markupScanTable_;
105 };
106
107 inline
108 void InputSource::advanceStart(const Char *to)
109 {
110   if (multicode_)
111     advanceStartMulticode(to);
112   else {
113     startLocation_ += to - start_;
114     start_ = to;
115   }
116 }
117
118 inline
119 Xchar InputSource::get(Messenger &mgr)
120 {
121   advanceStart(cur_);
122   return cur_ < end_ ? *cur_++ : fill(mgr);
123 }
124
125 inline
126 void InputSource::startTokenNoMulticode()
127 {
128   startLocation_ += cur_ - start_;
129   start_ = cur_;
130 }
131
132 inline
133 void InputSource::startToken()
134 {
135   advanceStart(cur_);
136 }
137
138 inline
139 void InputSource::endToken(size_t length)
140 {
141   cur_ = start_ + length;
142 }
143
144 inline
145 Xchar InputSource::tokenChar(Messenger &mgr)
146 {
147   return cur_ < end_ ? *cur_++ : fill(mgr);
148 }
149
150 inline
151 void InputSource::extendToBufferEnd()
152 {
153   cur_ = end_;
154 }
155
156 inline
157 const Char *InputSource::cur()
158 {
159   return cur_;
160 }
161
162 inline
163 const Char *InputSource::start()
164 {
165   return start_;
166 }
167
168 inline
169 const Char *InputSource::end()
170 {
171   return end_;
172 }
173
174 inline
175 void InputSource::changeBuffer(const Char *newBase, const Char *oldBase)
176 {
177   cur_ = newBase + (cur_ - oldBase);
178   start_ = newBase + (start_ - oldBase);
179   end_ = newBase + (end_ - oldBase);
180 }
181
182 inline
183 void InputSource::moveStart(const Char *newStart)
184 {
185   cur_ = newStart + (cur_ - start_);
186   end_ = newStart + (end_ - start_);
187   start_ = newStart;
188 }
189
190 inline
191 void InputSource::advanceEnd(const Char *newEnd)
192 {
193   end_ = newEnd;
194 }
195
196 inline
197 Char InputSource::nextChar()
198 {
199   return *cur_++;
200 }
201
202 inline
203 Index InputSource::startIndex()
204 {
205   return startLocation_.index();
206 }
207
208 inline
209 void InputSource::moveLeft()
210 {
211   start_--;
212   cur_--;
213 }
214
215 inline
216 void InputSource::noteCharRef(Index replacementIndex, const NamedCharRef &ref)
217 {
218   origin_->noteCharRef(replacementIndex, ref);
219 }
220
221 inline
222 const Location &InputSource::currentLocation() const
223 {
224   return startLocation_;
225 }
226
227 inline
228 const Char *InputSource::currentTokenStart() const
229 {
230   return start_;
231 }
232
233 inline
234 size_t InputSource::currentTokenLength() const
235 {
236   return cur_ - start_;
237 }
238
239 inline
240 Index InputSource::nextIndex() const
241 {
242   return startLocation_.index() + (cur_ - start_);
243 }
244
245 inline
246 const Char *InputSource::currentTokenEnd() const
247 {
248   return cur_;
249 }
250
251 inline
252 void InputSource::discardInitial()
253 {
254   advanceStart(cur_ - 1);
255 }
256
257 inline
258 void InputSource::ungetToken()
259 {
260   cur_ = start_;
261 }
262
263 inline
264 void InputSource::setMarkupScanTable(const XcharMap<unsigned char> &table)
265 {
266   markupScanTable_ = table;
267   multicode_ = 1;
268 }
269
270 inline
271 Boolean InputSource::scanSuppress() const
272 {
273   return scanSuppress_ && (!scanSuppressSingle_
274                            || startLocation_.index() == scanSuppressIndex_);
275 }
276
277 inline
278 InputSourceOrigin *InputSource::inputSourceOrigin()
279 {
280   return origin_.pointer();
281 }
282
283 inline
284 void InputSource::setAccessError()
285 {
286   accessError_ = 1;
287 }
288
289 inline
290 Boolean InputSource::accessError() const
291 {
292   return accessError_;
293 }
294
295 #ifdef SP_NAMESPACE
296 }
297 #endif
298
299 #endif /* not InputSource_INCLUDED */