]> git.lyx.org Git - features.git/blob - boost/boost/exception/detail/type_info.hpp
boost: add eol property
[features.git] / boost / boost / exception / detail / type_info.hpp
1 //Copyright (c) 2006-2009 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_C3E1741C754311DDB2834CCA55D89593
7 #define UUID_C3E1741C754311DDB2834CCA55D89593
8
9 #include <boost/detail/sp_typeinfo.hpp>
10 #include <boost/current_function.hpp>
11
12 namespace
13 boost
14     {
15     template <class T>
16     inline
17     char const *
18     tag_type_name()
19         {
20 #ifdef BOOST_NO_TYPEID
21         return BOOST_CURRENT_FUNCTION;
22 #else
23         return typeid(T*).name();
24 #endif
25         }
26
27     template <class T>
28     inline
29     char const *
30     type_name()
31         {
32 #ifdef BOOST_NO_TYPEID
33         return BOOST_CURRENT_FUNCTION;
34 #else
35         return typeid(T).name();
36 #endif
37         }
38
39     namespace
40     exception_detail
41         {
42 #ifdef BOOST_NO_TYPEID
43         struct
44         type_info_
45             {
46             detail::sp_typeinfo type_;
47             char const * name_;
48
49             explicit
50             type_info_( detail::sp_typeinfo type, char const * name ):
51                 type_(type),
52                 name_(name)
53                 {
54                 }
55
56             friend
57             bool
58             operator==( type_info_ const & a, type_info_ const & b )
59                 {
60                 return a.type_==b.type_;
61                 }
62
63             friend
64             bool
65             operator<( type_info_ const & a, type_info_ const & b )
66                 {
67                 return a.type_<b.type_;
68                 }
69
70             char const *
71             name() const
72                 {
73                 return name_;
74                 }
75             };
76 #else
77         struct
78         type_info_
79             {
80             detail::sp_typeinfo const * type_;
81
82             explicit
83             type_info_( detail::sp_typeinfo const & type ):
84                 type_(&type)
85                 {
86                 }
87
88             type_info_( detail::sp_typeinfo const & type, char const * ):
89                 type_(&type)
90                 {
91                 }
92
93             friend
94             bool
95             operator==( type_info_ const & a, type_info_ const & b )
96                 {
97                 return (*a.type_)==(*b.type_);
98                 }
99
100             friend
101             bool
102             operator<( type_info_ const & a, type_info_ const & b )
103                 {
104                 return 0!=(a.type_->before(*b.type_));
105                 }
106
107             char const *
108             name() const
109                 {
110                 return type_->name();
111                 }
112             };
113 #endif
114
115         inline
116         bool
117         operator!=( type_info_ const & a, type_info_ const & b )
118             {
119             return !(a==b);
120             }
121         }
122     }
123
124 #define BOOST_EXCEPTION_STATIC_TYPEID(T) ::boost::exception_detail::type_info_(BOOST_SP_TYPEID(T),::boost::tag_type_name<T>())
125
126 #ifndef BOOST_NO_RTTI
127 #define BOOST_EXCEPTION_DYNAMIC_TYPEID(x) ::boost::exception_detail::type_info_(typeid(x))
128 #endif
129
130 #endif