blob: d6ec23d24adcd16cdaebab9360c686e4c7b92b1f [file] [log] [blame]
Jeff Thompson86b6d642013-10-17 15:01:56 -07001// (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 NDNBOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
9#define NDNBOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED
10
11#if defined(_MSC_VER) && (_MSC_VER >= 1020)
12# pragma once
13#endif
14
15#include <typeinfo>
16#include <ndnboost/config.hpp> // member template friends.
17#include <ndnboost/iostreams/detail/char_traits.hpp>
18#include <ndnboost/iostreams/detail/ios.hpp> // openmode.
19#include <ndnboost/iostreams/detail/streambuf.hpp>
20
21// Must come last.
22#include <ndnboost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
23
24namespace ndnboost { namespace iostreams { namespace detail {
25
26template<typename Self, typename Ch, typename Tr, typename Alloc, typename Mode>
27class chain_base;
28
29template<typename Chain, typename Access, typename Mode> class chainbuf;
30
31#define NDNBOOST_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
40template<typename Ch, typename Tr = NDNBOOST_IOSTREAMS_CHAR_TRAITS(Ch) >
41class linked_streambuf : public NDNBOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) {
42protected:
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 }
48public:
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; }
53protected:
54
55 //----------grant friendship to chain_base and chainbuf-------------------//
56
57#ifndef NDNBOOST_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 NDNBOOST_IOSTREAMS_BASIC_STREAMBUF(Ch, Tr) base;
68 NDNBOOST_IOSTREAMS_USING_PROTECTED_STREAMBUF_MEMBERS(base)
69#endif
70 void close(NDNBOOST_IOS::openmode which)
71 {
72 if ( which == NDNBOOST_IOS::in &&
73 (flags_ & f_input_closed) == 0 )
74 {
75 flags_ |= f_input_closed;
76 close_impl(which);
77 }
78 if ( which == NDNBOOST_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(NDNBOOST_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 NDNBOOST_NO_MEMBER_TEMPLATE_FRIENDS
97 private:
98#else
99 public:
100#endif
101private:
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 <ndnboost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
113
114#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_LINKED_STREAMBUF_HPP_INCLUDED