]> git.lyx.org Git - lyx.git/blob - boost/boost/exception/exception.hpp
update boost to version 1.36
[lyx.git] / boost / boost / exception / exception.hpp
1 //Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
2
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)
5
6 #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593
7 #define UUID_274DA366004E11DCB1DDFE2E56D89593
8
9 #include <boost/config.hpp>
10 #include <boost/detail/workaround.hpp>
11 #include <boost/exception/detail/counted_base.hpp>
12 #include <boost/intrusive_ptr.hpp>
13 #include <typeinfo>
14
15 namespace
16 boost
17     {
18     template <class T>
19     class shared_ptr;
20
21     namespace
22     exception_detail
23         {
24         class error_info_base;
25
26         struct
27         error_info_container:
28             public exception_detail::counted_base
29             {
30             virtual char const * diagnostic_information( char const *, std::type_info const & ) const = 0;
31             virtual shared_ptr<error_info_base const> get( std::type_info const & ) const = 0;
32             virtual void set( shared_ptr<error_info_base const> const & ) = 0;
33             };
34         }
35
36     template <class Tag,class T>
37     class error_info;
38
39     template <class E,class Tag,class T>
40     E const & operator<<( E const &, error_info<Tag,T> const & );
41
42     template <class ErrorInfo,class E>
43     shared_ptr<typename ErrorInfo::value_type const> get_error_info( E const & );
44
45     class
46     exception
47         {
48         public:
49
50         virtual
51         char const *
52         diagnostic_information() const throw()
53             {
54             return _diagnostic_information(0);
55             }
56
57         protected:
58
59         exception()
60             {
61             }
62
63         exception( exception const & e ):
64             data_(e.data_)
65             {
66             }
67
68         char const *
69         _diagnostic_information( char const * std_what ) const throw()
70             {
71             if( data_ )
72                 try
73                     {
74                     char const * w = data_->diagnostic_information(std_what,typeid(*this));
75                     BOOST_ASSERT(0!=w);
76                     return w;
77                     }
78                 catch(...)
79                     {
80                     }
81             return std_what ? std_what : typeid(*this).name();
82             }
83
84 #if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) )
85         //Force class exception to be abstract.
86         //Otherwise, MSVC bug allows throw exception(), even though the copy constructor is protected.
87         virtual ~exception() throw()=0;
88 #else
89 #if BOOST_WORKAROUND( __GNUC__, BOOST_TESTED_AT(4) )
90         virtual //Disable bogus GCC warning.
91 #endif
92         ~exception() throw()
93             {
94             }
95 #endif
96
97         private:
98
99         shared_ptr<exception_detail::error_info_base const> get( std::type_info const & ) const;
100         void set( shared_ptr<exception_detail::error_info_base const> const & ) const;
101
102         template <class E,class Tag,class T>
103         friend E const & operator<<( E const &, error_info<Tag,T> const & );
104
105         template <class ErrorInfo,class E>
106         friend shared_ptr<typename ErrorInfo::value_type const> get_error_info( E const & );
107
108         intrusive_ptr<exception_detail::error_info_container> mutable data_;
109         };
110
111 #if BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1500) ) //See above.
112     inline
113     exception::
114     ~exception() throw()
115         {
116         }
117 #endif
118     }
119
120 #endif