1 // (C) Copyright Jonathan Turkanis 2004
2 // Distributed under the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
5 // See http://www.boost.org/libs/iostreams for documentation.
7 #ifndef BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
8 #define BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
10 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
14 #include <memory> // allocator.
15 #include <boost/iostreams/detail/access_control.hpp>
16 #include <boost/iostreams/detail/char_traits.hpp>
17 #include <boost/iostreams/detail/iostream.hpp> // standard streams.
18 #include <boost/iostreams/detail/push.hpp>
19 #include <boost/iostreams/detail/select.hpp>
20 #include <boost/iostreams/detail/streambuf.hpp> // pubsync.
21 #include <boost/iostreams/filtering_streambuf.hpp>
22 #include <boost/mpl/and.hpp>
23 #include <boost/mpl/bool.hpp>
24 #include <boost/static_assert.hpp>
25 #include <boost/type_traits/is_convertible.hpp>
28 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
30 namespace boost { namespace iostreams {
32 //--------------Definition of filtered_istream--------------------------------//
36 template<typename Mode, typename Ch, typename Tr>
37 struct filtering_stream_traits {
39 iostreams::select< // Disambiguation for Tru64
41 is_convertible<Mode, input>,
42 is_convertible<Mode, output>
44 BOOST_IOSTREAMS_BASIC_IOSTREAM(Ch, Tr),
45 is_convertible<Mode, input>,
46 BOOST_IOSTREAMS_BASIC_ISTREAM(Ch, Tr),
48 BOOST_IOSTREAMS_BASIC_OSTREAM(Ch, Tr)
52 template<typename Chain, typename Access>
53 class filtering_stream_base
54 : public access_control<
55 boost::iostreams::detail::chain_client<Chain>,
58 public filtering_stream_traits<
60 typename Chain::char_type,
61 typename Chain::traits_type
65 typedef Chain chain_type;
66 typedef access_control<
67 boost::iostreams::detail::chain_client<Chain>,
72 filtering_stream_traits<
74 typename Chain::char_type,
75 typename Chain::traits_type
77 filtering_stream_base() : stream_type(0) { this->set_chain(&chain_); }
79 void notify() { this->rdbuf(chain_.empty() ? 0 : &chain_.front()); }
83 } // End namespace detail.
86 // Macro: BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_)
87 // Description: Defines a template derived from std::basic_streambuf which uses
88 // a chain to perform i/o. The template has the following parameters:
89 // Mode - the i/o mode.
90 // Ch - The character type.
91 // Tr - The character traits type.
92 // Alloc - The allocator type.
93 // Access - Indicates accessibility of the chain interface; must be either
94 // public_ or protected_; defaults to public_.
96 // name_ - The name of the template to be defined.
97 // chain_type_ - The name of the chain template.
98 // default_char_ - The default value for the char template parameter.
100 #define BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_) \
101 template< typename Mode, \
102 typename Ch = default_char_, \
103 typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch), \
104 typename Alloc = std::allocator<Ch>, \
105 typename Access = public_ > \
107 : public boost::iostreams::detail::filtering_stream_base< \
108 chain_type_<Mode, Ch, Tr, Alloc>, Access \
112 typedef Ch char_type; \
113 BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
115 typedef chain_type_<Mode, Ch, Tr, Alloc> chain_type; \
117 BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \
119 if (this->is_complete()) \
120 this->rdbuf()->BOOST_IOSTREAMS_PUBSYNC(); \
123 typedef access_control< \
124 boost::iostreams::detail::chain_client< \
125 chain_type_<Mode, Ch, Tr, Alloc> \
129 template<typename T> \
130 void push_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) \
131 { client_type::push(t BOOST_IOSTREAMS_PUSH_ARGS()); } \
134 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(filtering_stream, boost::iostreams::chain, char)
135 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(wfiltering_stream, boost::iostreams::chain, wchar_t)
137 typedef filtering_stream<input> filtering_istream;
138 typedef filtering_stream<output> filtering_ostream;
139 typedef wfiltering_stream<input> filtering_wistream;
140 typedef wfiltering_stream<output> filtering_wostream;
142 //----------------------------------------------------------------------------//
144 } } // End namespace iostreams, boost
146 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC
148 #endif // #ifndef BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED