Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / nsgmls / Message.C
1 /* $XConsortium: Message.C /main/1 1996/07/29 16:56:53 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
9 #include "splib.h"
10 #include "Message.h"
11 #include "MessageArg.h"
12
13 #ifdef SP_NAMESPACE
14 namespace SP_NAMESPACE {
15 #endif
16
17 MessageFragment::MessageFragment(unsigned module, unsigned number, const char *
18 #ifndef SP_NO_MESSAGE_TEXT
19                                  text
20 #endif
21                                  )
22 : module_(module),
23 #ifndef SP_NO_MESSAGE_TEXT
24   text_(text),
25 #endif
26   number_(number)
27 {
28 }
29
30 MessageType::MessageType(Severity severity, unsigned module, unsigned number,
31                          const char *text, const char *
32 #ifndef SP_NO_MESSAGE_TEXT
33                          auxText
34 #endif
35                          )
36
37 #ifndef SP_NO_MESSAGE_TEXT
38   auxText_(auxText),
39 #endif
40   MessageFragment(module, number, text)
41 {
42   spare_ = severity;
43 }
44      
45 MessageType0::MessageType0(Severity severity, unsigned module, unsigned number,
46                            const char *text)
47 : MessageType(severity, module, number, text)
48 {
49 }
50
51 MessageType1::MessageType1(Severity severity, unsigned module, unsigned number,
52                            const char *text)
53 : MessageType(severity, module, number, text)
54 {
55 }
56
57 MessageType2::MessageType2(Severity severity, unsigned module, unsigned number,
58                            const char *text)
59 : MessageType(severity, module, number, text)
60 {
61 }
62
63 MessageType3::MessageType3(Severity severity, unsigned module, unsigned number,
64                            const char *text)
65 : MessageType(severity, module, number, text)
66 {
67 }
68
69 MessageType4::MessageType4(Severity severity, unsigned module, unsigned number,
70                            const char *text)
71 : MessageType(severity, module, number, text)
72 {
73 }
74
75 MessageType5::MessageType5(Severity severity, unsigned module, unsigned number,
76                            const char *text)
77 : MessageType(severity, module, number, text)
78 {
79 }
80
81 MessageType6::MessageType6(Severity severity, unsigned module, unsigned number,
82                            const char *text)
83 : MessageType(severity, module, number, text)
84 {
85 }
86
87 MessageType0L::MessageType0L(Severity severity, unsigned module, unsigned number,
88                              const char *text, const char *auxText)
89 : MessageType(severity, module, number, text, auxText)
90 {
91 }
92
93 MessageType1L::MessageType1L(Severity severity, unsigned module, unsigned number,
94                              const char *text, const char *auxText)
95 : MessageType(severity, module, number, text, auxText)
96 {
97 }
98
99 OpenElementInfo::OpenElementInfo()
100 : included(0), matchIndex(0)
101 {
102 }
103
104 Message::Message()
105 {
106 }
107
108 Message::Message(int nArgs)
109 : args(nArgs)
110 {
111 }
112
113 void Message::swap(Message &to)
114 {
115   const MessageType *tem = type;
116   type = to.type;
117   to.type = tem;
118   to.loc.swap(loc);
119   to.auxLoc.swap(auxLoc);
120   args.swap(to.args);
121   openElementInfo.swap(to.openElementInfo);
122 }
123
124 Messenger::Messenger()
125 : haveNextLocation_(0)
126 {
127 }
128
129 Messenger::~Messenger()
130 {
131 }
132
133 void Messenger::dispatchMessage(Message &msg)
134 {
135   const Message &tem = msg;
136   dispatchMessage(tem);
137 }
138
139 void Messenger::message(const MessageType0 &type)
140 {
141   Message msg(0);
142   doInitMessage(msg);
143   msg.type = &type;
144   dispatchMessage(msg);
145 }
146
147 void Messenger::message(const MessageType1 &type, const MessageArg &arg0)
148 {
149   Message msg(1);
150   doInitMessage(msg);
151   msg.args[0] = arg0.copy();
152   msg.type = &type;
153   dispatchMessage(msg);
154 }
155
156 void Messenger::message(const MessageType2 &type,
157                         const MessageArg &arg0,
158                         const MessageArg &arg1)
159 {
160   Message msg(2);
161   doInitMessage(msg);
162   msg.args[0] = arg0.copy();
163   msg.args[1] = arg1.copy();
164   msg.type = &type;
165   dispatchMessage(msg);
166 }
167
168 void Messenger::message(const MessageType3 &type,
169                         const MessageArg &arg0,
170                         const MessageArg &arg1,
171                         const MessageArg &arg2)
172 {
173   Message msg(3);
174   doInitMessage(msg);
175   msg.args[0] = arg0.copy();
176   msg.args[1] = arg1.copy();
177   msg.args[2] = arg2.copy();
178   msg.type = &type;
179   dispatchMessage(msg);
180 }
181
182 void Messenger::message(const MessageType4 &type,
183                         const MessageArg &arg0,
184                         const MessageArg &arg1,
185                         const MessageArg &arg2,
186                         const MessageArg &arg3)
187 {
188   Message msg(4);
189   doInitMessage(msg);
190   msg.args[0] = arg0.copy();
191   msg.args[1] = arg1.copy();
192   msg.args[2] = arg2.copy();
193   msg.args[3] = arg3.copy();
194   msg.type = &type;
195   dispatchMessage(msg);
196 }
197
198 void Messenger::message(const MessageType5 &type,
199                         const MessageArg &arg0,
200                         const MessageArg &arg1,
201                         const MessageArg &arg2,
202                         const MessageArg &arg3,
203                         const MessageArg &arg4)
204 {
205   Message msg(5);
206   doInitMessage(msg);
207   msg.args[0] = arg0.copy();
208   msg.args[1] = arg1.copy();
209   msg.args[2] = arg2.copy();
210   msg.args[3] = arg3.copy();
211   msg.args[4] = arg4.copy();
212   msg.type = &type;
213   dispatchMessage(msg);
214 }
215
216 void Messenger::message(const MessageType6 &type,
217                         const MessageArg &arg0,
218                         const MessageArg &arg1,
219                         const MessageArg &arg2,
220                         const MessageArg &arg3,
221                         const MessageArg &arg4,
222                         const MessageArg &arg5)
223 {
224   Message msg(6);
225   doInitMessage(msg);
226   msg.args[0] = arg0.copy();
227   msg.args[1] = arg1.copy();
228   msg.args[2] = arg2.copy();
229   msg.args[3] = arg3.copy();
230   msg.args[4] = arg4.copy();
231   msg.args[5] = arg5.copy();
232   msg.type = &type;
233   dispatchMessage(msg);
234 }
235
236 void Messenger::message(const MessageType0L &type, const Location &loc)
237 {
238   Message msg(0);
239   doInitMessage(msg);
240   msg.type = &type;
241   msg.auxLoc = loc;
242   dispatchMessage(msg);
243 }
244
245 void Messenger::message(const MessageType1L &type, const MessageArg &arg0,
246                         const Location &loc)
247 {
248   Message msg(1);
249   doInitMessage(msg);
250   msg.args[0] = arg0.copy();
251   msg.type = &type;
252   msg.auxLoc = loc;
253   dispatchMessage(msg);
254 }
255
256
257 void Messenger::setNextLocation(const Location &loc)
258 {
259   haveNextLocation_ = 1;
260   nextLocation_ = loc;
261 }
262
263 void Messenger::initMessage(Message &)
264 {
265 }
266
267 void Messenger::doInitMessage(Message &msg)
268 {
269   initMessage(msg);
270   if (haveNextLocation_) {
271     msg.loc = nextLocation_;
272     haveNextLocation_ = 0;
273   }
274 }
275
276 ForwardingMessenger::ForwardingMessenger(Messenger &to)
277 : to_(&to)
278 {
279 }
280
281 void ForwardingMessenger::dispatchMessage(Message &msg)
282 {
283   to_->dispatchMessage(msg);
284 }
285
286 void ForwardingMessenger::dispatchMessage(const Message &msg)
287 {
288   to_->dispatchMessage(msg);
289 }
290
291 void ForwardingMessenger::initMessage(Message &msg)
292 {
293   to_->initMessage(msg);
294 }
295
296 ParentLocationMessenger::ParentLocationMessenger(Messenger &mgr)
297 : ForwardingMessenger(mgr)
298 {
299 }
300
301 void ParentLocationMessenger::initMessage(Message &msg)
302 {
303   ForwardingMessenger::initMessage(msg);
304   if (!msg.loc.origin().isNull())
305     msg.loc = msg.loc.origin()->parent();
306 }
307
308 NullMessenger::NullMessenger()
309 {
310 }
311
312 void NullMessenger::dispatchMessage(Message &)
313 {
314 }
315
316 void NullMessenger::dispatchMessage(const Message &)
317 {
318 }
319
320 #ifdef SP_NAMESPACE
321 }
322 #endif