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 defined(__GNUC__) && !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>
27 typename enable_if<has_to_string<T>,std::string>::type
28 to_string( error_info<Tag,T> const & x )
30 return to_string(x.value());
33 template <class Tag,class T>
36 error_info( value_type const & value ):
41 template <class Tag,class T>
48 template <class Tag,class T>
52 tag_typeid_name() const
54 return tag_type_name<Tag>();
57 template <class Tag,class T>
61 value_as_string() const
63 return to_string_stub(*this);
70 error_info_container_impl:
71 public error_info_container
75 error_info_container_impl():
80 ~error_info_container_impl() throw()
85 set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
89 diagnostic_info_str_.clear();
92 shared_ptr<error_info_base>
93 get( type_info_ const & ti ) const
95 error_info_map::const_iterator i=info_.find(ti);
98 shared_ptr<error_info_base> const & p = i->second;
100 BOOST_ASSERT( BOOST_EXCEPTION_DYNAMIC_TYPEID(*p).type_==ti.type_ );
104 return shared_ptr<error_info_base>();
108 diagnostic_information( char const * header ) const
112 BOOST_ASSERT(*header!=0);
113 std::ostringstream tmp;
115 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
117 error_info_base const & x = *i->second;
118 tmp << '[' << x.tag_typeid_name() << "] = " << x.value_as_string() << '\n';
120 tmp.str().swap(diagnostic_info_str_);
122 return diagnostic_info_str_.c_str();
127 friend class boost::exception;
129 typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
130 error_info_map info_;
131 mutable std::string diagnostic_info_str_;
134 error_info_container_impl( error_info_container_impl const & );
135 error_info_container_impl & operator=( error_info_container const & );
155 refcount_ptr<error_info_container>
158 refcount_ptr<error_info_container> p;
159 error_info_container_impl * c=new error_info_container_impl;
166 template <class E,class Tag,class T>
169 set_info( E const & x, error_info<Tag,T> const & v )
171 typedef error_info<Tag,T> error_info_tag_t;
172 shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
173 exception_detail::error_info_container * c=x.data_.get();
175 x.data_.adopt(c=new exception_detail::error_info_container_impl);
176 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
182 derives_boost_exception
184 enum e { value = (sizeof(dispatch_boost_exception((T*)0))==sizeof(large_size)) };
188 template <class E,class Tag,class T>
190 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
191 operator<<( E const & x, error_info<Tag,T> const & v )
193 return exception_detail::set_info(x,v);
197 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)