TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/common/utils/boost_error_info_sstream.hpp
Go to the documentation of this file.
00001 #ifndef _BOOST_ERROR_INFO_SSTREAM_HPP
00002 #define _BOOST_ERROR_INFO_SSTREAM_HPP
00003 
00004 #include <boost/exception/exception.hpp>
00005 #include <boost/exception/info.hpp>
00006 #include <boost/version.hpp>
00007 #if( BOOST_VERSION >= 105400 )
00008 #include <boost/exception/to_string_stub.hpp>
00009 #endif
00010 
00011 #include <sstream>
00012 #include <string>
00013 
00014 #ifndef SWIG
00015 namespace boost {
00016 
00017 struct error_info_sstream
00018 {
00019         typedef std::ostringstream value_type;
00020         value_type _v;
00021 };
00022 
00023 inline std::string to_string( const error_info_sstream& x )
00024 {
00025         return x._v.str();
00026 }
00027 
00028 inline std::ostream& operator<<( std::ostream& os, const error_info_sstream& x )
00029 {
00030         os << x._v.str();
00031         return os;
00032 }
00033 
00034 template<class Tag>
00035 class error_info<Tag, error_info_sstream>: public exception_detail::error_info_base
00036 {
00037 public:
00038         typedef error_info_sstream T;
00039         typedef error_info<Tag, T> This;
00040         typedef T value_type;
00041 
00042         error_info() {}
00043         error_info( const This& v )
00044         {
00045                 _value._v << v._value._v.str();
00046         }
00047 
00048         template<typename V>
00049         error_info( const V& value )
00050         {
00051                 _value._v << value;
00052         }
00053 
00054         ~error_info() throw( ) {}
00055 
00056         template<typename V>
00057         This& operator+( const V& v )
00058         {
00059                 _value._v << v;
00060                 return *this;
00061         }
00062 
00063         const value_type& value() const { return _value; }
00064         value_type&       value()       { return _value; }
00065 
00066 private:
00067         
00068         #if( BOOST_VERSION >= 105400 )
00069         inline std::string name_value_string() const
00070         {
00071                 return to_string_stub(*this);
00072         }
00073         #elif( BOOST_VERSION >= 104300 )
00074         std::string tag_typeid_name() const { return tag_type_name<Tag>(); }
00075         #else
00076         char const* tag_typeid_name() const { return tag_type_name<Tag>(); }
00077         #endif
00078         std::string value_as_string() const { return _value._v.str(); }
00079 
00080         value_type _value;
00081 };
00082 }
00083 #endif
00084 
00085 
00086 #endif
00087