[857] | 1 | // (C) Copyright Jonathan Turkanis 2003.
|
---|
| 2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
| 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
---|
| 4 |
|
---|
| 5 | // See http://www.boost.org/libs/iostreams for documentation.
|
---|
| 6 |
|
---|
| 7 | #ifndef BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_BUFFER_HPP_INCLUDED
|
---|
| 8 | #define BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_BUFFER_HPP_INCLUDED
|
---|
| 9 |
|
---|
| 10 | #include <boost/iostreams/detail/broken_overload_resolution/forward.hpp>
|
---|
| 11 |
|
---|
| 12 | namespace boost { namespace iostreams {
|
---|
| 13 |
|
---|
| 14 | template< typename T,
|
---|
| 15 | typename Tr =
|
---|
| 16 | BOOST_IOSTREAMS_CHAR_TRAITS(
|
---|
| 17 | BOOST_DEDUCED_TYPENAME char_type_of<T>::type
|
---|
| 18 | ),
|
---|
| 19 | typename Alloc =
|
---|
| 20 | std::allocator<
|
---|
| 21 | BOOST_DEDUCED_TYPENAME char_type_of<T>::type
|
---|
| 22 | >,
|
---|
| 23 | typename Mode = BOOST_DEDUCED_TYPENAME mode_of<T>::type >
|
---|
| 24 | class stream_buffer
|
---|
| 25 | : public detail::stream_buffer_traits<T, Tr, Alloc, Mode>::type
|
---|
| 26 | {
|
---|
| 27 | private:
|
---|
| 28 | BOOST_STATIC_ASSERT((
|
---|
| 29 | is_convertible<
|
---|
| 30 | BOOST_DEDUCED_TYPENAME iostreams::category_of<T>::type, Mode
|
---|
| 31 | >::value
|
---|
| 32 | ));
|
---|
| 33 | typedef typename
|
---|
| 34 | detail::stream_buffer_traits<
|
---|
| 35 | T, Tr, Alloc, Mode
|
---|
| 36 | >::type base_type;
|
---|
| 37 | typedef T policy_type;
|
---|
| 38 | public:
|
---|
| 39 | typedef typename char_type_of<T>::type char_type;
|
---|
| 40 | BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
|
---|
| 41 | stream_buffer() { }
|
---|
| 42 | ~stream_buffer()
|
---|
| 43 | {
|
---|
| 44 | try {
|
---|
| 45 | if (this->is_open() && this->auto_close())
|
---|
| 46 | this->close();
|
---|
| 47 | } catch (std::exception&) { }
|
---|
| 48 | }
|
---|
| 49 | template<typename U0>
|
---|
| 50 | stream_buffer(const U0& u0)
|
---|
| 51 | {
|
---|
| 52 | open_impl(detail::forward<T, U0>(), u0);
|
---|
| 53 | }
|
---|
| 54 | template<typename U0, typename U1>
|
---|
| 55 | stream_buffer(const U0& u0, const U1& u1)
|
---|
| 56 | {
|
---|
| 57 | open_impl(detail::forward<T, U0>(), u0, u1);
|
---|
| 58 | }
|
---|
| 59 | template<typename U0, typename U1, typename U2>
|
---|
| 60 | stream_buffer(const U0& u0, const U1& u1, const U2& u2)
|
---|
| 61 | {
|
---|
| 62 | open_impl(detail::forward<T, U0>(), u0, u1, u2);
|
---|
| 63 | }
|
---|
| 64 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
|
---|
| 65 | template<typename U0>
|
---|
| 66 | stream_buffer(U0& u0)
|
---|
| 67 | {
|
---|
| 68 | open_impl(detail::forward<T, U0>(), u0);
|
---|
| 69 | }
|
---|
| 70 | template<typename U0, typename U1>
|
---|
| 71 | stream_buffer(U0& u0, const U1& u1)
|
---|
| 72 | {
|
---|
| 73 | open_impl(detail::forward<T, U0>(), u0, u1);
|
---|
| 74 | }
|
---|
| 75 | template<typename U0, typename U1, typename U2>
|
---|
| 76 | stream_buffer(U0& u0, const U1& u1, const U2& u2)
|
---|
| 77 | {
|
---|
| 78 | open_impl(detail::forward<T, U0>(), u0, u1, u2);
|
---|
| 79 | }
|
---|
| 80 | #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
|
---|
| 81 | template<typename U0>
|
---|
| 82 | void open(const U0& u0)
|
---|
| 83 | {
|
---|
| 84 | open_impl(detail::forward<T, U0>(), u0);
|
---|
| 85 | }
|
---|
| 86 | template<typename U0, typename U1>
|
---|
| 87 | void open(const U0& u0, const U1& u1)
|
---|
| 88 | {
|
---|
| 89 | open_impl(detail::forward<T, U0>(), u0, u1);
|
---|
| 90 | }
|
---|
| 91 | template<typename U0, typename U1, typename U2>
|
---|
| 92 | void open(const U0& u0, const U1& u1, const U2& u2)
|
---|
| 93 | {
|
---|
| 94 | open_impl(detail::forward<T, U0>(), u0, u1, u2);
|
---|
| 95 | }
|
---|
| 96 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
|
---|
| 97 | template<typename U0>
|
---|
| 98 | void open(U0& u0)
|
---|
| 99 | {
|
---|
| 100 | open_impl(detail::forward<T, U0>(), u0);
|
---|
| 101 | }
|
---|
| 102 | template<typename U0, typename U1>
|
---|
| 103 | void open(U0& u0, const U1& u1)
|
---|
| 104 | {
|
---|
| 105 | open_impl(detail::forward<T, U0>(), u0, u1);
|
---|
| 106 | }
|
---|
| 107 | template<typename U0, typename U1, typename U2>
|
---|
| 108 | void open(U0& u0, const U1& u1, const U2& u2)
|
---|
| 109 | {
|
---|
| 110 | open_impl(detail::forward<T, U0>(), u0, u1, u2);
|
---|
| 111 | }
|
---|
| 112 | #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
|
---|
| 113 | T& operator*() { return *this->component(); }
|
---|
| 114 | T* operator->() { return this->component(); }
|
---|
| 115 | private:
|
---|
| 116 | template<typename U0>
|
---|
| 117 | void open_impl(mpl::false_, const U0& u0)
|
---|
| 118 | {
|
---|
| 119 | base_type::open(const_cast<U0&>(u0), -1, -1);
|
---|
| 120 | }
|
---|
| 121 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
|
---|
| 122 | template<typename U0>
|
---|
| 123 | void open_impl(mpl::false_, U0& u0)
|
---|
| 124 | {
|
---|
| 125 | base_type::open(detail::wrap(u0), -1, -1);
|
---|
| 126 | }
|
---|
| 127 | #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
|
---|
| 128 | template<typename U0>
|
---|
| 129 | void open_impl(mpl::true_, const U0& u0)
|
---|
| 130 | {
|
---|
| 131 | base_type::open(T(const_cast<U0&>(u0)), -1, -1);
|
---|
| 132 | }
|
---|
| 133 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
|
---|
| 134 | template<typename U0>
|
---|
| 135 | void open_impl(mpl::true_, U0& u0)
|
---|
| 136 | {
|
---|
| 137 | base_type::open(T(u0), -1, -1);
|
---|
| 138 | }
|
---|
| 139 | #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
|
---|
| 140 | template<typename U0, typename U1>
|
---|
| 141 | void open_impl(mpl::false_, const U0& u0, const U1& u1)
|
---|
| 142 | {
|
---|
| 143 | base_type::open(u0, u1, -1);
|
---|
| 144 | }
|
---|
| 145 | template<typename U0, typename U1>
|
---|
| 146 | void open_impl(mpl::true_, const U0& u0, const U1& u1)
|
---|
| 147 | {
|
---|
| 148 | base_type::open(T(const_cast<U0&>(u0), u1), -1, -1);
|
---|
| 149 | }
|
---|
| 150 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
|
---|
| 151 | template<typename U0, typename U1>
|
---|
| 152 | void open_impl(mpl::true_, U0& u0, const U1& u1)
|
---|
| 153 | {
|
---|
| 154 | base_type::open(T(u0, u1), -1, -1);
|
---|
| 155 | }
|
---|
| 156 | #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
|
---|
| 157 | template<typename U0, typename U1, typename U2>
|
---|
| 158 | void open_impl(mpl::false_, const U0& u0, const U1& u1, const U2& u2)
|
---|
| 159 | {
|
---|
| 160 | base_type::open(u0, u1, u2);
|
---|
| 161 | }
|
---|
| 162 | template<typename U0, typename U1, typename U2>
|
---|
| 163 | void open_impl(mpl::true_, const U0& u0, const U1& u1, const U2& u2)
|
---|
| 164 | {
|
---|
| 165 | base_type::open(T(const_cast<U0&>(u0), u1, u2), -1, -1);
|
---|
| 166 | }
|
---|
| 167 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------------//
|
---|
| 168 | template<typename U0, typename U1, typename U2>
|
---|
| 169 | void open_impl(mpl::true_, U0& u0, const U1& u1, const U2& u2)
|
---|
| 170 | {
|
---|
| 171 | base_type::open(T(u0, u1, u2), -1, -1);
|
---|
| 172 | }
|
---|
| 173 | #endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) //---------------------------//
|
---|
| 174 | void check_open()
|
---|
| 175 | {
|
---|
| 176 | if (this->is_open())
|
---|
| 177 | throw BOOST_IOSTREAMS_FAILURE("already open");
|
---|
| 178 | }
|
---|
| 179 | };
|
---|
| 180 |
|
---|
| 181 | } } // End namespaces iostreams, boost.
|
---|
| 182 |
|
---|
| 183 | #endif // BOOST_IOSTREAMS_DETAIL_BROKEN_OVERLOAD_RESOLUTION_STREAM_BUFFER_HPP_INCLUDED
|
---|