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