1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
7 #define UUID_274DA366004E11DCB1DDFE2E56D89593
8 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
9 #pragma GCC system_header
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
12 #pragma warning(push,1)
37 refcount_ptr( refcount_ptr const & x ):
44 operator=( refcount_ptr const & x )
78 if( px_ && px_->release() )
84 ////////////////////////////////////////////////////////////////////////
86 template <class Tag,class T>
89 typedef error_info<struct throw_function_,char const *> throw_function;
90 typedef error_info<struct throw_file_,char const *> throw_file;
91 typedef error_info<struct throw_line_,int> throw_line;
95 error_info<throw_function_,char const *>
98 typedef char const * value_type;
101 error_info( value_type v ):
109 error_info<throw_file_,char const *>
112 typedef char const * value_type;
115 error_info( value_type v ):
123 error_info<throw_line_,int>
126 typedef int value_type;
129 error_info( value_type v ):
135 #if defined(__GNUC__)
136 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
137 # pragma GCC visibility push (default)
141 #if defined(__GNUC__)
142 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
143 # pragma GCC visibility pop
153 class error_info_base;
159 virtual char const * diagnostic_information( char const * ) const = 0;
160 virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
161 virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
162 virtual void add_ref() const = 0;
163 virtual bool release() const = 0;
164 virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
168 ~error_info_container() throw()
177 struct get_info<throw_function>;
180 struct get_info<throw_file>;
183 struct get_info<throw_line>;
189 struct set_info_rv<throw_function>;
192 struct set_info_rv<throw_file>;
195 struct set_info_rv<throw_line>;
197 char const * get_diagnostic_information( exception const &, char const * );
199 void copy_boost_exception( exception *, exception const * );
201 template <class E,class Tag,class T>
202 E const & set_info( E const &, error_info<Tag,T> const & );
205 E const & set_info( E const &, throw_function const & );
208 E const & set_info( E const &, throw_file const & );
211 E const & set_info( E const &, throw_line const & );
214 #if defined(__GNUC__)
215 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
216 # pragma GCC visibility push (default)
224 template <class Tag> void set( typename Tag::type const & );
225 template <class Tag> typename Tag::type const * get() const;
238 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
239 //On all other platforms, the same effect is achieved by the pure virtual destructor.
240 exception( exception const & x ) throw():
242 throw_function_(x.throw_function_),
243 throw_file_(x.throw_file_),
244 throw_line_(x.throw_line_)
249 virtual ~exception() throw()
251 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
255 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
261 friend E const & exception_detail::set_info( E const &, throw_function const & );
264 friend E const & exception_detail::set_info( E const &, throw_file const & );
267 friend E const & exception_detail::set_info( E const &, throw_line const & );
269 template <class E,class Tag,class T>
270 friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
272 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
275 friend struct exception_detail::get_info;
276 friend struct exception_detail::get_info<throw_function>;
277 friend struct exception_detail::get_info<throw_file>;
278 friend struct exception_detail::get_info<throw_line>;
280 friend struct exception_detail::set_info_rv;
281 friend struct exception_detail::set_info_rv<throw_function>;
282 friend struct exception_detail::set_info_rv<throw_file>;
283 friend struct exception_detail::set_info_rv<throw_line>;
284 friend void exception_detail::copy_boost_exception( exception *, exception const * );
286 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
287 mutable char const * throw_function_;
288 mutable char const * throw_file_;
289 mutable int throw_line_;
291 #if defined(__GNUC__)
292 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
293 # pragma GCC visibility pop
308 set_info( E const & x, throw_function const & y )
310 x.throw_function_=y.v_;
316 set_info( E const & x, throw_file const & y )
324 set_info( E const & x, throw_line const & y )
331 ////////////////////////////////////////////////////////////////////////
336 #if defined(__GNUC__)
337 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
338 # pragma GCC visibility push (default)
348 error_info_injector( T const & x ):
353 ~error_info_injector() throw()
357 #if defined(__GNUC__)
358 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
359 # pragma GCC visibility pop
363 struct large_size { char c[256]; };
364 large_size dispatch_boost_exception( exception const * );
366 struct small_size { };
367 small_size dispatch_boost_exception( void const * );
370 struct enable_error_info_helper;
374 enable_error_info_helper<T,sizeof(large_size)>
381 enable_error_info_helper<T,sizeof(small_size)>
383 typedef error_info_injector<T> type;
388 enable_error_info_return_type
390 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
397 exception_detail::enable_error_info_return_type<T>::type
398 enable_error_info( T const & x )
400 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
404 ////////////////////////////////////////////////////////////////////////
409 #if defined(__GNUC__)
410 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
411 # pragma GCC visibility push (default)
419 virtual clone_base const * clone() const = 0;
420 virtual void rethrow() const = 0;
423 ~clone_base() throw()
427 #if defined(__GNUC__)
428 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
429 # pragma GCC visibility pop
435 copy_boost_exception( exception * a, exception const * b )
437 refcount_ptr<error_info_container> data;
438 if( error_info_container * d=b->data_.get() )
440 a->throw_file_ = b->throw_file_;
441 a->throw_line_ = b->throw_line_;
442 a->throw_function_ = b->throw_function_;
448 copy_boost_exception( void *, void const * )
452 #if defined(__GNUC__)
453 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
454 # pragma GCC visibility push (default)
461 public virtual clone_base
463 struct clone_tag { };
464 clone_impl( clone_impl const & x, clone_tag ):
467 copy_boost_exception(this,&x);
473 clone_impl( T const & x ):
476 copy_boost_exception(this,&x);
479 ~clone_impl() throw()
488 return new clone_impl(*this,clone_tag());
498 #if defined(__GNUC__)
499 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
500 # pragma GCC visibility pop
506 exception_detail::clone_impl<T>
507 enable_current_exception( T const & x )
509 return exception_detail::clone_impl<T>(x);
513 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)