VirtualBox

source: vbox/trunk/src/libs/boost-1.37.0/boost/exception/info.hpp@ 34049

Last change on this file since 34049 was 16204, checked in by vboxsync, 16 years ago

export the boost stuff required for Main

File size: 4.1 KB
Line 
1//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
2
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)
5
6#ifndef UUID_8D22C4CA9CC811DCAA9133D256D89593
7#define UUID_8D22C4CA9CC811DCAA9133D256D89593
8
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>
13#include <map>
14
15namespace
16boost
17 {
18 template <class Tag,class T>
19 inline
20 error_info<Tag,T>::
21 error_info( value_type const & value ):
22 value_(value)
23 {
24 }
25
26 template <class Tag,class T>
27 inline
28 error_info<Tag,T>::
29 ~error_info() throw()
30 {
31 }
32
33 template <class Tag,class T>
34 inline
35 char const *
36 error_info<Tag,T>::
37 tag_typeid_name() const
38 {
39 return tag_type_name<Tag>();
40 }
41
42 template <class Tag,class T>
43 inline
44 std::string
45 error_info<Tag,T>::
46 value_as_string() const
47 {
48 return to_string_stub(value_);
49 }
50
51 namespace
52 exception_detail
53 {
54 class
55 error_info_container_impl:
56 public error_info_container
57 {
58 public:
59
60 error_info_container_impl():
61 count_(0)
62 {
63 }
64
65 ~error_info_container_impl() throw()
66 {
67 }
68
69 void
70 set( shared_ptr<error_info_base const> const & x, type_info_ const & typeid_ )
71 {
72 BOOST_ASSERT(x);
73 info_[typeid_] = x;
74 diagnostic_info_str_.clear();
75 }
76
77 shared_ptr<error_info_base const>
78 get( type_info_ const & ti ) const
79 {
80 error_info_map::const_iterator i=info_.find(ti);
81 if( info_.end()!=i )
82 {
83 shared_ptr<error_info_base const> const & p = i->second;
84#ifndef BOOST_NO_RTTI
85 BOOST_ASSERT( BOOST_EXCEPTION_DYNAMIC_TYPEID(*p)==ti );
86#endif
87 return p;
88 }
89 return shared_ptr<error_info_base const>();
90 }
91
92 char const *
93 diagnostic_information() const
94 {
95 if( diagnostic_info_str_.empty() )
96 {
97 std::string tmp;
98 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
99 {
100 shared_ptr<error_info_base const> const & x = i->second;
101 tmp += '[';
102 tmp += x->tag_typeid_name();
103 tmp += "] = ";
104 tmp += x->value_as_string();
105 tmp += '\n';
106 }
107 diagnostic_info_str_.swap(tmp);
108 }
109 return diagnostic_info_str_.c_str();
110 }
111
112 private:
113
114 friend class boost::exception;
115
116 typedef std::map< type_info_, shared_ptr<error_info_base const> > error_info_map;
117 error_info_map info_;
118 mutable std::string diagnostic_info_str_;
119 mutable int count_;
120
121 void
122 add_ref() const
123 {
124 ++count_;
125 }
126
127 void
128 release() const
129 {
130 if( !--count_ )
131 delete this;
132 }
133 };
134 }
135
136 template <class E,class Tag,class T>
137 inline
138 E const &
139 operator<<( E const & x, error_info<Tag,T> const & v )
140 {
141 typedef error_info<Tag,T> error_info_tag_t;
142 shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
143 exception_detail::error_info_container * c;
144 if( !(c=x.data_.get()) )
145 x.data_.adopt(c=new exception_detail::error_info_container_impl);
146 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
147 return x;
148 }
149 }
150
151#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette