]> git.mxchange.org Git - simgear.git/blob - simgear/structure/exception.cxx
Mathias Fröhlich:
[simgear.git] / simgear / structure / 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.empty()) {
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 += ", ";
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 const string
137 sg_throwable::getFormattedMessage () const
138 {
139   return getMessage();
140 }
141
142 void
143 sg_throwable::setMessage (const string &message)
144 {
145   _message = message;
146 }
147
148 const string &
149 sg_throwable::getOrigin () const
150 {
151   return _origin;
152 }
153
154 void
155 sg_throwable::setOrigin (const string &origin)
156 {
157   _origin = origin;
158 }
159
160
161 \f
162 ////////////////////////////////////////////////////////////////////////
163 // Implementation of sg_error class.
164 ////////////////////////////////////////////////////////////////////////
165
166 sg_error::sg_error ()
167   : sg_throwable ()
168 {
169 }
170
171 sg_error::sg_error (const string &message, const string &origin)
172   : sg_throwable(message, origin)
173 {
174 }
175
176 sg_error::~sg_error ()
177 {
178 }
179
180
181 \f
182 ////////////////////////////////////////////////////////////////////////
183 // Implementation of sg_exception class.
184 ////////////////////////////////////////////////////////////////////////
185
186 sg_exception::sg_exception ()
187   : sg_throwable ()
188 {
189 }
190
191 sg_exception::sg_exception (const string &message, const string &origin)
192   : sg_throwable(message, origin)
193 {
194 }
195
196 sg_exception::~sg_exception ()
197 {
198 }
199
200
201 \f
202 ////////////////////////////////////////////////////////////////////////
203 // Implementation of sg_io_exception.
204 ////////////////////////////////////////////////////////////////////////
205
206 sg_io_exception::sg_io_exception ()
207   : sg_exception()
208 {
209 }
210
211 sg_io_exception::sg_io_exception (const string &message, const string &origin)
212   : sg_exception(message, origin)
213 {
214 }
215
216 sg_io_exception::sg_io_exception (const string &message,
217                                   const sg_location &location,
218                                   const string &origin)
219   : sg_exception(message, origin),
220     _location(location)
221 {
222 }
223
224 sg_io_exception::~sg_io_exception ()
225 {
226 }
227
228 const string
229 sg_io_exception::getFormattedMessage () const
230 {
231   string ret = getMessage();
232   string loc = getLocation().asString();
233   if (loc.length()) {
234     ret += "\n at ";
235     ret += loc;
236   }
237   return ret;
238 }
239
240 const sg_location &
241 sg_io_exception::getLocation () const
242 {
243   return _location;
244 }
245
246 void
247 sg_io_exception::setLocation (const sg_location &location)
248 {
249   _location = location;
250 }
251
252
253 \f
254 ////////////////////////////////////////////////////////////////////////
255 // Implementation of sg_format_exception.
256 ////////////////////////////////////////////////////////////////////////
257
258 sg_format_exception::sg_format_exception ()
259   : sg_exception(),
260     _text("")
261 {
262 }
263
264 sg_format_exception::sg_format_exception (const string &message,
265                                           const string &text,
266                                           const string &origin)
267   : sg_exception(message, origin),
268     _text(text)
269 {
270 }
271
272 sg_format_exception::~sg_format_exception ()
273 {
274 }
275
276 const string &
277 sg_format_exception::getText () const
278 {
279   return _text;
280 }
281
282 void
283 sg_format_exception::setText (const string &text)
284 {
285   _text = text;
286 }
287
288
289 \f
290 ////////////////////////////////////////////////////////////////////////
291 // Implementation of sg_range_exception.
292 ////////////////////////////////////////////////////////////////////////
293
294 sg_range_exception::sg_range_exception ()
295   : sg_exception()
296 {
297 }
298
299 sg_range_exception::sg_range_exception (const string &message,
300                                         const string &origin)
301   : sg_exception(message, origin)
302 {
303 }
304
305 sg_range_exception::~sg_range_exception ()
306 {
307 }
308
309
310 // end of exception.cxx