1 //Copyright (c) 2006-2009 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/exception/exception.hpp>
10 #include <boost/exception/to_string_stub.hpp>
11 #include <boost/exception/detail/error_info_impl.hpp>
12 #include <boost/shared_ptr.hpp>
18 template <class Tag,class T>
20 typename enable_if<has_to_string<T>,std::string>::type
21 to_string( error_info<Tag,T> const & x )
23 return to_string(x.value());
26 template <class Tag,class T>
29 error_info( value_type const & value ):
34 template <class Tag,class T>
41 template <class Tag,class T>
45 tag_typeid_name() const
47 return tag_type_name<Tag>();
50 template <class Tag,class T>
54 value_as_string() const
56 return to_string_stub(*this);
63 error_info_container_impl:
64 public error_info_container
68 error_info_container_impl():
73 ~error_info_container_impl() throw()
78 set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
82 diagnostic_info_str_.clear();
85 shared_ptr<error_info_base>
86 get( type_info_ const & ti ) const
88 error_info_map::const_iterator i=info_.find(ti);
91 shared_ptr<error_info_base> const & p = i->second;
93 BOOST_ASSERT( BOOST_EXCEPTION_DYNAMIC_TYPEID(*p)==ti );
97 return shared_ptr<error_info_base>();
101 diagnostic_information( char const * header ) const
105 BOOST_ASSERT(*header!=0);
106 std::ostringstream tmp;
108 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
110 shared_ptr<error_info_base const> const & x = i->second;
111 tmp << '[' << x->tag_typeid_name() << "] = " << x->value_as_string() << '\n';
113 tmp.str().swap(diagnostic_info_str_);
115 return diagnostic_info_str_.c_str();
120 friend class boost::exception;
122 typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
123 error_info_map info_;
124 mutable std::string diagnostic_info_str_;
142 template <class E,class Tag,class T>
145 operator<<( E const & x, error_info<Tag,T> const & v )
147 typedef error_info<Tag,T> error_info_tag_t;
148 shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
149 exception_detail::error_info_container * c;
150 if( !(c=x.data_.get()) )
151 x.data_.adopt(c=new exception_detail::error_info_container_impl);
152 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));