File indexing completed on 2025-01-18 09:38:54
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED
0010
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif
0014
0015 #include <memory> // allocator.
0016 #include <boost/config.hpp> // BOOST_DEDUCED_TYPENAME.
0017 #include <boost/iostreams/detail/char_traits.hpp>
0018 #include <boost/iostreams/detail/config/overload_resolution.hpp>
0019 #include <boost/iostreams/detail/forward.hpp>
0020 #include <boost/iostreams/detail/ios.hpp> // failure, streamsize.
0021 #include <boost/iostreams/detail/streambuf/direct_streambuf.hpp>
0022 #include <boost/iostreams/detail/streambuf/indirect_streambuf.hpp>
0023 #include <boost/iostreams/traits.hpp>
0024 #include <boost/static_assert.hpp>
0025 #include <boost/throw_exception.hpp>
0026 #include <boost/type_traits/is_convertible.hpp>
0027
0028
0029 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
0030
0031 namespace boost { namespace iostreams { namespace detail {
0032
0033 template<typename T, typename Tr, typename Alloc, typename Mode>
0034 struct stream_buffer_traits {
0035 typedef typename
0036 mpl::if_<
0037 is_convertible<
0038 BOOST_DEDUCED_TYPENAME category_of<T>::type,
0039 direct_tag
0040 >,
0041 direct_streambuf<T, Tr>,
0042 indirect_streambuf<T, Tr, Alloc, Mode>
0043 >::type type;
0044 };
0045
0046 } } }
0047
0048 #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
0049 # include <boost/iostreams/detail/broken_overload_resolution/stream_buffer.hpp>
0050 #else
0051
0052 namespace boost { namespace iostreams {
0053
0054 template< typename T,
0055 typename Tr =
0056 BOOST_IOSTREAMS_CHAR_TRAITS(
0057 BOOST_DEDUCED_TYPENAME char_type_of<T>::type
0058 ),
0059 typename Alloc =
0060 std::allocator<
0061 BOOST_DEDUCED_TYPENAME char_type_of<T>::type
0062 >,
0063 typename Mode = BOOST_DEDUCED_TYPENAME mode_of<T>::type >
0064 class stream_buffer
0065 : public detail::stream_buffer_traits<T, Tr, Alloc, Mode>::type
0066 {
0067 private:
0068 BOOST_STATIC_ASSERT((
0069 is_convertible<
0070 BOOST_DEDUCED_TYPENAME iostreams::category_of<T>::type, Mode
0071 >::value
0072 ));
0073 typedef typename
0074 detail::stream_buffer_traits<
0075 T, Tr, Alloc, Mode
0076 >::type base_type;
0077 public:
0078 typedef typename char_type_of<T>::type char_type;
0079 struct category
0080 : Mode,
0081 closable_tag,
0082 streambuf_tag
0083 { };
0084 BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
0085 public:
0086 stream_buffer() { }
0087 ~stream_buffer()
0088 {
0089 try {
0090 if (this->is_open() && this->auto_close())
0091 this->close();
0092 } catch (...) { }
0093 }
0094 BOOST_IOSTREAMS_FORWARD( stream_buffer, open_impl, T,
0095 BOOST_IOSTREAMS_PUSH_PARAMS,
0096 BOOST_IOSTREAMS_PUSH_ARGS )
0097 T& operator*() { return *this->component(); }
0098 T* operator->() { return this->component(); }
0099 private:
0100 void open_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS())
0101 {
0102 if (this->is_open())
0103 boost::throw_exception(
0104 BOOST_IOSTREAMS_FAILURE("already open")
0105 );
0106 base_type::open(t BOOST_IOSTREAMS_PUSH_ARGS());
0107 }
0108 };
0109
0110 } }
0111
0112 #endif
0113
0114 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
0115
0116 #endif