Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / GenericEventHandler.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: GenericEventHandler.h /main/1 1996/07/29 16:52:21 cde-hp $ */
24 // Copyright (c) 1995, 1996 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef GenericEventHandler_INCLUDED
28 #define GenericEventHandler_INCLUDED 1
29
30 #ifdef __GNUG__
31 #pragma interface
32 #endif
33
34 // Must include Boolean.h before SGMLApplication.h.
35
36 #include "Boolean.h"
37 #include "SGMLApplication.h"
38 #include "Event.h"
39 #include "MessageReporter.h"
40 #include "ErrorCountEventHandler.h"
41
42 #ifdef SP_NAMESPACE
43 namespace SP_NAMESPACE {
44 #endif
45
46 class SP_API GenericEventHandler : public ErrorCountEventHandler {
47 public:
48   GenericEventHandler(SGMLApplication &, bool generalEntities);
49   ~GenericEventHandler();
50   void message(MessageEvent *);
51   void appinfo(AppinfoEvent *);
52   void startDtd(StartDtdEvent *);
53   void endDtd(EndDtdEvent *);
54   void endProlog(EndPrologEvent *);
55   void entityDefaulted(EntityDefaultedEvent *);
56   void startElement(StartElementEvent *);
57   void endElement(EndElementEvent *);
58   void data(DataEvent *);
59   void pi(PiEvent *);
60   void sdataEntity(SdataEntityEvent *);
61   void externalDataEntity(ExternalDataEntityEvent *);
62   void subdocEntity(SubdocEntityEvent *);
63   void commentDecl(CommentDeclEvent *);
64   void ignoredChars(IgnoredCharsEvent *);
65   void markedSectionStart(MarkedSectionStartEvent *);
66   void markedSectionEnd(MarkedSectionEndEvent *);
67   void *allocate(size_t);
68   void freeAll();
69   void freeAll1();
70
71   struct Block {
72     Block *next;
73     char *mem;
74     size_t size;
75   };
76   static void setString(SGMLApplication::CharString &, const StringC &);
77   static void clearString(SGMLApplication::CharString &);
78   virtual void reportMessage(const Message &msg, StringC &) = 0;
79 private:
80   GenericEventHandler(const GenericEventHandler &); // undefined
81   void operator=(const GenericEventHandler &);  // undefined
82   void setLocation(SGMLApplication::Position &, const Location &);
83   void setLocation1(SGMLApplication::Position &, const Location &);
84   void setAttributes(const SGMLApplication::Attribute *&attributes,
85                      const AttributeList &attributeList);
86   void setExternalId(SGMLApplication::ExternalId &to,
87                      const ExternalId &from);
88   void setEntity(SGMLApplication::Entity &to, const Entity &from);
89   void setNotation(SGMLApplication::Notation &, const Notation &notation);
90   static void clearNotation(SGMLApplication::Notation &);
91   static void clearExternalId(SGMLApplication::ExternalId &);
92   ConstPtr<Origin> lastOrigin_;
93   SGMLApplication::OpenEntityPtr openEntityPtr_;
94   size_t firstBlockUsed_;
95   size_t firstBlockSpare_;
96   Block *freeBlocks_;
97   Block *allocBlocks_;
98   bool generalEntities_;
99   SGMLApplication *app_;
100 };
101
102 class SP_API MsgGenericEventHandler : public GenericEventHandler {
103 public:
104   MsgGenericEventHandler(SGMLApplication &, 
105                          bool generalEntities,
106                          MessageReporter &reporter,
107                          const bool *messagesInhibitedPtr);
108   void reportMessage(const Message &msg, StringC &);
109 private:
110   MsgGenericEventHandler(const MsgGenericEventHandler &); // undefined
111   void operator=(const MsgGenericEventHandler &);  // undefined
112   struct WrapReporter {
113     WrapReporter(MessageReporter *r) : reporter(r), origStream(0) {
114       origStream = reporter->releaseMessageStream();
115       reporter->setMessageStream(&strStream);
116     }
117     ~WrapReporter() {
118       if (origStream) {
119         reporter->releaseMessageStream();
120         reporter->setMessageStream(origStream);
121       }
122     }
123     MessageReporter *reporter;
124     OutputCharStream *origStream;
125     StrOutputCharStream strStream;
126   };
127   const bool *messagesInhibitedPtr_;
128   MessageReporter *reporter_;
129 };
130
131 inline void
132 GenericEventHandler::setString(SGMLApplication::CharString &to,
133                            const StringC &from)
134 {
135   to.ptr = from.data();
136   to.len = from.size();
137 }
138
139 inline
140 void GenericEventHandler::clearString(SGMLApplication::CharString &to)
141 {
142   to.len = 0;
143 }
144
145 #ifdef SP_NAMESPACE
146 }
147 #endif
148
149 #endif /* not GenericEventHandler_INCLUDED */