]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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.) | |
5 | ||
6 | // See http://www.boost.org/libs/iostreams for documentation. | |
7 | ||
8 | #ifndef BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED | |
9 | #define BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED | |
10 | ||
11 | #if defined(_MSC_VER) | |
12 | # pragma once | |
13 | #endif | |
14 | ||
15 | #include <typeinfo> | |
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> | |
20 | ||
21 | // Must come last. | |
22 | #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC. | |
23 | ||
24 | namespace boost { namespace iostreams { namespace detail { | |
25 | ||
26 | template<typename Self, typename Ch, typename Tr, typename Alloc, typename Mode> | |
27 | class chain_base; | |
28 | ||
29 | template<typename Chain, typename Access, typename Mode> class chainbuf; | |
30 | ||
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; \ | |
38 | /**/ | |
39 | ||
40 | template<typename Ch, typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch) > | |
41 | class linked_streambuf : public BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) { | |
42 | protected: | |
43 | linked_streambuf() : flags_(0) { } | |
44 | void set_true_eof(bool eof) | |
45 | { | |
46 | flags_ = (flags_ & ~f_true_eof) | (eof ? f_true_eof : 0); | |
47 | } | |
48 | public: | |
49 | ||
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; } | |
53 | protected: | |
54 | ||
55 | //----------grant friendship to chain_base and chainbuf-------------------// | |
56 | ||
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; | |
63 | template<typename U> | |
64 | friend class member_close_operation; | |
65 | #else | |
66 | public: | |
67 | typedef BOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) base; | |
68 | BOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base) | |
69 | #endif | |
70 | void close(BOOST_IOS::openmode which) | |
71 | { | |
72 | if ( which == BOOST_IOS::in && | |
73 | (flags_ & f_input_closed) == 0 ) | |
74 | { | |
75 | flags_ |= f_input_closed; | |
76 | close_impl(which); | |
77 | } | |
78 | if ( which == BOOST_IOS::out && | |
79 | (flags_ & f_output_closed) == 0 ) | |
80 | { | |
81 | flags_ |= f_output_closed; | |
82 | close_impl(which); | |
83 | } | |
84 | } | |
85 | void set_needs_close() | |
86 | { | |
87 | flags_ &= ~(f_input_closed | f_output_closed); | |
88 | } | |
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 | |
97 | private: | |
98 | #else | |
99 | public: | |
100 | #endif | |
101 | private: | |
102 | enum flag_type { | |
103 | f_true_eof = 1, | |
104 | f_input_closed = f_true_eof << 1, | |
105 | f_output_closed = f_input_closed << 1 | |
106 | }; | |
107 | int flags_; | |
108 | }; | |
109 | ||
110 | } } } // End namespaces detail, iostreams, boost. | |
111 | ||
112 | #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC. | |
113 | ||
114 | #endif // #ifndef BOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED |