Chris@16
|
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
|
Chris@16
|
2
|
Chris@16
|
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
|
Chris@16
|
7 #define UUID_274DA366004E11DCB1DDFE2E56D89593
|
Chris@16
|
8 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
9 #pragma GCC system_header
|
Chris@16
|
10 #endif
|
Chris@16
|
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
12 #pragma warning(push,1)
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 namespace
|
Chris@16
|
16 boost
|
Chris@16
|
17 {
|
Chris@16
|
18 namespace
|
Chris@16
|
19 exception_detail
|
Chris@16
|
20 {
|
Chris@16
|
21 template <class T>
|
Chris@16
|
22 class
|
Chris@16
|
23 refcount_ptr
|
Chris@16
|
24 {
|
Chris@16
|
25 public:
|
Chris@16
|
26
|
Chris@16
|
27 refcount_ptr():
|
Chris@16
|
28 px_(0)
|
Chris@16
|
29 {
|
Chris@16
|
30 }
|
Chris@16
|
31
|
Chris@16
|
32 ~refcount_ptr()
|
Chris@16
|
33 {
|
Chris@16
|
34 release();
|
Chris@16
|
35 }
|
Chris@16
|
36
|
Chris@16
|
37 refcount_ptr( refcount_ptr const & x ):
|
Chris@16
|
38 px_(x.px_)
|
Chris@16
|
39 {
|
Chris@16
|
40 add_ref();
|
Chris@16
|
41 }
|
Chris@16
|
42
|
Chris@16
|
43 refcount_ptr &
|
Chris@16
|
44 operator=( refcount_ptr const & x )
|
Chris@16
|
45 {
|
Chris@16
|
46 adopt(x.px_);
|
Chris@16
|
47 return *this;
|
Chris@16
|
48 }
|
Chris@16
|
49
|
Chris@16
|
50 void
|
Chris@16
|
51 adopt( T * px )
|
Chris@16
|
52 {
|
Chris@16
|
53 release();
|
Chris@16
|
54 px_=px;
|
Chris@16
|
55 add_ref();
|
Chris@16
|
56 }
|
Chris@16
|
57
|
Chris@16
|
58 T *
|
Chris@16
|
59 get() const
|
Chris@16
|
60 {
|
Chris@16
|
61 return px_;
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 private:
|
Chris@16
|
65
|
Chris@16
|
66 T * px_;
|
Chris@16
|
67
|
Chris@16
|
68 void
|
Chris@16
|
69 add_ref()
|
Chris@16
|
70 {
|
Chris@16
|
71 if( px_ )
|
Chris@16
|
72 px_->add_ref();
|
Chris@16
|
73 }
|
Chris@16
|
74
|
Chris@16
|
75 void
|
Chris@16
|
76 release()
|
Chris@16
|
77 {
|
Chris@16
|
78 if( px_ && px_->release() )
|
Chris@16
|
79 px_=0;
|
Chris@16
|
80 }
|
Chris@16
|
81 };
|
Chris@16
|
82 }
|
Chris@16
|
83
|
Chris@16
|
84 ////////////////////////////////////////////////////////////////////////
|
Chris@16
|
85
|
Chris@16
|
86 template <class Tag,class T>
|
Chris@16
|
87 class error_info;
|
Chris@16
|
88
|
Chris@16
|
89 typedef error_info<struct throw_function_,char const *> throw_function;
|
Chris@16
|
90 typedef error_info<struct throw_file_,char const *> throw_file;
|
Chris@16
|
91 typedef error_info<struct throw_line_,int> throw_line;
|
Chris@16
|
92
|
Chris@16
|
93 template <>
|
Chris@16
|
94 class
|
Chris@16
|
95 error_info<throw_function_,char const *>
|
Chris@16
|
96 {
|
Chris@16
|
97 public:
|
Chris@16
|
98 typedef char const * value_type;
|
Chris@16
|
99 value_type v_;
|
Chris@16
|
100 explicit
|
Chris@16
|
101 error_info( value_type v ):
|
Chris@16
|
102 v_(v)
|
Chris@16
|
103 {
|
Chris@16
|
104 }
|
Chris@16
|
105 };
|
Chris@16
|
106
|
Chris@16
|
107 template <>
|
Chris@16
|
108 class
|
Chris@16
|
109 error_info<throw_file_,char const *>
|
Chris@16
|
110 {
|
Chris@16
|
111 public:
|
Chris@16
|
112 typedef char const * value_type;
|
Chris@16
|
113 value_type v_;
|
Chris@16
|
114 explicit
|
Chris@16
|
115 error_info( value_type v ):
|
Chris@16
|
116 v_(v)
|
Chris@16
|
117 {
|
Chris@16
|
118 }
|
Chris@16
|
119 };
|
Chris@16
|
120
|
Chris@16
|
121 template <>
|
Chris@16
|
122 class
|
Chris@16
|
123 error_info<throw_line_,int>
|
Chris@16
|
124 {
|
Chris@16
|
125 public:
|
Chris@16
|
126 typedef int value_type;
|
Chris@16
|
127 value_type v_;
|
Chris@16
|
128 explicit
|
Chris@16
|
129 error_info( value_type v ):
|
Chris@16
|
130 v_(v)
|
Chris@16
|
131 {
|
Chris@16
|
132 }
|
Chris@16
|
133 };
|
Chris@16
|
134
|
Chris@16
|
135 #if defined(__GNUC__)
|
Chris@16
|
136 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
137 # pragma GCC visibility push (default)
|
Chris@16
|
138 # endif
|
Chris@16
|
139 #endif
|
Chris@16
|
140 class exception;
|
Chris@16
|
141 #if defined(__GNUC__)
|
Chris@16
|
142 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
143 # pragma GCC visibility pop
|
Chris@16
|
144 # endif
|
Chris@16
|
145 #endif
|
Chris@16
|
146
|
Chris@16
|
147 template <class T>
|
Chris@16
|
148 class shared_ptr;
|
Chris@16
|
149
|
Chris@16
|
150 namespace
|
Chris@16
|
151 exception_detail
|
Chris@16
|
152 {
|
Chris@16
|
153 class error_info_base;
|
Chris@16
|
154 struct type_info_;
|
Chris@16
|
155
|
Chris@16
|
156 struct
|
Chris@16
|
157 error_info_container
|
Chris@16
|
158 {
|
Chris@16
|
159 virtual char const * diagnostic_information( char const * ) const = 0;
|
Chris@16
|
160 virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
|
Chris@16
|
161 virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
|
Chris@16
|
162 virtual void add_ref() const = 0;
|
Chris@16
|
163 virtual bool release() const = 0;
|
Chris@16
|
164 virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
|
Chris@16
|
165
|
Chris@16
|
166 protected:
|
Chris@16
|
167
|
Chris@16
|
168 ~error_info_container() throw()
|
Chris@16
|
169 {
|
Chris@16
|
170 }
|
Chris@16
|
171 };
|
Chris@16
|
172
|
Chris@16
|
173 template <class>
|
Chris@16
|
174 struct get_info;
|
Chris@16
|
175
|
Chris@16
|
176 template <>
|
Chris@16
|
177 struct get_info<throw_function>;
|
Chris@16
|
178
|
Chris@16
|
179 template <>
|
Chris@16
|
180 struct get_info<throw_file>;
|
Chris@16
|
181
|
Chris@16
|
182 template <>
|
Chris@16
|
183 struct get_info<throw_line>;
|
Chris@16
|
184
|
Chris@16
|
185 char const * get_diagnostic_information( exception const &, char const * );
|
Chris@16
|
186
|
Chris@16
|
187 void copy_boost_exception( exception *, exception const * );
|
Chris@16
|
188
|
Chris@16
|
189 template <class E,class Tag,class T>
|
Chris@16
|
190 E const & set_info( E const &, error_info<Tag,T> const & );
|
Chris@16
|
191
|
Chris@16
|
192 template <class E>
|
Chris@16
|
193 E const & set_info( E const &, throw_function const & );
|
Chris@16
|
194
|
Chris@16
|
195 template <class E>
|
Chris@16
|
196 E const & set_info( E const &, throw_file const & );
|
Chris@16
|
197
|
Chris@16
|
198 template <class E>
|
Chris@16
|
199 E const & set_info( E const &, throw_line const & );
|
Chris@16
|
200 }
|
Chris@16
|
201
|
Chris@16
|
202 #if defined(__GNUC__)
|
Chris@16
|
203 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
204 # pragma GCC visibility push (default)
|
Chris@16
|
205 # endif
|
Chris@16
|
206 #endif
|
Chris@16
|
207 class
|
Chris@16
|
208 exception
|
Chris@16
|
209 {
|
Chris@16
|
210 protected:
|
Chris@16
|
211
|
Chris@16
|
212 exception():
|
Chris@16
|
213 throw_function_(0),
|
Chris@16
|
214 throw_file_(0),
|
Chris@16
|
215 throw_line_(-1)
|
Chris@16
|
216 {
|
Chris@16
|
217 }
|
Chris@16
|
218
|
Chris@16
|
219 #ifdef __HP_aCC
|
Chris@16
|
220 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
|
Chris@16
|
221 //On all other platforms, the same effect is achieved by the pure virtual destructor.
|
Chris@16
|
222 exception( exception const & x ) throw():
|
Chris@16
|
223 data_(x.data_),
|
Chris@16
|
224 throw_function_(x.throw_function_),
|
Chris@16
|
225 throw_file_(x.throw_file_),
|
Chris@16
|
226 throw_line_(x.throw_line_)
|
Chris@16
|
227 {
|
Chris@16
|
228 }
|
Chris@16
|
229 #endif
|
Chris@16
|
230
|
Chris@16
|
231 virtual ~exception() throw()
|
Chris@16
|
232 #ifndef __HP_aCC
|
Chris@16
|
233 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
|
Chris@16
|
234 #endif
|
Chris@16
|
235 ;
|
Chris@16
|
236
|
Chris@16
|
237 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
|
Chris@16
|
238 public:
|
Chris@16
|
239 #else
|
Chris@16
|
240 private:
|
Chris@16
|
241
|
Chris@16
|
242 template <class E>
|
Chris@16
|
243 friend E const & exception_detail::set_info( E const &, throw_function const & );
|
Chris@16
|
244
|
Chris@16
|
245 template <class E>
|
Chris@16
|
246 friend E const & exception_detail::set_info( E const &, throw_file const & );
|
Chris@16
|
247
|
Chris@16
|
248 template <class E>
|
Chris@16
|
249 friend E const & exception_detail::set_info( E const &, throw_line const & );
|
Chris@16
|
250
|
Chris@16
|
251 template <class E,class Tag,class T>
|
Chris@16
|
252 friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
|
Chris@16
|
253
|
Chris@16
|
254 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
|
Chris@16
|
255
|
Chris@16
|
256 template <class>
|
Chris@16
|
257 friend struct exception_detail::get_info;
|
Chris@16
|
258 friend struct exception_detail::get_info<throw_function>;
|
Chris@16
|
259 friend struct exception_detail::get_info<throw_file>;
|
Chris@16
|
260 friend struct exception_detail::get_info<throw_line>;
|
Chris@16
|
261 friend void exception_detail::copy_boost_exception( exception *, exception const * );
|
Chris@16
|
262 #endif
|
Chris@16
|
263 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
|
Chris@16
|
264 mutable char const * throw_function_;
|
Chris@16
|
265 mutable char const * throw_file_;
|
Chris@16
|
266 mutable int throw_line_;
|
Chris@16
|
267 };
|
Chris@16
|
268 #if defined(__GNUC__)
|
Chris@16
|
269 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
270 # pragma GCC visibility pop
|
Chris@16
|
271 # endif
|
Chris@16
|
272 #endif
|
Chris@16
|
273
|
Chris@16
|
274 inline
|
Chris@16
|
275 exception::
|
Chris@16
|
276 ~exception() throw()
|
Chris@16
|
277 {
|
Chris@16
|
278 }
|
Chris@16
|
279
|
Chris@16
|
280 namespace
|
Chris@16
|
281 exception_detail
|
Chris@16
|
282 {
|
Chris@16
|
283 template <class E>
|
Chris@16
|
284 E const &
|
Chris@16
|
285 set_info( E const & x, throw_function const & y )
|
Chris@16
|
286 {
|
Chris@16
|
287 x.throw_function_=y.v_;
|
Chris@16
|
288 return x;
|
Chris@16
|
289 }
|
Chris@16
|
290
|
Chris@16
|
291 template <class E>
|
Chris@16
|
292 E const &
|
Chris@16
|
293 set_info( E const & x, throw_file const & y )
|
Chris@16
|
294 {
|
Chris@16
|
295 x.throw_file_=y.v_;
|
Chris@16
|
296 return x;
|
Chris@16
|
297 }
|
Chris@16
|
298
|
Chris@16
|
299 template <class E>
|
Chris@16
|
300 E const &
|
Chris@16
|
301 set_info( E const & x, throw_line const & y )
|
Chris@16
|
302 {
|
Chris@16
|
303 x.throw_line_=y.v_;
|
Chris@16
|
304 return x;
|
Chris@16
|
305 }
|
Chris@16
|
306 }
|
Chris@16
|
307
|
Chris@16
|
308 ////////////////////////////////////////////////////////////////////////
|
Chris@16
|
309
|
Chris@16
|
310 namespace
|
Chris@16
|
311 exception_detail
|
Chris@16
|
312 {
|
Chris@16
|
313 #if defined(__GNUC__)
|
Chris@16
|
314 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
315 # pragma GCC visibility push (default)
|
Chris@16
|
316 # endif
|
Chris@16
|
317 #endif
|
Chris@16
|
318 template <class T>
|
Chris@16
|
319 struct
|
Chris@16
|
320 error_info_injector:
|
Chris@16
|
321 public T,
|
Chris@16
|
322 public exception
|
Chris@16
|
323 {
|
Chris@16
|
324 explicit
|
Chris@16
|
325 error_info_injector( T const & x ):
|
Chris@16
|
326 T(x)
|
Chris@16
|
327 {
|
Chris@16
|
328 }
|
Chris@16
|
329
|
Chris@16
|
330 ~error_info_injector() throw()
|
Chris@16
|
331 {
|
Chris@16
|
332 }
|
Chris@16
|
333 };
|
Chris@16
|
334 #if defined(__GNUC__)
|
Chris@16
|
335 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
336 # pragma GCC visibility pop
|
Chris@16
|
337 # endif
|
Chris@16
|
338 #endif
|
Chris@16
|
339
|
Chris@16
|
340 struct large_size { char c[256]; };
|
Chris@16
|
341 large_size dispatch_boost_exception( exception const * );
|
Chris@16
|
342
|
Chris@16
|
343 struct small_size { };
|
Chris@16
|
344 small_size dispatch_boost_exception( void const * );
|
Chris@16
|
345
|
Chris@16
|
346 template <class,int>
|
Chris@16
|
347 struct enable_error_info_helper;
|
Chris@16
|
348
|
Chris@16
|
349 template <class T>
|
Chris@16
|
350 struct
|
Chris@16
|
351 enable_error_info_helper<T,sizeof(large_size)>
|
Chris@16
|
352 {
|
Chris@16
|
353 typedef T type;
|
Chris@16
|
354 };
|
Chris@16
|
355
|
Chris@16
|
356 template <class T>
|
Chris@16
|
357 struct
|
Chris@16
|
358 enable_error_info_helper<T,sizeof(small_size)>
|
Chris@16
|
359 {
|
Chris@16
|
360 typedef error_info_injector<T> type;
|
Chris@16
|
361 };
|
Chris@16
|
362
|
Chris@16
|
363 template <class T>
|
Chris@16
|
364 struct
|
Chris@16
|
365 enable_error_info_return_type
|
Chris@16
|
366 {
|
Chris@16
|
367 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
|
Chris@16
|
368 };
|
Chris@16
|
369 }
|
Chris@16
|
370
|
Chris@16
|
371 template <class T>
|
Chris@16
|
372 inline
|
Chris@16
|
373 typename
|
Chris@16
|
374 exception_detail::enable_error_info_return_type<T>::type
|
Chris@16
|
375 enable_error_info( T const & x )
|
Chris@16
|
376 {
|
Chris@16
|
377 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
|
Chris@16
|
378 return rt(x);
|
Chris@16
|
379 }
|
Chris@16
|
380
|
Chris@16
|
381 ////////////////////////////////////////////////////////////////////////
|
Chris@16
|
382
|
Chris@16
|
383 namespace
|
Chris@16
|
384 exception_detail
|
Chris@16
|
385 {
|
Chris@16
|
386 #if defined(__GNUC__)
|
Chris@16
|
387 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
388 # pragma GCC visibility push (default)
|
Chris@16
|
389 # endif
|
Chris@16
|
390 #endif
|
Chris@16
|
391 class
|
Chris@16
|
392 clone_base
|
Chris@16
|
393 {
|
Chris@16
|
394 public:
|
Chris@16
|
395
|
Chris@16
|
396 virtual clone_base const * clone() const = 0;
|
Chris@16
|
397 virtual void rethrow() const = 0;
|
Chris@16
|
398
|
Chris@16
|
399 virtual
|
Chris@16
|
400 ~clone_base() throw()
|
Chris@16
|
401 {
|
Chris@16
|
402 }
|
Chris@16
|
403 };
|
Chris@16
|
404 #if defined(__GNUC__)
|
Chris@16
|
405 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
406 # pragma GCC visibility pop
|
Chris@16
|
407 # endif
|
Chris@16
|
408 #endif
|
Chris@16
|
409
|
Chris@16
|
410 inline
|
Chris@16
|
411 void
|
Chris@16
|
412 copy_boost_exception( exception * a, exception const * b )
|
Chris@16
|
413 {
|
Chris@16
|
414 refcount_ptr<error_info_container> data;
|
Chris@16
|
415 if( error_info_container * d=b->data_.get() )
|
Chris@16
|
416 data = d->clone();
|
Chris@16
|
417 a->throw_file_ = b->throw_file_;
|
Chris@16
|
418 a->throw_line_ = b->throw_line_;
|
Chris@16
|
419 a->throw_function_ = b->throw_function_;
|
Chris@16
|
420 a->data_ = data;
|
Chris@16
|
421 }
|
Chris@16
|
422
|
Chris@16
|
423 inline
|
Chris@16
|
424 void
|
Chris@16
|
425 copy_boost_exception( void *, void const * )
|
Chris@16
|
426 {
|
Chris@16
|
427 }
|
Chris@16
|
428
|
Chris@16
|
429 template <class T>
|
Chris@16
|
430 class
|
Chris@16
|
431 clone_impl:
|
Chris@16
|
432 public T,
|
Chris@16
|
433 public virtual clone_base
|
Chris@16
|
434 {
|
Chris@16
|
435 struct clone_tag { };
|
Chris@16
|
436 clone_impl( clone_impl const & x, clone_tag ):
|
Chris@16
|
437 T(x)
|
Chris@16
|
438 {
|
Chris@16
|
439 copy_boost_exception(this,&x);
|
Chris@16
|
440 }
|
Chris@16
|
441
|
Chris@16
|
442 public:
|
Chris@16
|
443
|
Chris@16
|
444 explicit
|
Chris@16
|
445 clone_impl( T const & x ):
|
Chris@16
|
446 T(x)
|
Chris@16
|
447 {
|
Chris@16
|
448 copy_boost_exception(this,&x);
|
Chris@16
|
449 }
|
Chris@16
|
450
|
Chris@16
|
451 ~clone_impl() throw()
|
Chris@16
|
452 {
|
Chris@16
|
453 }
|
Chris@16
|
454
|
Chris@16
|
455 private:
|
Chris@16
|
456
|
Chris@16
|
457 clone_base const *
|
Chris@16
|
458 clone() const
|
Chris@16
|
459 {
|
Chris@16
|
460 return new clone_impl(*this,clone_tag());
|
Chris@16
|
461 }
|
Chris@16
|
462
|
Chris@16
|
463 void
|
Chris@16
|
464 rethrow() const
|
Chris@16
|
465 {
|
Chris@16
|
466 throw*this;
|
Chris@16
|
467 }
|
Chris@16
|
468 };
|
Chris@16
|
469 }
|
Chris@16
|
470
|
Chris@16
|
471 template <class T>
|
Chris@16
|
472 inline
|
Chris@16
|
473 exception_detail::clone_impl<T>
|
Chris@16
|
474 enable_current_exception( T const & x )
|
Chris@16
|
475 {
|
Chris@16
|
476 return exception_detail::clone_impl<T>(x);
|
Chris@16
|
477 }
|
Chris@16
|
478 }
|
Chris@16
|
479
|
Chris@16
|
480 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
481 #pragma warning(pop)
|
Chris@16
|
482 #endif
|
Chris@16
|
483 #endif
|