]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/exception/info.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
9a9408fb2affed8b3044a3e294a420f1345b247c
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / exception / info.hpp
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.\r
2 \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
5 \r
6 #ifndef UUID_8D22C4CA9CC811DCAA9133D256D89593\r
7 #define UUID_8D22C4CA9CC811DCAA9133D256D89593\r
8 #if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)\r
9 #pragma GCC system_header\r
10 #endif\r
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)\r
12 #pragma warning(push,1)\r
13 #endif\r
14 \r
15 #include <boost/exception/exception.hpp>\r
16 #include <boost/exception/to_string_stub.hpp>\r
17 #include <boost/exception/detail/error_info_impl.hpp>\r
18 #include <boost/shared_ptr.hpp>\r
19 #include <boost/config.hpp>\r
20 #include <map>\r
21 \r
22 namespace\r
23 boost\r
24     {\r
25     template <class Tag,class T>\r
26     inline\r
27     typename enable_if<has_to_string<T>,std::string>::type\r
28     to_string( error_info<Tag,T> const & x )\r
29         {\r
30         return to_string(x.value());\r
31         }\r
32 \r
33     template <class Tag,class T>\r
34     inline\r
35     error_info<Tag,T>::\r
36     error_info( value_type const & value ):\r
37         value_(value)\r
38         {\r
39         }\r
40 \r
41     template <class Tag,class T>\r
42     inline\r
43     error_info<Tag,T>::\r
44     ~error_info() throw()\r
45         {\r
46         }\r
47 \r
48     template <class Tag,class T>\r
49     inline\r
50     char const *\r
51     error_info<Tag,T>::\r
52     tag_typeid_name() const\r
53         {\r
54         return tag_type_name<Tag>();\r
55         }\r
56 \r
57     template <class Tag,class T>\r
58     inline\r
59     std::string\r
60     error_info<Tag,T>::\r
61     value_as_string() const\r
62         {\r
63         return to_string_stub(*this);\r
64         }\r
65 \r
66     namespace\r
67     exception_detail\r
68         {\r
69         class\r
70         error_info_container_impl:\r
71             public error_info_container\r
72             {\r
73             public:\r
74 \r
75             error_info_container_impl():\r
76                 count_(0)\r
77                 {\r
78                 }\r
79 \r
80             ~error_info_container_impl() throw()\r
81                 {\r
82                 }\r
83 \r
84             void\r
85             set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )\r
86                 {\r
87                 BOOST_ASSERT(x);\r
88                 info_[typeid_] = x;\r
89                 diagnostic_info_str_.clear();\r
90                 }\r
91 \r
92             shared_ptr<error_info_base>\r
93             get( type_info_ const & ti ) const\r
94                 {\r
95                 error_info_map::const_iterator i=info_.find(ti);\r
96                 if( info_.end()!=i )\r
97                     {\r
98                     shared_ptr<error_info_base> const & p = i->second;\r
99 #ifndef BOOST_NO_RTTI\r
100                     BOOST_ASSERT( BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==ti.type_ );\r
101 #endif\r
102                     return p;\r
103                     }\r
104                 return shared_ptr<error_info_base>();\r
105                 }\r
106 \r
107             char const *\r
108             diagnostic_information( char const * header ) const\r
109                 {\r
110                 if( header )\r
111                     {\r
112                     BOOST_ASSERT(*header!=0);\r
113                     std::ostringstream tmp;\r
114                     tmp << header;\r
115                     for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )\r
116                         {\r
117                         shared_ptr<error_info_base const> const & x = i->second;\r
118                         tmp << '[' << x->tag_typeid_name() << "] = " << x->value_as_string() << '\n';\r
119                         }\r
120                     tmp.str().swap(diagnostic_info_str_);\r
121                     }\r
122                 return diagnostic_info_str_.c_str();\r
123                 }\r
124 \r
125             private:\r
126 \r
127             friend class boost::exception;\r
128 \r
129             typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;\r
130             error_info_map info_;\r
131             mutable std::string diagnostic_info_str_;\r
132             mutable int count_;\r
133 \r
134             void\r
135             add_ref() const\r
136                 {\r
137                 ++count_;\r
138                 }\r
139 \r
140             void\r
141             release() const\r
142                 {\r
143                 if( !--count_ )\r
144                     delete this;\r
145                 }\r
146             };\r
147         }\r
148 \r
149     template <class E,class Tag,class T>\r
150     inline\r
151     E const &\r
152     operator<<( E const & x, error_info<Tag,T> const & v )\r
153         {\r
154         typedef error_info<Tag,T> error_info_tag_t;\r
155         shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );\r
156         exception_detail::error_info_container * c=x.data_.get();\r
157         if( !c )\r
158             x.data_.adopt(c=new exception_detail::error_info_container_impl);\r
159         c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));\r
160         return x;\r
161         }\r
162     }\r
163 \r
164 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)\r
165 #pragma warning(pop)\r
166 #endif\r
167 #endif\r