1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
\r
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
\r
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
\r
6 #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
\r
7 #define UUID_274DA366004E11DCB1DDFE2E56D89593
\r
8 #if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
\r
9 #pragma GCC system_header
\r
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
\r
12 #pragma warning(push,1)
\r
37 refcount_ptr( refcount_ptr const & x ):
\r
44 operator=( refcount_ptr const & x )
\r
78 if( px_ && px_->release() )
\r
84 ////////////////////////////////////////////////////////////////////////
\r
86 template <class Tag,class T>
\r
89 typedef error_info<struct throw_function_,char const *> throw_function;
\r
90 typedef error_info<struct throw_file_,char const *> throw_file;
\r
91 typedef error_info<struct throw_line_,int> throw_line;
\r
95 error_info<throw_function_,char const *>
\r
98 typedef char const * value_type;
\r
101 error_info( value_type v ):
\r
109 error_info<throw_file_,char const *>
\r
112 typedef char const * value_type;
\r
115 error_info( value_type v ):
\r
123 error_info<throw_line_,int>
\r
126 typedef int value_type;
\r
129 error_info( value_type v ):
\r
135 #if defined(__GNUC__)
\r
136 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
\r
137 # pragma GCC visibility push (default)
\r
141 #if defined(__GNUC__)
\r
142 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
\r
143 # pragma GCC visibility pop
\r
153 class error_info_base;
\r
157 error_info_container
\r
159 virtual char const * diagnostic_information( char const * ) const = 0;
\r
160 virtual shared_ptr<error_info_base> get( type_info_ const & ) const = 0;
\r
161 virtual void set( shared_ptr<error_info_base> const &, type_info_ const & ) = 0;
\r
162 virtual void add_ref() const = 0;
\r
163 virtual bool release() const = 0;
\r
164 virtual refcount_ptr<exception_detail::error_info_container> clone() const = 0;
\r
168 ~error_info_container() throw()
\r
177 struct get_info<throw_function>;
\r
180 struct get_info<throw_file>;
\r
183 struct get_info<throw_line>;
\r
185 char const * get_diagnostic_information( exception const &, char const * );
\r
187 void copy_boost_exception( exception *, exception const * );
\r
189 template <class E,class Tag,class T>
\r
190 E const & set_info( E const &, error_info<Tag,T> const & );
\r
193 E const & set_info( E const &, throw_function const & );
\r
196 E const & set_info( E const &, throw_file const & );
\r
199 E const & set_info( E const &, throw_line const & );
\r
202 #if defined(__GNUC__)
\r
203 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
\r
204 # pragma GCC visibility push (default)
\r
213 throw_function_(0),
\r
220 //On HP aCC, this protected copy constructor prevents throwing boost::exception.
\r
221 //On all other platforms, the same effect is achieved by the pure virtual destructor.
\r
222 exception( exception const & x ) throw():
\r
224 throw_function_(x.throw_function_),
\r
225 throw_file_(x.throw_file_),
\r
226 throw_line_(x.throw_line_)
\r
231 virtual ~exception() throw()
\r
233 = 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
\r
237 #if (defined(__MWERKS__) && __MWERKS__<=0x3207) || (defined(_MSC_VER) && _MSC_VER<=1310)
\r
243 friend E const & exception_detail::set_info( E const &, throw_function const & );
\r
246 friend E const & exception_detail::set_info( E const &, throw_file const & );
\r
249 friend E const & exception_detail::set_info( E const &, throw_line const & );
\r
251 template <class E,class Tag,class T>
\r
252 friend E const & exception_detail::set_info( E const &, error_info<Tag,T> const & );
\r
254 friend char const * exception_detail::get_diagnostic_information( exception const &, char const * );
\r
257 friend struct exception_detail::get_info;
\r
258 friend struct exception_detail::get_info<throw_function>;
\r
259 friend struct exception_detail::get_info<throw_file>;
\r
260 friend struct exception_detail::get_info<throw_line>;
\r
261 friend void exception_detail::copy_boost_exception( exception *, exception const * );
\r
263 mutable exception_detail::refcount_ptr<exception_detail::error_info_container> data_;
\r
264 mutable char const * throw_function_;
\r
265 mutable char const * throw_file_;
\r
266 mutable int throw_line_;
\r
268 #if defined(__GNUC__)
\r
269 # if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
\r
270 # pragma GCC visibility pop
\r
276 ~exception() throw()
\r
285 set_info( E const & x, throw_function const & y )
\r
287 x.throw_function_=y.v_;
\r
293 set_info( E const & x, throw_file const & y )
\r
295 x.throw_file_=y.v_;
\r
301 set_info( E const & x, throw_line const & y )
\r
303 x.throw_line_=y.v_;
\r
308 ////////////////////////////////////////////////////////////////////////
\r
315 error_info_injector:
\r
320 error_info_injector( T const & x ):
\r
325 ~error_info_injector() throw()
\r
330 struct large_size { char c[256]; };
\r
331 large_size dispatch_boost_exception( exception const * );
\r
333 struct small_size { };
\r
334 small_size dispatch_boost_exception( void const * );
\r
336 template <class,int>
\r
337 struct enable_error_info_helper;
\r
341 enable_error_info_helper<T,sizeof(large_size)>
\r
348 enable_error_info_helper<T,sizeof(small_size)>
\r
350 typedef error_info_injector<T> type;
\r
355 enable_error_info_return_type
\r
357 typedef typename enable_error_info_helper<T,sizeof(exception_detail::dispatch_boost_exception(static_cast<T *>(0)))>::type type;
\r
364 exception_detail::enable_error_info_return_type<T>::type
\r
365 enable_error_info( T const & x )
\r
367 typedef typename exception_detail::enable_error_info_return_type<T>::type rt;
\r
371 ////////////////////////////////////////////////////////////////////////
\r
381 virtual clone_base const * clone() const = 0;
\r
382 virtual void rethrow() const = 0;
\r
385 ~clone_base() throw()
\r
392 copy_boost_exception( exception * a, exception const * b )
\r
394 refcount_ptr<error_info_container> data;
\r
395 if( error_info_container * d=b->data_.get() )
\r
397 a->throw_file_ = b->throw_file_;
\r
398 a->throw_line_ = b->throw_line_;
\r
399 a->throw_function_ = b->throw_function_;
\r
405 copy_boost_exception( void *, void const * )
\r
418 clone_impl( T const & x ):
\r
421 copy_boost_exception(this,&x);
\r
424 ~clone_impl() throw()
\r
433 return new clone_impl(*this);
\r
446 exception_detail::clone_impl<T>
\r
447 enable_current_exception( T const & x )
\r
449 return exception_detail::clone_impl<T>(x);
\r
453 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
\r
454 #pragma warning(pop)
\r