]> git.mxchange.org Git - simgear.git/blob - simgear/misc/exception.cxx
- new file: implementation of SimGear general exception classes
[simgear.git] / simgear / misc / exception.cxx
1 // exception.cxx - implementation of SimGear base exceptions.
2 // Started Summer 2001 by David Megginson, david@megginson.com
3 // This code is released into the Public Domain.
4 //
5 // $Id$
6
7
8 #include "exception.hxx"
9 #include <stdio.h>
10
11 \f
12 ////////////////////////////////////////////////////////////////////////
13 // Implementation of sg_location class.
14 ////////////////////////////////////////////////////////////////////////
15
16 sg_location::sg_location ()
17   : _path(""),
18     _line(-1),
19     _column(-1),
20     _byte(-1)
21 {
22 }
23
24 sg_location::sg_location (const string &path, int line, int column)
25   : _path(path),
26     _line(line),
27     _column(column),
28     _byte(-1)
29 {
30 }
31
32 sg_location::~sg_location ()
33 {
34 }
35
36 const string &
37 sg_location::getPath () const
38 {
39   return _path;
40 }
41
42 void
43 sg_location::setPath (const string &path)
44 {
45   _path = path;
46 }
47
48 int
49 sg_location::getLine () const
50 {
51   return _line;
52 }
53
54 void
55 sg_location::setLine (int line)
56 {
57   _line = line;
58 }
59
60 int
61 sg_location::getColumn () const
62 {
63   return _column;
64 }
65
66 void
67 sg_location::setColumn (int column)
68 {
69   _column = column;
70 }
71
72 int
73 sg_location::getByte () const
74 {
75   return _byte;
76 }
77
78 void
79 sg_location::setByte (int byte)
80 {
81   _byte = byte;
82 }
83
84 string
85 sg_location::asString () const
86 {
87   char buf[128];
88   string out = "";
89   if (_path != "") {
90     out += _path;
91     if (_line != -1 || _column != -1)
92       out += ",\n";
93   }
94   if (_line != -1) {
95     sprintf(buf, "line %d", _line);
96     out += buf;
97     if (_column != -1)
98       out += ",\n";
99   }
100   if (_column != -1) {
101     sprintf(buf, "column %d", _column);
102     out += buf;
103   }
104   return out;
105     
106 }
107
108
109 \f
110 ////////////////////////////////////////////////////////////////////////
111 // Implementation of sg_throwable class.
112 ////////////////////////////////////////////////////////////////////////
113
114 sg_throwable::sg_throwable ()
115   : _message(""),
116     _origin("")
117 {
118 }
119
120 sg_throwable::sg_throwable (const string &message, const string &origin)
121   : _message(message),
122     _origin(origin)
123 {
124 }
125
126 sg_throwable::~sg_throwable ()
127 {
128 }
129
130 const string &
131 sg_throwable::getMessage () const
132 {
133   return _message;
134 }
135
136 void
137 sg_throwable::setMessage (const string &message)
138 {
139   _message = message;
140 }
141
142 const string &
143 sg_throwable::getOrigin () const
144 {
145   return _origin;
146 }
147
148 void
149 sg_throwable::setOrigin (const string &origin)
150 {
151   _origin = origin;
152 }
153
154
155 sg_throwable *
156 sg_throwable::clone () const
157 {
158   return new sg_throwable(getMessage(), getOrigin());
159 }
160
161
162
163 \f
164 ////////////////////////////////////////////////////////////////////////
165 // Implementation of sg_error class.
166 ////////////////////////////////////////////////////////////////////////
167
168 sg_error::sg_error ()
169   : sg_throwable ()
170 {
171 }
172
173 sg_error::sg_error (const string &message, const string &origin)
174   : sg_throwable(message, origin)
175 {
176 }
177
178 sg_error::~sg_error ()
179 {
180 }
181
182 sg_error *
183 sg_error::clone () const
184 {
185   return new sg_error(getMessage(), getOrigin());
186 }
187
188
189 \f
190 ////////////////////////////////////////////////////////////////////////
191 // Implementation of sg_exception class.
192 ////////////////////////////////////////////////////////////////////////
193
194 sg_exception::sg_exception ()
195   : sg_throwable ()
196 {
197 }
198
199 sg_exception::sg_exception (const string &message, const string &origin)
200   : sg_throwable(message, origin)
201 {
202 }
203
204 sg_exception::~sg_exception ()
205 {
206 }
207
208 sg_exception *
209 sg_exception::clone () const
210 {
211   return new sg_exception(getMessage(), getOrigin());
212 }
213
214
215 \f
216 ////////////////////////////////////////////////////////////////////////
217 // Implementation of sg_io_exception.
218 ////////////////////////////////////////////////////////////////////////
219
220 sg_io_exception::sg_io_exception ()
221   : sg_exception()
222 {
223 }
224
225 sg_io_exception::sg_io_exception (const string &message, const string &origin)
226   : sg_exception(message, origin)
227 {
228 }
229
230 sg_io_exception::sg_io_exception (const string &message,
231                                   const sg_location &location,
232                                   const string &origin)
233   : sg_exception(message, origin),
234     _location(location)
235 {
236 }
237
238 sg_io_exception::~sg_io_exception ()
239 {
240 }
241
242 const sg_location &
243 sg_io_exception::getLocation () const
244 {
245   return _location;
246 }
247
248 void
249 sg_io_exception::setLocation (const sg_location &location)
250 {
251   _location = location;
252 }
253
254 sg_io_exception *
255 sg_io_exception::clone () const
256 {
257   return new sg_io_exception(getMessage(), getLocation(), getOrigin());
258 }
259
260
261
262 \f
263 ////////////////////////////////////////////////////////////////////////
264 // Implementation of sg_format_exception.
265 ////////////////////////////////////////////////////////////////////////
266
267 sg_format_exception::sg_format_exception ()
268   : sg_exception(),
269     _text("")
270 {
271 }
272
273 sg_format_exception::sg_format_exception (const string &message,
274                                           const string &text,
275                                           const string &origin)
276   : sg_exception(message, origin),
277     _text(text)
278 {
279 }
280
281 sg_format_exception::~sg_format_exception ()
282 {
283 }
284
285 const string &
286 sg_format_exception::getText () const
287 {
288   return _text;
289 }
290
291 void
292 sg_format_exception::setText (const string &text)
293 {
294   _text = text;
295 }
296
297 sg_format_exception *
298 sg_format_exception::clone () const
299 {
300   return new sg_format_exception(getMessage(), getText(), getOrigin());
301 }
302
303
304 \f
305 ////////////////////////////////////////////////////////////////////////
306 // Implementation of sg_range_exception.
307 ////////////////////////////////////////////////////////////////////////
308
309 sg_range_exception::sg_range_exception ()
310   : sg_exception()
311 {
312 }
313
314 sg_range_exception::sg_range_exception (const string &message,
315                                         const string &origin)
316   : sg_exception(message, origin)
317 {
318 }
319
320 sg_range_exception::~sg_range_exception ()
321 {
322 }
323
324 sg_range_exception *
325 sg_range_exception::clone () const
326 {
327   return new sg_range_exception(getMessage(), getOrigin());
328 }
329
330
331 // end of exception.cxx