Merge branch 'master' of https://git.code.sf.net/p/cdesktopenv/code
[oweals/cde.git] / cde / programs / nsgmls / Message.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: Message.h /main/1 1996/07/29 16:56:58 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef Message_INCLUDED
28 #define Message_INCLUDED 1
29
30 #ifdef __GNUG__
31 #pragma interface
32 #endif
33
34 #include <stddef.h>
35 #include "Location.h"
36 #include "Vector.h"
37 #include "CopyOwner.h"
38 #include "Boolean.h"
39 #include "StringC.h"
40 #include "MessageArg.h"
41
42 #ifdef SP_NAMESPACE
43 namespace SP_NAMESPACE {
44 #endif
45
46 class SP_API MessageFragment {
47 public:
48   enum {
49     libModule = 0,
50     appModule = 1
51     };
52   MessageFragment(unsigned module, unsigned number, const char *text = 0);
53   unsigned module() const;
54   unsigned number() const;
55   const char *text() const;
56 private:
57   unsigned short number_;
58   unsigned char module_;
59 protected:
60   unsigned char spare_;
61 private:
62 #ifndef SP_NO_MESSAGE_TEXT
63   const char *text_;
64 #endif
65 };
66
67 class SP_API MessageType : public MessageFragment {
68 public:
69   enum Severity {
70     info,
71     warning,
72     quantityError,
73     idrefError,
74     error
75     };
76   MessageType(Severity, unsigned module, unsigned number,
77               const char *text = 0, const char *auxText = 0);
78   Severity severity() const;
79   MessageFragment auxFragment() const;
80   Boolean isError() const;
81 private:
82 #ifndef SP_NO_MESSAGE_TEXT
83   const char *auxText_;
84 #endif
85 };
86
87
88 class SP_API MessageType0 : public MessageType {
89 public:
90   MessageType0(Severity, unsigned module, unsigned number, const char *text = 0);
91 };
92
93 class SP_API MessageType1 : public MessageType {
94 public:
95   MessageType1(Severity, unsigned module, unsigned number, const char *text = 0);
96 };
97
98 class SP_API MessageType2 : public MessageType {
99 public:
100   MessageType2(Severity, unsigned module, unsigned number, const char *text = 0);
101 };
102
103 class SP_API MessageType3 : public MessageType {
104 public:
105   MessageType3(Severity, unsigned module, unsigned number, const char *text = 0);
106 };
107
108 class SP_API MessageType4 : public MessageType {
109 public:
110   MessageType4(Severity, unsigned module, unsigned number, const char *text = 0);
111 };
112
113 class SP_API MessageType5 : public MessageType {
114 public:
115   MessageType5(Severity, unsigned module, unsigned number, const char *text = 0);
116 };
117
118 class SP_API MessageType6 : public MessageType {
119 public:
120   MessageType6(Severity, unsigned module, unsigned number, const char *text = 0);
121 };
122
123 class SP_API MessageType0L : public MessageType {
124 public:
125   MessageType0L(Severity, unsigned module, unsigned number, const char *text = 0,
126                 const char *auxText = 0);
127 };
128
129 class SP_API MessageType1L : public MessageType {
130 public:
131   MessageType1L(Severity, unsigned module, unsigned number, const char *text = 0,
132                 const char *auxText = 0);
133 };
134
135 class SP_API OpenElementInfo {
136 public:
137   OpenElementInfo();
138   PackedBoolean included;
139   StringC gi;
140   StringC matchType;
141   unsigned matchIndex;
142 };
143
144 class SP_API Message {
145 public:
146   Message();
147   Message(int nArgs);
148   const MessageType *type;
149   Location loc;
150   Location auxLoc;
151   Vector<CopyOwner<MessageArg> > args;
152   Vector<OpenElementInfo> openElementInfo;
153   void swap(Message &);
154   Boolean isError() const;
155 };
156
157 class SP_API Messenger {
158 public:
159   Messenger();
160   virtual ~Messenger();
161   void message(const MessageType0 &);
162   void message(const MessageType1 &, const MessageArg &);
163   void message(const MessageType2 &,
164                const MessageArg &,
165                const MessageArg &);
166   void message(const MessageType3 &,
167                const MessageArg &,
168                const MessageArg &,
169                const MessageArg &);
170   void message(const MessageType4 &,
171                const MessageArg &,
172                const MessageArg &,
173                const MessageArg &,
174                const MessageArg &);
175   void message(const MessageType5 &,
176                const MessageArg &,
177                const MessageArg &,
178                const MessageArg &,
179                const MessageArg &,
180                const MessageArg &);
181   void message(const MessageType6 &,
182                const MessageArg &,
183                const MessageArg &,
184                const MessageArg &,
185                const MessageArg &,
186                const MessageArg &,
187                const MessageArg &);
188   void message(const MessageType0L &, const Location &);
189   void message(const MessageType1L &, const MessageArg &, const Location &);
190   void setNextLocation(const Location &);
191   virtual void initMessage(Message &);
192   virtual void dispatchMessage(const Message &) = 0;
193   virtual void dispatchMessage(Message &);
194 private:
195   void doInitMessage(Message &);
196   Boolean haveNextLocation_;
197   Location nextLocation_;
198 };
199
200 class SP_API ForwardingMessenger : public Messenger {
201 public:
202   ForwardingMessenger(Messenger &);
203   void dispatchMessage(const Message &);
204   void dispatchMessage(Message &);
205   void initMessage(Message &);
206 private:
207   Messenger *to_;
208 };
209
210 class SP_API ParentLocationMessenger : public ForwardingMessenger {
211 public:
212   ParentLocationMessenger(Messenger &);
213   void initMessage(Message &);
214 };
215
216 class SP_API NullMessenger : public Messenger {
217 public:
218   NullMessenger();
219   void dispatchMessage(const Message &);
220   void dispatchMessage(Message &);
221 };
222
223 inline
224 unsigned MessageFragment::module() const
225 {
226   return module_;
227 }
228
229 inline
230 unsigned MessageFragment::number() const
231 {
232   return number_;
233 }
234
235 inline
236 const char *MessageFragment::text() const
237 {
238 #ifdef SP_NO_MESSAGE_TEXT
239   return 0;
240 #else
241   return text_;
242 #endif
243 }
244
245 inline
246 MessageType::Severity MessageType::severity() const
247 {
248   return Severity(spare_);
249 }
250
251 inline
252 MessageFragment MessageType::auxFragment() const
253 {
254   return MessageFragment(module(),
255                          number() + 1,
256 #ifdef SP_NO_MESSAGE_TEXT
257                          0
258 #else
259                          auxText_
260 #endif
261                          );
262 }
263
264 inline
265 Boolean MessageType::isError() const
266 {
267   return severity() != info && severity() != warning;
268 }
269
270 inline
271 Boolean Message::isError() const
272 {
273   return type->isError();
274 }
275
276 #ifdef SP_NAMESPACE
277 }
278 #endif
279
280 #endif /* not Message_INCLUDED */