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@101
|
210 //<N3757>
|
Chris@101
|
211 public:
|
Chris@101
|
212 template <class Tag> void set( typename Tag::type const & );
|
Chris@101
|
213 template <class Tag> typename Tag::type const * get() const;
|
Chris@101
|
214 //</N3757>
|
Chris@101
|
215
|
Chris@16
|
216 protected:
|
Chris@16
|
217
|
Chris@16
|
218 exception():
|
Chris@16
|
219 throw_function_(0),
|
Chris@16
|
220 throw_file_(0),
|
Chris@16
|
221 throw_line_(-1)
|
Chris@16
|
222 {
|
Chris@16
|
223 }
|
Chris@16
|
224
|
Chris@16
|
225 #ifdef __HP_aCC
|
Chris@16
|
226 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
|
Chris@16
|
227 //On all other platforms, the same effect is achieved by the pure virtual destructor.
|
Chris@16
|
228 exception( exception const & x ) throw():
|
Chris@16
|
229 data_(x.data_),
|
Chris@16
|
230 throw_function_(x.throw_function_),
|
Chris@16
|
231 throw_file_(x.throw_file_),
|
Chris@16
|
232 throw_line_(x.throw_line_)
|
Chris@16
|
233 {
|
Chris@16
|
234 }
|
Chris@16
|
235 #endif
|
Chris@16
|
236
|
Chris@16
|
237 virtual ~exception() throw()
|
Chris@16
|
238 #ifndef __HP_aCC
|
Chris@16
|
239 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
|
Chris@16
|
240 #endif
|
Chris@16
|
241 ;
|
Chris@16
|
242
|
Chris@16
|
243 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
|
Chris@16
|
244 public:
|
Chris@16
|
245 #else
|
Chris@16
|
246 private:
|
Chris@16
|
247
|
Chris@16
|
248 template <class E>
|
Chris@16
|
249 friend E const & exception_detail::set_info( E const &, throw_function const & );
|
Chris@16
|
250
|
Chris@16
|
251 template <class E>
|
Chris@16
|
252 friend E const & exception_detail::set_info( E const &, throw_file const & );
|
Chris@16
|
253
|
Chris@16
|
254 template <class E>
|
Chris@16
|
255 friend E const & exception_detail::set_info( E const &, throw_line const & );
|
Chris@16
|
256
|
Chris@16
|
257 template <class E,class Tag,class T>
|
Chris@16
|
258 friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
|
Chris@16
|
259
|
Chris@16
|
260 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
|
Chris@16
|
261
|
Chris@16
|
262 template <class>
|
Chris@16
|
263 friend struct exception_detail::get_info;
|
Chris@16
|
264 friend struct exception_detail::get_info<throw_function>;
|
Chris@16
|
265 friend struct exception_detail::get_info<throw_file>;
|
Chris@16
|
266 friend struct exception_detail::get_info<throw_line>;
|
Chris@16
|
267 friend void exception_detail::copy_boost_exception( exception *, exception const * );
|
Chris@16
|
268 #endif
|
Chris@16
|
269 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
|
Chris@16
|
270 mutable char const * throw_function_;
|
Chris@16
|
271 mutable char const * throw_file_;
|
Chris@16
|
272 mutable int throw_line_;
|
Chris@16
|
273 };
|
Chris@16
|
274 #if defined(__GNUC__)
|
Chris@16
|
275 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
276 # pragma GCC visibility pop
|
Chris@16
|
277 # endif
|
Chris@16
|
278 #endif
|
Chris@16
|
279
|
Chris@16
|
280 inline
|
Chris@16
|
281 exception::
|
Chris@16
|
282 ~exception() throw()
|
Chris@16
|
283 {
|
Chris@16
|
284 }
|
Chris@16
|
285
|
Chris@16
|
286 namespace
|
Chris@16
|
287 exception_detail
|
Chris@16
|
288 {
|
Chris@16
|
289 template <class E>
|
Chris@16
|
290 E const &
|
Chris@16
|
291 set_info( E const & x, throw_function const & y )
|
Chris@16
|
292 {
|
Chris@16
|
293 x.throw_function_=y.v_;
|
Chris@16
|
294 return x;
|
Chris@16
|
295 }
|
Chris@16
|
296
|
Chris@16
|
297 template <class E>
|
Chris@16
|
298 E const &
|
Chris@16
|
299 set_info( E const & x, throw_file const & y )
|
Chris@16
|
300 {
|
Chris@16
|
301 x.throw_file_=y.v_;
|
Chris@16
|
302 return x;
|
Chris@16
|
303 }
|
Chris@16
|
304
|
Chris@16
|
305 template <class E>
|
Chris@16
|
306 E const &
|
Chris@16
|
307 set_info( E const & x, throw_line const & y )
|
Chris@16
|
308 {
|
Chris@16
|
309 x.throw_line_=y.v_;
|
Chris@16
|
310 return x;
|
Chris@16
|
311 }
|
Chris@16
|
312 }
|
Chris@16
|
313
|
Chris@16
|
314 ////////////////////////////////////////////////////////////////////////
|
Chris@16
|
315
|
Chris@16
|
316 namespace
|
Chris@16
|
317 exception_detail
|
Chris@16
|
318 {
|
Chris@16
|
319 #if defined(__GNUC__)
|
Chris@16
|
320 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
321 # pragma GCC visibility push (default)
|
Chris@16
|
322 # endif
|
Chris@16
|
323 #endif
|
Chris@16
|
324 template <class T>
|
Chris@16
|
325 struct
|
Chris@16
|
326 error_info_injector:
|
Chris@16
|
327 public T,
|
Chris@16
|
328 public exception
|
Chris@16
|
329 {
|
Chris@16
|
330 explicit
|
Chris@16
|
331 error_info_injector( T const & x ):
|
Chris@16
|
332 T(x)
|
Chris@16
|
333 {
|
Chris@16
|
334 }
|
Chris@16
|
335
|
Chris@16
|
336 ~error_info_injector() throw()
|
Chris@16
|
337 {
|
Chris@16
|
338 }
|
Chris@16
|
339 };
|
Chris@16
|
340 #if defined(__GNUC__)
|
Chris@16
|
341 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
342 # pragma GCC visibility pop
|
Chris@16
|
343 # endif
|
Chris@16
|
344 #endif
|
Chris@16
|
345
|
Chris@16
|
346 struct large_size { char c[256]; };
|
Chris@16
|
347 large_size dispatch_boost_exception( exception const * );
|
Chris@16
|
348
|
Chris@16
|
349 struct small_size { };
|
Chris@16
|
350 small_size dispatch_boost_exception( void const * );
|
Chris@16
|
351
|
Chris@16
|
352 template <class,int>
|
Chris@16
|
353 struct enable_error_info_helper;
|
Chris@16
|
354
|
Chris@16
|
355 template <class T>
|
Chris@16
|
356 struct
|
Chris@16
|
357 enable_error_info_helper<T,sizeof(large_size)>
|
Chris@16
|
358 {
|
Chris@16
|
359 typedef T type;
|
Chris@16
|
360 };
|
Chris@16
|
361
|
Chris@16
|
362 template <class T>
|
Chris@16
|
363 struct
|
Chris@16
|
364 enable_error_info_helper<T,sizeof(small_size)>
|
Chris@16
|
365 {
|
Chris@16
|
366 typedef error_info_injector<T> type;
|
Chris@16
|
367 };
|
Chris@16
|
368
|
Chris@16
|
369 template <class T>
|
Chris@16
|
370 struct
|
Chris@16
|
371 enable_error_info_return_type
|
Chris@16
|
372 {
|
Chris@16
|
373 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
|
Chris@16
|
374 };
|
Chris@16
|
375 }
|
Chris@16
|
376
|
Chris@16
|
377 template <class T>
|
Chris@16
|
378 inline
|
Chris@16
|
379 typename
|
Chris@16
|
380 exception_detail::enable_error_info_return_type<T>::type
|
Chris@16
|
381 enable_error_info( T const & x )
|
Chris@16
|
382 {
|
Chris@16
|
383 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
|
Chris@16
|
384 return rt(x);
|
Chris@16
|
385 }
|
Chris@16
|
386
|
Chris@16
|
387 ////////////////////////////////////////////////////////////////////////
|
Chris@16
|
388
|
Chris@16
|
389 namespace
|
Chris@16
|
390 exception_detail
|
Chris@16
|
391 {
|
Chris@16
|
392 #if defined(__GNUC__)
|
Chris@16
|
393 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
394 # pragma GCC visibility push (default)
|
Chris@16
|
395 # endif
|
Chris@16
|
396 #endif
|
Chris@16
|
397 class
|
Chris@16
|
398 clone_base
|
Chris@16
|
399 {
|
Chris@16
|
400 public:
|
Chris@16
|
401
|
Chris@16
|
402 virtual clone_base const * clone() const = 0;
|
Chris@16
|
403 virtual void rethrow() const = 0;
|
Chris@16
|
404
|
Chris@16
|
405 virtual
|
Chris@16
|
406 ~clone_base() throw()
|
Chris@16
|
407 {
|
Chris@16
|
408 }
|
Chris@16
|
409 };
|
Chris@16
|
410 #if defined(__GNUC__)
|
Chris@16
|
411 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
Chris@16
|
412 # pragma GCC visibility pop
|
Chris@16
|
413 # endif
|
Chris@16
|
414 #endif
|
Chris@16
|
415
|
Chris@16
|
416 inline
|
Chris@16
|
417 void
|
Chris@16
|
418 copy_boost_exception( exception * a, exception const * b )
|
Chris@16
|
419 {
|
Chris@16
|
420 refcount_ptr<error_info_container> data;
|
Chris@16
|
421 if( error_info_container * d=b->data_.get() )
|
Chris@16
|
422 data = d->clone();
|
Chris@16
|
423 a->throw_file_ = b->throw_file_;
|
Chris@16
|
424 a->throw_line_ = b->throw_line_;
|
Chris@16
|
425 a->throw_function_ = b->throw_function_;
|
Chris@16
|
426 a->data_ = data;
|
Chris@16
|
427 }
|
Chris@16
|
428
|
Chris@16
|
429 inline
|
Chris@16
|
430 void
|
Chris@16
|
431 copy_boost_exception( void *, void const * )
|
Chris@16
|
432 {
|
Chris@16
|
433 }
|
Chris@16
|
434
|
Chris@16
|
435 template <class T>
|
Chris@16
|
436 class
|
Chris@16
|
437 clone_impl:
|
Chris@16
|
438 public T,
|
Chris@16
|
439 public virtual clone_base
|
Chris@16
|
440 {
|
Chris@16
|
441 struct clone_tag { };
|
Chris@16
|
442 clone_impl( clone_impl const & x, clone_tag ):
|
Chris@16
|
443 T(x)
|
Chris@16
|
444 {
|
Chris@16
|
445 copy_boost_exception(this,&x);
|
Chris@16
|
446 }
|
Chris@16
|
447
|
Chris@16
|
448 public:
|
Chris@16
|
449
|
Chris@16
|
450 explicit
|
Chris@16
|
451 clone_impl( T const & x ):
|
Chris@16
|
452 T(x)
|
Chris@16
|
453 {
|
Chris@16
|
454 copy_boost_exception(this,&x);
|
Chris@16
|
455 }
|
Chris@16
|
456
|
Chris@16
|
457 ~clone_impl() throw()
|
Chris@16
|
458 {
|
Chris@16
|
459 }
|
Chris@16
|
460
|
Chris@16
|
461 private:
|
Chris@16
|
462
|
Chris@16
|
463 clone_base const *
|
Chris@16
|
464 clone() const
|
Chris@16
|
465 {
|
Chris@16
|
466 return new clone_impl(*this,clone_tag());
|
Chris@16
|
467 }
|
Chris@16
|
468
|
Chris@16
|
469 void
|
Chris@16
|
470 rethrow() const
|
Chris@16
|
471 {
|
Chris@16
|
472 throw*this;
|
Chris@16
|
473 }
|
Chris@16
|
474 };
|
Chris@16
|
475 }
|
Chris@16
|
476
|
Chris@16
|
477 template <class T>
|
Chris@16
|
478 inline
|
Chris@16
|
479 exception_detail::clone_impl<T>
|
Chris@16
|
480 enable_current_exception( T const & x )
|
Chris@16
|
481 {
|
Chris@16
|
482 return exception_detail::clone_impl<T>(x);
|
Chris@16
|
483 }
|
Chris@16
|
484 }
|
Chris@16
|
485
|
Chris@16
|
486 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
487 #pragma warning(pop)
|
Chris@16
|
488 #endif
|
Chris@16
|
489 #endif
|