]> git.mxchange.org Git - simgear.git/blob - simgear/structure/exception.cxx
Portability fix
[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   ret += "\n at ";
233   ret += getLocation().asString();
234   return ret;
235 }
236
237 const sg_location &
238 sg_io_exception::getLocation () const
239 {
240   return _location;
241 }
242
243 void
244 sg_io_exception::setLocation (const sg_location &location)
245 {
246   _location = location;
247 }
248
249
250 \f
251 ////////////////////////////////////////////////////////////////////////
252 // Implementation of sg_format_exception.
253 ////////////////////////////////////////////////////////////////////////
254
255 sg_format_exception::sg_format_exception ()
256   : sg_exception(),
257     _text("")
258 {
259 }
260
261 sg_format_exception::sg_format_exception (const string &message,
262                                           const string &text,
263                                           const string &origin)
264   : sg_exception(message, origin),
265     _text(text)
266 {
267 }
268
269 sg_format_exception::~sg_format_exception ()
270 {
271 }
272
273 const string &
274 sg_format_exception::getText () const
275 {
276   return _text;
277 }
278
279 void
280 sg_format_exception::setText (const string &text)
281 {
282   _text = text;
283 }
284
285
286 \f
287 ////////////////////////////////////////////////////////////////////////
288 // Implementation of sg_range_exception.
289 ////////////////////////////////////////////////////////////////////////
290
291 sg_range_exception::sg_range_exception ()
292   : sg_exception()
293 {
294 }
295
296 sg_range_exception::sg_range_exception (const string &message,
297                                         const string &origin)
298   : sg_exception(message, origin)
299 {
300 }
301
302 sg_range_exception::~sg_range_exception ()
303 {
304 }
305
306
307 // end of exception.cxx