File indexing completed on 2025-01-18 09:30:47
0001
0002
0003
0004
0005
0006 #ifndef BOOST_EXCEPTION_8D22C4CA9CC811DCAA9133D256D89593
0007 #define BOOST_EXCEPTION_8D22C4CA9CC811DCAA9133D256D89593
0008
0009 #include <boost/config.hpp>
0010 #include <boost/exception/exception.hpp>
0011 #include <boost/exception/to_string_stub.hpp>
0012 #include <boost/exception/detail/error_info_impl.hpp>
0013 #include <boost/exception/detail/shared_ptr.hpp>
0014 #include <map>
0015
0016 #ifndef BOOST_EXCEPTION_ENABLE_WARNINGS
0017 #if __GNUC__*100+__GNUC_MINOR__>301
0018 #pragma GCC system_header
0019 #endif
0020 #ifdef __clang__
0021 #pragma clang system_header
0022 #endif
0023 #ifdef _MSC_VER
0024 #pragma warning(push,1)
0025 #endif
0026 #endif
0027
0028 namespace
0029 boost
0030 {
0031 template <class Tag,class T>
0032 inline
0033 std::string
0034 error_info_name( error_info<Tag,T> const & )
0035 {
0036 return tag_type_name<Tag>();
0037 }
0038
0039 template <class Tag,class T>
0040 inline
0041 std::string
0042 to_string( error_info<Tag,T> const & x )
0043 {
0044 return '[' + error_info_name(x) + "] = " + to_string_stub(x.value()) + '\n';
0045 }
0046
0047 template <class Tag,class T>
0048 inline
0049 std::string
0050 error_info<Tag,T>::
0051 name_value_string() const
0052 {
0053 return to_string_stub(*this);
0054 }
0055
0056 namespace
0057 exception_detail
0058 {
0059 class
0060 error_info_container_impl BOOST_FINAL:
0061 public error_info_container
0062 {
0063 public:
0064
0065 error_info_container_impl():
0066 count_(0)
0067 {
0068 }
0069
0070 ~error_info_container_impl() BOOST_NOEXCEPT_OR_NOTHROW
0071 {
0072 }
0073
0074 void
0075 set( shared_ptr<error_info_base> const & x, type_info_ const & typeid_ )
0076 {
0077 BOOST_ASSERT(x);
0078 info_[typeid_] = x;
0079 diagnostic_info_str_.clear();
0080 }
0081
0082 shared_ptr<error_info_base>
0083 get( type_info_ const & ti ) const
0084 {
0085 error_info_map::const_iterator i=info_.find(ti);
0086 if( info_.end()!=i )
0087 {
0088 shared_ptr<error_info_base> const & p = i->second;
0089 return p;
0090 }
0091 return shared_ptr<error_info_base>();
0092 }
0093
0094 char const *
0095 diagnostic_information( char const * header ) const
0096 {
0097 if( header )
0098 {
0099 std::ostringstream tmp;
0100 tmp << header;
0101 for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
0102 {
0103 error_info_base const & x = *i->second;
0104 tmp << x.name_value_string();
0105 }
0106 tmp.str().swap(diagnostic_info_str_);
0107 }
0108 return diagnostic_info_str_.c_str();
0109 }
0110
0111 private:
0112
0113 friend class boost::exception;
0114
0115 typedef std::map< type_info_, shared_ptr<error_info_base> > error_info_map;
0116 error_info_map info_;
0117 mutable std::string diagnostic_info_str_;
0118 mutable int count_;
0119
0120 error_info_container_impl( error_info_container_impl const & );
0121 error_info_container_impl & operator=( error_info_container const & );
0122
0123 void
0124 add_ref() const
0125 {
0126 ++count_;
0127 }
0128
0129 bool
0130 release() const
0131 {
0132 if( --count_ )
0133 return false;
0134 else
0135 {
0136 delete this;
0137 return true;
0138 }
0139 }
0140
0141 refcount_ptr<error_info_container>
0142 clone() const
0143 {
0144 refcount_ptr<error_info_container> p;
0145 error_info_container_impl * c=new error_info_container_impl;
0146 p.adopt(c);
0147 for( error_info_map::const_iterator i=info_.begin(),e=info_.end(); i!=e; ++i )
0148 {
0149 shared_ptr<error_info_base> cp(i->second->clone());
0150 c->info_.insert(std::make_pair(i->first,cp));
0151 }
0152 return p;
0153 }
0154 };
0155
0156 template <class E,class Tag,class T>
0157 inline
0158 E const &
0159 set_info( E const & x, error_info<Tag,T> const & v )
0160 {
0161 typedef error_info<Tag,T> error_info_tag_t;
0162 shared_ptr<error_info_tag_t> p( new error_info_tag_t(v) );
0163 exception_detail::error_info_container * c=x.data_.get();
0164 if( !c )
0165 x.data_.adopt(c=new exception_detail::error_info_container_impl);
0166 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
0167 return x;
0168 }
0169
0170 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0171 template <class E,class Tag,class T>
0172 E const & set_info( E const &, error_info<Tag,T> && );
0173 template <class T>
0174 struct set_info_rv;
0175 template <class Tag,class T>
0176 struct
0177 set_info_rv<error_info<Tag,T> >
0178 {
0179 template <class E,class Tag1,class T1>
0180 friend E const & set_info( E const &, error_info<Tag1,T1> && );
0181 template <class E>
0182 static
0183 E const &
0184 set( E const & x, error_info<Tag,T> && v )
0185 {
0186 typedef error_info<Tag,T> error_info_tag_t;
0187 shared_ptr<error_info_tag_t> p( new error_info_tag_t(std::move(v)) );
0188 exception_detail::error_info_container * c=x.data_.get();
0189 if( !c )
0190 x.data_.adopt(c=new exception_detail::error_info_container_impl);
0191 c->set(p,BOOST_EXCEPTION_STATIC_TYPEID(error_info_tag_t));
0192 return x;
0193 }
0194 };
0195 template <>
0196 struct
0197 set_info_rv<throw_function>
0198 {
0199 template <class E,class Tag1,class T1>
0200 friend E const & set_info( E const &, error_info<Tag1,T1> && );
0201 template <class E>
0202 static
0203 E const &
0204 set( E const & x, throw_function && y )
0205 {
0206 x.throw_function_=y.v_;
0207 return x;
0208 }
0209 };
0210 template <>
0211 struct
0212 set_info_rv<throw_file>
0213 {
0214 template <class E,class Tag1,class T1>
0215 friend E const & set_info( E const &, error_info<Tag1,T1> && );
0216 template <class E>
0217 static
0218 E const &
0219 set( E const & x, throw_file && y )
0220 {
0221 x.throw_file_=y.v_;
0222 return x;
0223 }
0224 };
0225 template <>
0226 struct
0227 set_info_rv<throw_line>
0228 {
0229 template <class E,class Tag1,class T1>
0230 friend E const & set_info( E const &, error_info<Tag1,T1> && );
0231 template <class E>
0232 static
0233 E const &
0234 set( E const & x, throw_line && y )
0235 {
0236 x.throw_line_=y.v_;
0237 return x;
0238 }
0239 };
0240 template <class E,class Tag,class T>
0241 inline
0242 E const &
0243 set_info( E const & x, error_info<Tag,T> && v )
0244 {
0245 return set_info_rv<error_info<Tag,T> >::template set<E>(x,std::move(v));
0246 }
0247 #endif
0248
0249 template <class T>
0250 struct
0251 derives_boost_exception
0252 {
0253 enum e { value = (sizeof(dispatch_boost_exception((T*)0))==sizeof(large_size)) };
0254 };
0255 }
0256
0257 template <class E,class Tag,class T>
0258 inline
0259 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
0260 operator<<( E const & x, error_info<Tag,T> const & v )
0261 {
0262 return exception_detail::set_info(x,v);
0263 }
0264
0265 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0266 template <class E,class Tag,class T>
0267 inline
0268 typename enable_if<exception_detail::derives_boost_exception<E>,E const &>::type
0269 operator<<( E const & x, error_info<Tag,T> && v )
0270 {
0271 return exception_detail::set_info(x,std::move(v));
0272 }
0273 #endif
0274 }
0275
0276 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
0277 #pragma warning(pop)
0278 #endif
0279 #endif