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_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
16 #include <boost/config.hpp> // member template friends.
17 #include <boost/iostreams/detail/char_traits.hpp>
18 #include <boost/iostreams/detail/ios.hpp> // openmode.
19 #include <boost/iostreams/detail/streambuf.hpp>
22 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
24 namespace boost
{ namespace iostreams
{ namespace detail
{
26 template<typename Self
, typename Ch
, typename Tr
, typename Alloc
, typename Mode
>
29 template<typename Chain
, typename Access
, typename Mode
> class chainbuf
;
31 #define BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base) \
32 using base::eback; using base::gptr; using base::egptr; \
33 using base::setg; using base::gbump; using base::pbase; \
34 using base::pptr; using base::epptr; using base::setp; \
35 using base::pbump; using base::underflow; using base::pbackfail; \
36 using base::xsgetn; using base::overflow; using base::xsputn; \
37 using base::sync; using base::seekoff; using base::seekpos; \
40 template<typename Ch
, typename Tr
= BOOST_IOSTREAMS_CHAR_TRAITS(Ch
) >
41 class linked_streambuf
: public BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch
, Tr
) {
43 linked_streambuf() : flags_(0) { }
44 void set_true_eof(bool eof
)
46 flags_
= (flags_
& ~f_true_eof
) | (eof
? f_true_eof
: 0);
50 // Should be called only after receiving an ordinary EOF indication,
51 // to confirm that it represents EOF rather than WOULD_BLOCK.
52 bool true_eof() const { return (flags_
& f_true_eof
) != 0; }
55 //----------grant friendship to chain_base and chainbuf-------------------//
57 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
58 template< typename Self
, typename ChT
, typename TrT
,
59 typename Alloc
, typename Mode
>
60 friend class chain_base
;
61 template<typename Chain
, typename Mode
, typename Access
>
62 friend class chainbuf
;
64 friend class member_close_operation
;
67 typedef BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch
, Tr
) base
;
68 BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base
)
70 void close(BOOST_IOS::openmode which
)
72 if ( which
== BOOST_IOS::in
&&
73 (flags_
& f_input_closed
) == 0 )
75 flags_
|= f_input_closed
;
78 if ( which
== BOOST_IOS::out
&&
79 (flags_
& f_output_closed
) == 0 )
81 flags_
|= f_output_closed
;
85 void set_needs_close()
87 flags_
&= ~(f_input_closed
| f_output_closed
);
89 virtual void set_next(linked_streambuf
<Ch
, Tr
>* /* next */) { }
90 virtual void close_impl(BOOST_IOS::openmode
) = 0;
91 virtual bool auto_close() const = 0;
92 virtual void set_auto_close(bool) = 0;
93 virtual bool strict_sync() = 0;
94 virtual const std::type_info
& component_type() const = 0;
95 virtual void* component_impl() = 0;
96 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
104 f_input_closed
= f_true_eof
<< 1,
105 f_output_closed
= f_input_closed
<< 1
110 } } } // End namespaces detail, iostreams, boost.
112 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
114 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED