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
9 #include <boost/config.hpp>
10 #include <boost/exception/exception.hpp>
11 #include <boost/exception/to_string_stub.hpp>
12 #include <boost/exception/detail/error_info_impl.hpp>
13 #include <boost/exception/detail/shared_ptr.hpp>
16 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
17 #pragma GCC system_header
19 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
20 #pragma warning(push,1)
26 template <class Tag,class T>
29 error_info_name( error_info<Tag,T> const & x )
31 return tag_type_name<Tag>();
34 template <class Tag,class T>
37 to_string( error_info<Tag,T> const & x )
39 return '[' + error_info_name(x) + "] = " + to_string_stub(x.value()) + '\n';
42 template <class Tag,class T>
46 name_value_string() const
48 return to_string_stub(*this);
55 error_info_container_impl:
56 public error_info_container
60 error_info_container_impl():
65 ~error_info_container_impl() throw()
70 set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
74 diagnostic_info_str_.clear();
77 shared_ptr<error_info_base>
78 get( type_info_ const & ti ) const
80 error_info_map::const_iterator i=info_.find(ti);
83 shared_ptr<error_info_base> const & p = i->second;
85 BOOST_ASSERT( *BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==*ti.type_ );
89 return shared_ptr<error_info_base>();
93 diagnostic_information( char const * header ) const
97 std::ostringstream tmp;
99 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
101 error_info_base const & x = *i->second;
102 tmp << x.name_value_string();
104 tmp.str().swap(diagnostic_info_str_);
106 return diagnostic_info_str_.c_str();
111 friend class boost::exception;
113 typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
114 error_info_map info_;
115 mutable std::string diagnostic_info_str_;
118 error_info_container_impl( error_info_container_impl const & );
119 error_info_container_impl & operator=( error_info_container const & );
139 refcount_ptr<error_info_container>
142 refcount_ptr<error_info_container> p;
143 error_info_container_impl * c=new error_info_container_impl;
145 for( error_info_map::const_iterator i=info_.begin(),e=info_.end(); i!=e; ++i )
147 shared_ptr<error_info_base> cp(i->second->clone());
148 c->info_.insert(std::make_pair(i->first,cp));
154 template <class E,class Tag,class T>
157 set_info( E const & x, error_info<Tag,T> const & v )
159 typedef error_info<Tag,T> error_info_tag_t;
160 shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
161 exception_detail::error_info_container * c=x.data_.get();
163 x.data_.adopt(c=new exception_detail::error_info_container_impl);
164 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
168 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
169 template <class E,class Tag,class T>
170 E const & set_info( E const &, error_info<Tag,T> && );
173 template <class Tag,class T>
175 set_info_rv<error_info<Tag,T> >
177 template <class E,class Tag1,class T1>
178 friend E const & set_info( E const &, error_info<Tag1,T1> && );
182 set( E const & x, error_info<Tag,T> && v )
184 typedef error_info<Tag,T> error_info_tag_t;
185 shared_ptr<error_info_tag_t> p( new error_info_tag_t(std::move(v)) );
186 exception_detail::error_info_container * c=x.data_.get();
188 x.data_.adopt(c=new exception_detail::error_info_container_impl);
189 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
195 set_info_rv<throw_function>
197 template <class E,class Tag1,class T1>
198 friend E const & set_info( E const &, error_info<Tag1,T1> && );
202 set( E const & x, throw_function && y )
204 x.throw_function_=y.v_;
210 set_info_rv<throw_file>
212 template <class E,class Tag1,class T1>
213 friend E const & set_info( E const &, error_info<Tag1,T1> && );
217 set( E const & x, throw_file && y )
225 set_info_rv<throw_line>
227 template <class E,class Tag1,class T1>
228 friend E const & set_info( E const &, error_info<Tag1,T1> && );
232 set( E const & x, throw_line && y )
238 template <class E,class Tag,class T>
241 set_info( E const & x, error_info<Tag,T> && v )
243 return set_info_rv<error_info<Tag,T> >::template set<E>(x,std::move(v));
249 derives_boost_exception
251 enum e { value = (sizeof(dispatch_boost_exception((T*)0))==sizeof(large_size)) };
255 template <class E,class Tag,class T>
257 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
258 operator<<( E const & x, error_info<Tag,T> const & v )
260 return exception_detail::set_info(x,v);
263 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
264 template <class E,class Tag,class T>
266 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
267 operator<<( E const & x, error_info<Tag,T> && v )
269 return exception_detail::set_info(x,std::move(v));
274 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)