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 BOOST_EXCEPTION_8D22C4CA9CC811DCAA9133D256D89593
7 #define BOOST_EXCEPTION_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 #ifndef BOOST_EXCEPTION_ENABLE_WARNINGS
17 #if __GNUC__*100+__GNUC_MINOR__>301
18 #pragma GCC system_header
21 #pragma clang system_header
24 #pragma warning(push,1)
31 template <class Tag,class T>
34 error_info_name( error_info<Tag,T> const & )
36 return tag_type_name<Tag>();
39 template <class Tag,class T>
42 to_string( error_info<Tag,T> const & x )
44 return '[' + error_info_name(x) + "] = " + to_string_stub(x.value()) + '\n';
47 template <class Tag,class T>
51 name_value_string() const
53 return to_string_stub(*this);
60 error_info_container_impl BOOST_FINAL:
61 public error_info_container
65 error_info_container_impl():
70 ~error_info_container_impl() BOOST_NOEXCEPT_OR_NOTHROW
75 set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
79 diagnostic_info_str_.clear();
82 shared_ptr<error_info_base>
83 get( type_info_ const & ti ) const
85 error_info_map::const_iterator i=info_.find(ti);
88 shared_ptr<error_info_base> const & p = i->second;
91 return shared_ptr<error_info_base>();
95 diagnostic_information( char const * header ) const
99 std::ostringstream tmp;
101 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
103 error_info_base const & x = *i->second;
104 tmp << x.name_value_string();
106 tmp.str().swap(diagnostic_info_str_);
108 return diagnostic_info_str_.c_str();
113 friend class boost::exception;
115 typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
116 error_info_map info_;
117 mutable std::string diagnostic_info_str_;
120 error_info_container_impl( error_info_container_impl const & );
121 error_info_container_impl & operator=( error_info_container const & );
141 refcount_ptr<error_info_container>
144 refcount_ptr<error_info_container> p;
145 error_info_container_impl * c=new error_info_container_impl;
147 for( error_info_map::const_iterator i=info_.begin(),e=info_.end(); i!=e; ++i )
149 shared_ptr<error_info_base> cp(i->second->clone());
150 c->info_.insert(std::make_pair(i->first,cp));
156 template <class E,class Tag,class T>
159 set_info( E const & x, error_info<Tag,T> const & v )
161 typedef error_info<Tag,T> error_info_tag_t;
162 shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
163 exception_detail::error_info_container * c=x.data_.get();
165 x.data_.adopt(c=new exception_detail::error_info_container_impl);
166 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
170 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
171 template <class E,class Tag,class T>
172 E const & set_info( E const &, error_info<Tag,T> && );
175 template <class Tag,class T>
177 set_info_rv<error_info<Tag,T> >
179 template <class E,class Tag1,class T1>
180 friend E const & set_info( E const &, error_info<Tag1,T1> && );
184 set( E const & x, error_info<Tag,T> && v )
186 typedef error_info<Tag,T> error_info_tag_t;
187 shared_ptr<error_info_tag_t> p( new error_info_tag_t(std::move(v)) );
188 exception_detail::error_info_container * c=x.data_.get();
190 x.data_.adopt(c=new exception_detail::error_info_container_impl);
191 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
197 set_info_rv<throw_function>
199 template <class E,class Tag1,class T1>
200 friend E const & set_info( E const &, error_info<Tag1,T1> && );
204 set( E const & x, throw_function && y )
206 x.throw_function_=y.v_;
212 set_info_rv<throw_file>
214 template <class E,class Tag1,class T1>
215 friend E const & set_info( E const &, error_info<Tag1,T1> && );
219 set( E const & x, throw_file && y )
227 set_info_rv<throw_line>
229 template <class E,class Tag1,class T1>
230 friend E const & set_info( E const &, error_info<Tag1,T1> && );
234 set( E const & x, throw_line && y )
240 template <class E,class Tag,class T>
243 set_info( E const & x, error_info<Tag,T> && v )
245 return set_info_rv<error_info<Tag,T> >::template set<E>(x,std::move(v));
251 derives_boost_exception
253 enum e { value = (sizeof(dispatch_boost_exception((T*)0))==sizeof(large_size)) };
257 template <class E,class Tag,class T>
259 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
260 operator<<( E const & x, error_info<Tag,T> const & v )
262 return exception_detail::set_info(x,v);
265 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
266 template <class E,class Tag,class T>
268 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
269 operator<<( E const & x, error_info<Tag,T> && v )
271 return exception_detail::set_info(x,std::move(v));
276 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)