1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2004-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_FILTER_STREAM_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
15 #include <memory> // allocator.
16 #include <boost/iostreams/detail/access_control.hpp>
17 #include <boost/iostreams/detail/char_traits.hpp>
18 #include <boost/iostreams/detail/iostream.hpp> // standard streams.
19 #include <boost/iostreams/detail/push.hpp>
20 #include <boost/iostreams/detail/select.hpp>
21 #include <boost/iostreams/detail/streambuf.hpp> // pubsync.
22 #include <boost/iostreams/filtering_streambuf.hpp>
23 #include <boost/mpl/and.hpp>
24 #include <boost/mpl/bool.hpp>
25 #include <boost/static_assert.hpp>
26 #include <boost/type_traits/is_convertible.hpp>
29 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
31 namespace boost { namespace iostreams {
33 //--------------Definition of filtered_istream--------------------------------//
37 template<typename Mode, typename Ch, typename Tr>
38 struct filtering_stream_traits {
40 iostreams::select< // Disambiguation for Tru64
42 is_convertible<Mode, input>,
43 is_convertible<Mode, output>
45 BOOST_IOSTREAMS_BASIC_IOSTREAM(Ch, Tr),
46 is_convertible<Mode, input>,
47 BOOST_IOSTREAMS_BASIC_ISTREAM(Ch, Tr),
49 BOOST_IOSTREAMS_BASIC_OSTREAM(Ch, Tr)
52 iostreams::select< // Dismbiguation required for Tru64.
54 is_convertible<Mode, input>,
55 is_convertible<Mode, output>
58 is_convertible<Mode, input>,
65 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
66 # pragma warning(push)
67 // https://connect.microsoft.com/VisualStudio/feedback/details/733720/
68 # pragma warning(disable: 4250)
71 template<typename Chain, typename Access>
72 class filtering_stream_base
73 : public access_control<
74 boost::iostreams::detail::chain_client<Chain>,
77 public filtering_stream_traits<
79 typename Chain::char_type,
80 typename Chain::traits_type
84 typedef Chain chain_type;
85 typedef access_control<
86 boost::iostreams::detail::chain_client<Chain>,
91 filtering_stream_traits<
93 typename Chain::char_type,
94 typename Chain::traits_type
95 >::stream_type stream_type;
96 filtering_stream_base() : stream_type(0) { this->set_chain(&chain_); }
98 void notify() { this->rdbuf(chain_.empty() ? 0 : &chain_.front()); }
102 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
103 # pragma warning(pop)
106 } // End namespace detail.
109 // Macro: BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_)
110 // Description: Defines a template derived from std::basic_streambuf which uses
111 // a chain to perform i/o. The template has the following parameters:
112 // Mode - the i/o mode.
113 // Ch - The character type.
114 // Tr - The character traits type.
115 // Alloc - The allocator type.
116 // Access - Indicates accessibility of the chain interface; must be either
117 // public_ or protected_; defaults to public_.
119 // name_ - The name of the template to be defined.
120 // chain_type_ - The name of the chain template.
121 // default_char_ - The default value for the char template parameter.
123 #define BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_) \
124 template< typename Mode, \
125 typename Ch = default_char_, \
126 typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch), \
127 typename Alloc = std::allocator<Ch>, \
128 typename Access = public_ > \
130 : public boost::iostreams::detail::filtering_stream_base< \
131 chain_type_<Mode, Ch, Tr, Alloc>, Access \
135 typedef Ch char_type; \
139 detail::filtering_stream_traits<Mode, Ch, Tr>::stream_tag \
141 BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
143 typedef chain_type_<Mode, Ch, Tr, Alloc> chain_type; \
145 BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \
147 if (this->is_complete()) \
148 this->rdbuf()->BOOST_IOSTREAMS_PUBSYNC(); \
151 typedef access_control< \
152 boost::iostreams::detail::chain_client< \
153 chain_type_<Mode, Ch, Tr, Alloc> \
157 template<typename T> \
158 void push_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) \
159 { client_type::push(t BOOST_IOSTREAMS_PUSH_ARGS()); } \
163 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
164 # pragma warning(push)
165 // https://connect.microsoft.com/VisualStudio/feedback/details/733720/
166 # pragma warning(disable: 4250)
169 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(filtering_stream, boost::iostreams::chain, char)
170 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(wfiltering_stream, boost::iostreams::chain, wchar_t)
172 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
173 # pragma warning(pop)
176 typedef filtering_stream<input> filtering_istream;
177 typedef filtering_stream<output> filtering_ostream;
178 typedef wfiltering_stream<input> filtering_wistream;
179 typedef wfiltering_stream<output> filtering_wostream;
181 //----------------------------------------------------------------------------//
183 } } // End namespace iostreams, boost
185 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC
187 #endif // #ifndef BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED