File indexing completed on 2025-01-18 09:38:53
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_FILTER_STREAM_HPP_INCLUDED
0010
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif
0014
0015 #include <memory> // allocator.
0016 #include <boost/iostreams/detail/access_control.hpp>
0017 #include <boost/iostreams/detail/char_traits.hpp>
0018 #include <boost/iostreams/detail/iostream.hpp> // standard streams.
0019 #include <boost/iostreams/detail/push.hpp>
0020 #include <boost/iostreams/detail/select.hpp>
0021 #include <boost/iostreams/detail/streambuf.hpp> // pubsync.
0022 #include <boost/iostreams/filtering_streambuf.hpp>
0023 #include <boost/mpl/and.hpp>
0024 #include <boost/mpl/bool.hpp>
0025 #include <boost/static_assert.hpp>
0026 #include <boost/type_traits/is_convertible.hpp>
0027
0028
0029 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
0030
0031 namespace boost { namespace iostreams {
0032
0033
0034
0035 namespace detail {
0036
0037 template<typename Mode, typename Ch, typename Tr>
0038 struct filtering_stream_traits {
0039 typedef typename
0040 iostreams::select<
0041 mpl::and_<
0042 is_convertible<Mode, input>,
0043 is_convertible<Mode, output>
0044 >,
0045 BOOST_IOSTREAMS_BASIC_IOSTREAM(Ch, Tr),
0046 is_convertible<Mode, input>,
0047 BOOST_IOSTREAMS_BASIC_ISTREAM(Ch, Tr),
0048 else_,
0049 BOOST_IOSTREAMS_BASIC_OSTREAM(Ch, Tr)
0050 >::type stream_type;
0051 typedef typename
0052 iostreams::select<
0053 mpl::and_<
0054 is_convertible<Mode, input>,
0055 is_convertible<Mode, output>
0056 >,
0057 iostream_tag,
0058 is_convertible<Mode, input>,
0059 istream_tag,
0060 else_,
0061 ostream_tag
0062 >::type stream_tag;
0063 };
0064
0065 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
0066 # pragma warning(push)
0067
0068 # pragma warning(disable: 4250)
0069 #endif
0070
0071 template<typename Chain, typename Access>
0072 class filtering_stream_base
0073 : public access_control<
0074 boost::iostreams::detail::chain_client<Chain>,
0075 Access
0076 >,
0077 public filtering_stream_traits<
0078 typename Chain::mode,
0079 typename Chain::char_type,
0080 typename Chain::traits_type
0081 >::stream_type
0082 {
0083 public:
0084 typedef Chain chain_type;
0085 typedef access_control<
0086 boost::iostreams::detail::chain_client<Chain>,
0087 Access
0088 > client_type;
0089 protected:
0090 typedef typename
0091 filtering_stream_traits<
0092 typename Chain::mode,
0093 typename Chain::char_type,
0094 typename Chain::traits_type
0095 >::stream_type stream_type;
0096 filtering_stream_base() : stream_type(0) { this->set_chain(&chain_); }
0097 private:
0098 void notify() { this->rdbuf(chain_.empty() ? 0 : &chain_.front()); }
0099 Chain chain_;
0100 };
0101
0102 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
0103 # pragma warning(pop)
0104 #endif
0105
0106 }
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 #define BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(name_, chain_type_, default_char_) \
0124 template< typename Mode, \
0125 typename Ch = default_char_, \
0126 typename Tr = BOOST_IOSTREAMS_CHAR_TRAITS(Ch), \
0127 typename Alloc = std::allocator<Ch>, \
0128 typename Access = public_ > \
0129 class name_ \
0130 : public boost::iostreams::detail::filtering_stream_base< \
0131 chain_type_<Mode, Ch, Tr, Alloc>, Access \
0132 > \
0133 { \
0134 public: \
0135 typedef Ch char_type; \
0136 struct category \
0137 : Mode, \
0138 closable_tag, \
0139 detail::filtering_stream_traits<Mode, Ch, Tr>::stream_tag \
0140 { }; \
0141 BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) \
0142 typedef Mode mode; \
0143 typedef chain_type_<Mode, Ch, Tr, Alloc> chain_type; \
0144 name_() { } \
0145 BOOST_IOSTREAMS_DEFINE_PUSH_CONSTRUCTOR(name_, mode, Ch, push_impl) \
0146 ~name_() { \
0147 if (this->is_complete()) \
0148 this->rdbuf()->BOOST_IOSTREAMS_PUBSYNC(); \
0149 } \
0150 private: \
0151 typedef access_control< \
0152 boost::iostreams::detail::chain_client< \
0153 chain_type_<Mode, Ch, Tr, Alloc> \
0154 >, \
0155 Access \
0156 > client_type; \
0157 template<typename T> \
0158 void push_impl(const T& t BOOST_IOSTREAMS_PUSH_PARAMS()) \
0159 { client_type::push(t BOOST_IOSTREAMS_PUSH_ARGS()); } \
0160 }; \
0161
0162
0163 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
0164 # pragma warning(push)
0165
0166 # pragma warning(disable: 4250)
0167 #endif
0168
0169 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(filtering_stream, boost::iostreams::chain, char)
0170 BOOST_IOSTREAMS_DEFINE_FILTER_STREAM(wfiltering_stream, boost::iostreams::chain, wchar_t)
0171
0172 #if defined(BOOST_MSVC) && (BOOST_MSVC == 1700)
0173 # pragma warning(pop)
0174 #endif
0175
0176 typedef filtering_stream<input> filtering_istream;
0177 typedef filtering_stream<output> filtering_ostream;
0178 typedef wfiltering_stream<input> filtering_wistream;
0179 typedef wfiltering_stream<output> filtering_wostream;
0180
0181
0182
0183 } }
0184
0185 #include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC
0186
0187 #endif