1 //Copyright (c) 2006-2010 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_8D22C4CA9CC811DCAA9133D256D89593
7 #define UUID_8D22C4CA9CC811DCAA9133D256D89593
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)
15 #include <boost/exception/exception.hpp>
16 #include <boost/exception/to_string_stub.hpp>
17 #include <boost/exception/detail/error_info_impl.hpp>
18 #include <boost/shared_ptr.hpp>
19 #include <boost/config.hpp>
25 template <class Tag,class T>
28 error_info_name( error_info<Tag,T> const & x )
30 return tag_type_name<Tag>();
33 template <class Tag,class T>
36 to_string( error_info<Tag,T> const & x )
38 return '[' + error_info_name(x) + "] = " + to_string_stub(x.value()) + '\n';
41 template <class Tag,class T>
44 error_info( value_type const & value ):
49 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
50 template <class Tag,class T>
53 error_info( error_info const & x ):
57 template <class Tag,class T>
60 error_info( value_type && value ) BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(value_type(std::move(value)))):
61 value_(std::move(value))
64 template <class Tag,class T>
67 error_info( error_info && x ) BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(value_type(std::move(x.value_)))):
68 value_(std::move(x.value_))
73 template <class Tag,class T>
80 template <class Tag,class T>
84 name_value_string() const
86 return to_string_stub(*this);
93 error_info_container_impl:
94 public error_info_container
98 error_info_container_impl():
103 ~error_info_container_impl() throw()
108 set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
112 diagnostic_info_str_.clear();
115 shared_ptr<error_info_base>
116 get( type_info_ const & ti ) const
118 error_info_map::const_iterator i=info_.find(ti);
121 shared_ptr<error_info_base> const & p = i->second;
122 #ifndef BOOST_NO_RTTI
123 BOOST_ASSERT( *BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==*ti.type_ );
127 return shared_ptr<error_info_base>();
131 diagnostic_information( char const * header ) const
135 std::ostringstream tmp;
137 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
139 error_info_base const & x = *i->second;
140 tmp << x.name_value_string();
142 tmp.str().swap(diagnostic_info_str_);
144 return diagnostic_info_str_.c_str();
149 friend class boost::exception;
151 typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
152 error_info_map info_;
153 mutable std::string diagnostic_info_str_;
156 error_info_container_impl( error_info_container_impl const & );
157 error_info_container_impl & operator=( error_info_container const & );
177 refcount_ptr<error_info_container>
180 refcount_ptr<error_info_container> p;
181 error_info_container_impl * c=new error_info_container_impl;
188 template <class E,class Tag,class T>
191 set_info( E const & x, error_info<Tag,T> const & v )
193 typedef error_info<Tag,T> error_info_tag_t;
194 shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
195 exception_detail::error_info_container * c=x.data_.get();
197 x.data_.adopt(c=new exception_detail::error_info_container_impl);
198 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
202 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
203 template <class E,class Tag,class T>
204 E const & set_info( E const &, error_info<Tag,T> && );
207 template <class Tag,class T>
209 set_info_rv<error_info<Tag,T> >
211 template <class E,class Tag1,class T1>
212 friend E const & set_info( E const &, error_info<Tag1,T1> && );
216 set( E const & x, error_info<Tag,T> && v )
218 typedef error_info<Tag,T> error_info_tag_t;
219 shared_ptr<error_info_tag_t> p( new error_info_tag_t(std::move(v)) );
220 exception_detail::error_info_container * c=x.data_.get();
222 x.data_.adopt(c=new exception_detail::error_info_container_impl);
223 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
229 set_info_rv<throw_function>
231 template <class E,class Tag1,class T1>
232 friend E const & set_info( E const &, error_info<Tag1,T1> && );
236 set( E const & x, throw_function && y )
238 x.throw_function_=y.v_;
244 set_info_rv<throw_file>
246 template <class E,class Tag1,class T1>
247 friend E const & set_info( E const &, error_info<Tag1,T1> && );
251 set( E const & x, throw_file && y )
259 set_info_rv<throw_line>
261 template <class E,class Tag1,class T1>
262 friend E const & set_info( E const &, error_info<Tag1,T1> && );
266 set( E const & x, throw_line && y )
272 template <class E,class Tag,class T>
275 set_info( E const & x, error_info<Tag,T> && v )
277 return set_info_rv<error_info<Tag,T> >::template set<E>(x,std::move(v));
283 derives_boost_exception
285 enum e { value = (sizeof(dispatch_boost_exception((T*)0))==sizeof(large_size)) };
289 template <class E,class Tag,class T>
291 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
292 operator<<( E const & x, error_info<Tag,T> const & v )
294 return exception_detail::set_info(x,v);
297 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
298 template <class E,class Tag,class T>
300 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
301 operator<<( E const & x, error_info<Tag,T> && v )
303 return exception_detail::set_info(x,std::move(v));
308 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)