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