1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
\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
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
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
\r
12 #pragma warning(push,1)
\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
25 template <class Tag,class T>
\r
27 typename enable_if<has_to_string<T>,std::string>::type
\r
28 to_string( error_info<Tag,T> const & x )
\r
30 return to_string(x.value());
\r
33 template <class Tag,class T>
\r
36 error_info( value_type const & value ):
\r
41 template <class Tag,class T>
\r
44 ~error_info() throw()
\r
48 template <class Tag,class T>
\r
52 tag_typeid_name() const
\r
54 return tag_type_name<Tag>();
\r
57 template <class Tag,class T>
\r
61 value_as_string() const
\r
63 return to_string_stub(*this);
\r
70 error_info_container_impl:
\r
71 public error_info_container
\r
75 error_info_container_impl():
\r
80 ~error_info_container_impl() throw()
\r
85 set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
\r
89 diagnostic_info_str_.clear();
\r
92 shared_ptr<error_info_base>
\r
93 get( type_info_ const & ti ) const
\r
95 error_info_map::const_iterator i=info_.find(ti);
\r
96 if( info_.end()!=i )
\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
104 return shared_ptr<error_info_base>();
\r
108 diagnostic_information( char const * header ) const
\r
112 BOOST_ASSERT(*header!=0);
\r
113 std::ostringstream tmp;
\r
115 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
\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
120 tmp.str().swap(diagnostic_info_str_);
\r
122 return diagnostic_info_str_.c_str();
\r
127 friend class boost::exception;
\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
149 template <class E,class Tag,class T>
\r
152 operator<<( E const & x, error_info<Tag,T> const & v )
\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
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
164 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
\r
165 #pragma warning(pop)
\r