Chris@16
|
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
|
Chris@16
|
2 // (C) Copyright 2003-2007 Jonathan Turkanis
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
Chris@16
|
5
|
Chris@16
|
6 // See http://www.boost.org/libs/iostreams for documentation.
|
Chris@16
|
7
|
Chris@16
|
8 #ifndef BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
|
Chris@16
|
9 #define BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
|
Chris@16
|
10
|
Chris@16
|
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
Chris@16
|
12 # pragma once
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 #include <typeinfo>
|
Chris@16
|
16 #include <boost/config.hpp> // member template friends.
|
Chris@16
|
17 #include <boost/iostreams/detail/char_traits.hpp>
|
Chris@16
|
18 #include <boost/iostreams/detail/ios.hpp> // openmode.
|
Chris@16
|
19 #include <boost/iostreams/detail/streambuf.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 // Must come last.
|
Chris@16
|
22 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost { namespace iostreams { namespace detail {
|
Chris@16
|
25
|
Chris@16
|
26 template<typename Self, typename Ch, typename Tr, typename Alloc, typename Mode>
|
Chris@16
|
27 class chain_base;
|
Chris@16
|
28
|
Chris@16
|
29 template<typename Chain, typename Access, typename Mode> class chainbuf;
|
Chris@16
|
30
|
Chris@16
|
31 #define BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base) \
|
Chris@16
|
32 using base::eback; using base::gptr; using base::egptr; \
|
Chris@16
|
33 using base::setg; using base::gbump; using base::pbase; \
|
Chris@16
|
34 using base::pptr; using base::epptr; using base::setp; \
|
Chris@16
|
35 using base::pbump; using base::underflow; using base::pbackfail; \
|
Chris@16
|
36 using base::xsgetn; using base::overflow; using base::xsputn; \
|
Chris@16
|
37 using base::sync; using base::seekoff; using base::seekpos; \
|
Chris@16
|
38 /**/
|
Chris@16
|
39
|
Chris@16
|
40 template<typename Ch, typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch) >
|
Chris@16
|
41 class linked_streambuf : public BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) {
|
Chris@16
|
42 protected:
|
Chris@16
|
43 linked_streambuf() : flags_(0) { }
|
Chris@16
|
44 void set_true_eof(bool eof)
|
Chris@16
|
45 {
|
Chris@16
|
46 flags_ = (flags_ & ~f_true_eof) | (eof ? f_true_eof : 0);
|
Chris@16
|
47 }
|
Chris@16
|
48 public:
|
Chris@16
|
49
|
Chris@16
|
50 // Should be called only after receiving an ordinary EOF indication,
|
Chris@16
|
51 // to confirm that it represents EOF rather than WOULD_BLOCK.
|
Chris@16
|
52 bool true_eof() const { return (flags_ & f_true_eof) != 0; }
|
Chris@16
|
53 protected:
|
Chris@16
|
54
|
Chris@16
|
55 //----------grant friendship to chain_base and chainbuf-------------------//
|
Chris@16
|
56
|
Chris@16
|
57 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
Chris@16
|
58 template< typename Self, typename ChT, typename TrT,
|
Chris@16
|
59 typename Alloc, typename Mode >
|
Chris@16
|
60 friend class chain_base;
|
Chris@16
|
61 template<typename Chain, typename Mode, typename Access>
|
Chris@16
|
62 friend class chainbuf;
|
Chris@16
|
63 template<typename U>
|
Chris@16
|
64 friend class member_close_operation;
|
Chris@16
|
65 #else
|
Chris@16
|
66 public:
|
Chris@16
|
67 typedef BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) base;
|
Chris@16
|
68 BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base)
|
Chris@16
|
69 #endif
|
Chris@16
|
70 void close(BOOST_IOS::openmode which)
|
Chris@16
|
71 {
|
Chris@16
|
72 if ( which == BOOST_IOS::in &&
|
Chris@16
|
73 (flags_ & f_input_closed) == 0 )
|
Chris@16
|
74 {
|
Chris@16
|
75 flags_ |= f_input_closed;
|
Chris@16
|
76 close_impl(which);
|
Chris@16
|
77 }
|
Chris@16
|
78 if ( which == BOOST_IOS::out &&
|
Chris@16
|
79 (flags_ & f_output_closed) == 0 )
|
Chris@16
|
80 {
|
Chris@16
|
81 flags_ |= f_output_closed;
|
Chris@16
|
82 close_impl(which);
|
Chris@16
|
83 }
|
Chris@16
|
84 }
|
Chris@16
|
85 void set_needs_close()
|
Chris@16
|
86 {
|
Chris@16
|
87 flags_ &= ~(f_input_closed | f_output_closed);
|
Chris@16
|
88 }
|
Chris@16
|
89 virtual void set_next(linked_streambuf<Ch, Tr>* /* next */) { }
|
Chris@16
|
90 virtual void close_impl(BOOST_IOS::openmode) = 0;
|
Chris@16
|
91 virtual bool auto_close() const = 0;
|
Chris@16
|
92 virtual void set_auto_close(bool) = 0;
|
Chris@16
|
93 virtual bool strict_sync() = 0;
|
Chris@16
|
94 virtual const std::type_info& component_type() const = 0;
|
Chris@16
|
95 virtual void* component_impl() = 0;
|
Chris@16
|
96 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
Chris@16
|
97 private:
|
Chris@16
|
98 #else
|
Chris@16
|
99 public:
|
Chris@16
|
100 #endif
|
Chris@16
|
101 private:
|
Chris@16
|
102 enum flag_type {
|
Chris@16
|
103 f_true_eof = 1,
|
Chris@16
|
104 f_input_closed = f_true_eof << 1,
|
Chris@16
|
105 f_output_closed = f_input_closed << 1
|
Chris@16
|
106 };
|
Chris@16
|
107 int flags_;
|
Chris@16
|
108 };
|
Chris@16
|
109
|
Chris@16
|
110 } } } // End namespaces detail, iostreams, boost.
|
Chris@16
|
111
|
Chris@16
|
112 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
|
Chris@16
|
113
|
Chris@16
|
114 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
|