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> const & x
, type_info_
const & typeid_
)
82 diagnostic_info_str_
.clear();
85 shared_ptr
<error_info_base
const>
86 get( type_info_
const & ti
) const
88 error_info_map::const_iterator i
=info_
.find(ti
);
91 shared_ptr
<error_info_base
const> const & p
= i
->second
;
93 BOOST_ASSERT( BOOST_EXCEPTION_DYNAMIC_TYPEID(*p
)==ti
);
97 return shared_ptr
<error_info_base
const>();
101 diagnostic_information() const
103 if( diagnostic_info_str_
.empty() )
105 std::ostringstream tmp
;
106 for( error_info_map::const_iterator i
=info_
.begin(),end
=info_
.end(); i
!=end
; ++i
)
108 shared_ptr
<error_info_base
const> const & x
= i
->second
;
109 tmp
<< '[' << x
->tag_typeid_name() << "] = " << x
->value_as_string() << '\n';
111 tmp
.str().swap(diagnostic_info_str_
);
113 return diagnostic_info_str_
.c_str();
118 friend class boost::exception
;
120 typedef std::map
< type_info_
, shared_ptr
<error_info_base
const> > error_info_map
;
121 error_info_map info_
;
122 mutable std::string diagnostic_info_str_
;
140 template <class E
,class Tag
,class T
>
143 operator<<( E
const & x
, error_info
<Tag
,T
> const & v
)
145 typedef error_info
<Tag
,T
> error_info_tag_t
;
146 shared_ptr
<error_info_tag_t
> p( new error_info_tag_t(v
) );
147 exception_detail::error_info_container
* c
;
148 if( !(c
=x
.data_
.get()) )
149 x
.data_
.adopt(c
=new exception_detail::error_info_container_impl
);
150 c
->set(p
,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t
));