Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / Entity.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: Entity.h /main/1 1996/07/29 16:49:52 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Entity_INCLUDED
28 #define Entity_INCLUDED 1
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33 #include "types.h"
34 #include "StringC.h"
35 #include "NamedResource.h"
36 #include "Location.h"
37 #include "Owner.h"
38 #include "Attribute.h"
39 #include "ExternalId.h"
40 #include "Text.h"
41 #include "SubstTable.h"
42 #include "StringResource.h"
43 #include "Allocator.h"
44 #include "EntityDecl.h"
45 #include "Markup.h"
46
47 #ifdef SP_NAMESPACE
48 namespace SP_NAMESPACE {
49 #endif
50
51 class Messenger;
52 class InputSource;
53 class EntityOrigin;
54 class ParserState;
55 class ExternalEntity;
56 class ExternalDataEntity;
57 class SubdocEntity;
58 class InternalEntity;
59 class Notation;
60
61 class Entity : public EntityDecl {
62 public:
63   Entity(const StringC &name, DeclType declType, DataType dataType,
64          const Location &defLocation);
65   // reference in a literal
66   virtual void litReference(Text &, ParserState &,
67                             const Ptr<EntityOrigin> &,
68                             Boolean squeezeSpaces)
69     const;
70   // reference in a declaration
71   virtual void declReference(ParserState &,
72                              const Ptr<EntityOrigin> &)
73     const;
74   // reference in a declaration subset
75   virtual void dsReference(ParserState &,
76                            const Ptr<EntityOrigin> &)
77     const;
78   // reference in content
79   virtual void contentReference(ParserState &,
80                                 const Ptr<EntityOrigin> &)
81     const;
82   // reference in rcdata
83   virtual void rcdataReference(ParserState &,
84                                const Ptr<EntityOrigin> &)
85     const;
86   // for entity name attribute checking
87   virtual Boolean isDataOrSubdoc() const;
88   // for determining whether we need to validate as character data
89   virtual Boolean isCharacterData() const;
90   virtual const ExternalDataEntity *asExternalDataEntity() const;
91   virtual const SubdocEntity *asSubdocEntity() const;
92   virtual const InternalEntity *asInternalEntity() const;
93   virtual const ExternalEntity *asExternalEntity() const;
94   // needed for default entity
95   virtual Entity *copy() const = 0;
96   virtual void generateSystemId(ParserState &);
97   void setUsed();
98   Boolean used() const;
99   void setDefaulted();
100   Boolean defaulted() const;
101 protected:
102   static void checkEntlvl(ParserState &);
103   Boolean checkNotOpen(ParserState &) const;
104 private:
105   virtual void normalReference(ParserState &,
106                                const Ptr<EntityOrigin> &,
107                                Boolean generateEvent) const = 0;
108   PackedBoolean used_;
109   PackedBoolean defaulted_;
110 };
111
112 class InternalEntity : public Entity {
113 public:
114   InternalEntity(const StringC &, DeclType declType, DataType dataType,
115                  const Location &, Text &);
116   const StringC &string() const;
117   const Text &text() const;
118   const InternalEntity *asInternalEntity() const;
119 protected:
120   Text text_;
121 };
122
123 class PiEntity : public InternalEntity {
124 public:
125   PiEntity(const StringC &, DeclType, const Location &, Text &);
126   void litReference(Text &, ParserState &,
127                     const Ptr<EntityOrigin> &,
128                     Boolean) const;
129   void normalReference(ParserState &,
130                        const Ptr<EntityOrigin> &,
131                        Boolean) const;
132   void declReference(ParserState &,
133                      const Ptr<EntityOrigin> &) const;
134   void rcdataReference(ParserState &,
135                        const Ptr<EntityOrigin> &) const;
136   Entity *copy() const;
137 };
138
139 class InternalDataEntity : public InternalEntity {
140 public:
141   InternalDataEntity(const StringC &, DataType, const Location &, Text &);
142   void declReference(ParserState &,
143                      const Ptr<EntityOrigin> &) const;
144   Boolean isDataOrSubdoc() const;
145 };
146
147 class InternalCdataEntity : public InternalDataEntity {
148 public:
149   InternalCdataEntity(const StringC &, const Location &, Text &);
150   void normalReference(ParserState &,
151                        const Ptr<EntityOrigin> &,
152                        Boolean) const;
153   void litReference(Text &, ParserState &,
154                     const Ptr<EntityOrigin> &,
155                     Boolean) const;
156   Entity *copy() const;
157   Boolean isCharacterData() const;
158 };
159
160 class InternalSdataEntity : public InternalDataEntity {
161 public:
162   InternalSdataEntity(const StringC &, const Location &, Text &);
163   void normalReference(ParserState &,
164                        const Ptr<EntityOrigin> &,
165                        Boolean) const;
166   void litReference(Text &, ParserState &,
167                     const Ptr<EntityOrigin> &,
168                     Boolean) const;
169   Entity *copy() const;
170   Boolean isCharacterData() const;
171 };
172
173 class InternalTextEntity : public InternalEntity {
174 public:
175   enum Bracketed {
176     none,
177     starttag,
178     endtag,
179     ms,
180     md
181     };
182   InternalTextEntity(const StringC &, DeclType, const Location &, Text &,
183                      Bracketed);
184   Entity *copy() const;
185 private:
186   void normalReference(ParserState &,
187                        const Ptr<EntityOrigin> &,
188                        Boolean) const;
189   void litReference(Text &, ParserState &,
190                     const Ptr<EntityOrigin> &,
191                     Boolean) const;
192   Bracketed bracketed_;
193 };
194
195 class ExternalEntity : public Entity {
196 public:
197   ExternalEntity(const StringC &, DeclType, DataType, const Location &,
198                  const ExternalId &);
199   const ExternalId &externalId() const;
200   const ExternalEntity *asExternalEntity() const;
201   void generateSystemId(ParserState &);
202   const StringC *systemIdPointer() const;
203   const StringC *effectiveSystemIdPointer() const;
204   const StringC *publicIdPointer() const;
205 private:
206   ExternalId externalId_;
207 };
208
209 class ExternalTextEntity : public ExternalEntity {
210 public:
211   ExternalTextEntity(const StringC &, DeclType, const Location &,
212                      const ExternalId &);
213   Entity *copy() const;
214 private:
215   void normalReference(ParserState &,
216                        const Ptr<EntityOrigin> &,
217                        Boolean) const;
218   void litReference(Text &, ParserState &,
219                     const Ptr<EntityOrigin> &,
220                     Boolean) const;
221 };
222
223 class ExternalNonTextEntity : public ExternalEntity {
224 public:
225   ExternalNonTextEntity(const StringC &, DataType,
226                         const Location &, const ExternalId &);
227   Boolean isDataOrSubdoc() const;
228   void litReference(Text &, ParserState &,
229                     const Ptr<EntityOrigin> &,
230                     Boolean) const;
231   void rcdataReference(ParserState &,
232                        const Ptr<EntityOrigin> &) const;
233   void normalReference(ParserState &,
234                        const Ptr<EntityOrigin> &,
235                        Boolean) const;
236   Boolean isCharacterData() const;
237 };
238
239 class ExternalDataEntity : public ExternalNonTextEntity {
240 public:
241   ExternalDataEntity(const StringC &, DataType, const Location &,
242                      const ExternalId &, const ConstPtr<Notation> &,
243                      AttributeList &);
244   const AttributeList &attributes() const;
245   const Notation *notation() const;
246   const ExternalDataEntity *asExternalDataEntity() const;
247   Entity *copy() const;
248   void contentReference(ParserState &,
249                         const Ptr<EntityOrigin> &) const;
250   void setNotation(const ConstPtr<Notation>  &, AttributeList &);
251 private:
252   ConstPtr<Notation> notation_;
253   AttributeList attributes_;
254 };
255
256 class SubdocEntity : public ExternalNonTextEntity {
257 public:
258   SubdocEntity(const StringC &, const Location &, const ExternalId &);
259   const SubdocEntity *asSubdocEntity() const;
260   Entity *copy() const;
261   void contentReference(ParserState &,
262                         const Ptr<EntityOrigin> &) const;
263 private:
264 };
265
266 class IgnoredEntity : public Entity {
267 public:
268   IgnoredEntity(const StringC &, DeclType declType);
269   Entity *copy() const;
270   void litReference(Text &, ParserState &,
271                     const Ptr<EntityOrigin> &,
272                     Boolean squeezeSpaces) const;
273   void declReference(ParserState &,
274                      const Ptr<EntityOrigin> &) const;
275 private:
276   void normalReference(ParserState &,
277                        const Ptr<EntityOrigin> &,
278                        Boolean generateEvent) const;
279 };
280
281 class SP_API EntityOrigin : public InputSourceOrigin {
282 public:
283   void *operator new(size_t sz, Allocator &alloc) {
284     return alloc.alloc(sz);
285   }
286   void *operator new(size_t sz) {
287     return Allocator::allocSimple(sz);
288   }
289   void operator delete(void *p) {
290     Allocator::free(p);
291   }
292   EntityOrigin();
293   EntityOrigin(const Location &refLocation);
294   EntityOrigin(const ConstPtr<Entity> &);
295   EntityOrigin(const ConstPtr<Entity> &,
296                const Location &refLocation);
297   EntityOrigin(const ConstPtr<Entity> &,
298                const Location &refLocation, Index refLength,
299                Owner<Markup> &markup);
300   ~EntityOrigin();
301   InputSourceOrigin *copy() const;
302   const ConstPtr<Entity> &entity() const { return entity_; }
303   const StringC *entityName() const;
304   const EntityDecl *entityDecl() const;
305   const EntityOrigin *asEntityOrigin() const;
306   Boolean defLocation(Offset off, Location &loc) const;
307   Index refLength() const;
308   const Markup *markup() const;
309 private:
310   EntityOrigin(const EntityOrigin &); // undefined
311   void operator=(const EntityOrigin &); // undefined
312   ConstPtr<Entity> entity_;     // 0 for document entity
313   // total length of reference
314   // (characters that were replaced by the entity)
315   Index refLength_;
316   Owner<Markup> markup_;
317 };
318
319 inline
320 Boolean Entity::used() const
321 {
322   return used_;
323 }
324
325 inline
326 void Entity::setUsed()
327 {
328   used_ = 1;
329 }
330
331 inline
332 Boolean Entity::defaulted() const
333 {
334   return defaulted_;
335 }
336
337 inline
338 void Entity::setDefaulted()
339 {
340   defaulted_ = 1;
341 }
342
343 inline
344 const StringC &InternalEntity::string() const
345 {
346   return text_.string();
347 }
348
349 inline
350 const Text &InternalEntity::text() const
351 {
352   return text_;
353 }
354
355 inline
356 const ExternalId &ExternalEntity::externalId() const
357 {
358   return externalId_;
359 }
360
361 inline
362 const AttributeList &ExternalDataEntity::attributes() const
363 {
364   return attributes_;
365 }
366
367 inline
368 const Notation *ExternalDataEntity::notation() const
369 {
370   return notation_.pointer();
371 }
372
373 inline
374 const Markup *EntityOrigin::markup() const
375 {
376   return markup_.pointer();
377 }
378
379 #ifdef SP_NAMESPACE
380 }
381 #endif
382
383 #endif /* not Entity_INCLUDED */