fix doc example typo
[boost.git] / boost / iostreams / stream_buffer.hpp
blob6d7ade3f7b1a1329b5020ebe4692f387de8e40ee
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
12 # pragma once
13 #endif
15 #include <memory> // allocator.
16 #include <boost/config.hpp> // BOOST_DEDUCED_TYPENAME.
17 #include <boost/iostreams/detail/char_traits.hpp>
18 #include <boost/iostreams/detail/config/overload_resolution.hpp>
19 #include <boost/iostreams/detail/forward.hpp>
20 #include <boost/iostreams/detail/ios.hpp> // failure, streamsize.
21 #include <boost/iostreams/detail/streambuf/direct_streambuf.hpp>
22 #include <boost/iostreams/detail/streambuf/indirect_streambuf.hpp>
23 #include <boost/iostreams/traits.hpp>
24 #include <boost/static_assert.hpp>
25 #include <boost/type_traits/is_convertible.hpp>
27 // Must come last.
28 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
30 namespace boost { namespace iostreams { namespace detail {
32 template<typename T, typename Tr, typename Alloc, typename Mode>
33 struct stream_buffer_traits {
34 typedef typename
35 mpl::if_<
36 is_convertible<
37 BOOST_DEDUCED_TYPENAME category_of<T>::type,
38 direct_tag
40 direct_streambuf<T, Tr>,
41 indirect_streambuf<T, Tr, Alloc, Mode>
42 >::type type;
45 } } } // End namespaces detail, iostreams, boost
47 #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
48 # include <boost/iostreams/detail/broken_overload_resolution/stream_buffer.hpp>
49 #else
51 namespace boost { namespace iostreams {
53 template< typename T,
54 typename Tr =
55 BOOST_IOSTREAMS_CHAR_TRAITS(
56 BOOST_DEDUCED_TYPENAME char_type_of<T>::type
58 typename Alloc =
59 std::allocator<
60 BOOST_DEDUCED_TYPENAME char_type_of<T>::type
62 typename Mode = BOOST_DEDUCED_TYPENAME mode_of<T>::type >
63 class stream_buffer
64 : public detail::stream_buffer_traits<T, Tr, Alloc, Mode>::type
66 private:
67 BOOST_STATIC_ASSERT((
68 is_convertible<
69 BOOST_DEDUCED_TYPENAME iostreams::category_of<T>::type, Mode
70 >::value
71 ));
72 typedef typename
73 detail::stream_buffer_traits<
74 T, Tr, Alloc, Mode
75 >::type base_type;
76 public:
77 typedef typename char_type_of<T>::type char_type;
78 struct category
79 : Mode,
80 closable_tag,
81 streambuf_tag
82 { };
83 BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr)
84 public:
85 stream_buffer() { }
86 ~stream_buffer()
88 try {
89 if (this->is_open() && this->auto_close())
90 this->close();
91 } catch (...) { }
93 BOOST_IOSTREAMS_FORWARD( stream_buffer, open_impl, T,
94 BOOST_IOSTREAMS_PUSH_PARAMS,
95 BOOST_IOSTREAMS_PUSH_ARGS )
96 T& operator*() { return *this->component(); }
97 T* operator->() { return this->component(); }
98 private:
99 void open_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS())
100 { // Used for forwarding.
101 if (this->is_open())
102 BOOST_IOSTREAMS_FAILURE("already open");
103 base_type::open(t BOOST_IOSTREAMS_PUSH_ARGS());
107 } } // End namespaces iostreams, boost.
109 #endif // #ifdef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION
111 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
113 #endif // #ifndef BOOST_IOSTREAMS_STREAM_BUFFER_HPP_INCLUDED