1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/iostreams/combine.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,233 @@
1.4 +// (C) Copyright Jonathan Turkanis 2003.
1.5 +// Distributed under the Boost Software License, Version 1.0. (See accompanying
1.6 +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
1.7 +
1.8 +// See http://www.boost.org/libs/iostreams for documentation.
1.9 +
1.10 +// To do: add support for random-access.
1.11 +
1.12 +#ifndef BOOST_IOSTREAMS_COMBINE_HPP_INCLUDED
1.13 +#define BOOST_IOSTREAMS_COMBINE_HPP_INCLUDED
1.14 +
1.15 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1.16 +# pragma once
1.17 +#endif
1.18 +
1.19 +#include <boost/config.hpp> // NO_STD_LOCALE, DEDUCED_TYPENAME.
1.20 +#ifndef BOOST_NO_STD_LOCALE
1.21 +# include <locale>
1.22 +#endif
1.23 +#include <boost/iostreams/detail/ios.hpp>
1.24 +#include <boost/iostreams/detail/wrap_unwrap.hpp>
1.25 +#include <boost/iostreams/traits.hpp>
1.26 +#include <boost/iostreams/operations.hpp>
1.27 +#include <boost/mpl/if.hpp>
1.28 +#include <boost/static_assert.hpp>
1.29 +#include <boost/type_traits/is_convertible.hpp>
1.30 +#include <boost/type_traits/is_same.hpp>
1.31 +
1.32 +namespace boost { namespace iostreams {
1.33 +
1.34 +namespace detail {
1.35 +
1.36 +//
1.37 +// Template name: combined_device.
1.38 +// Description: Model of Device defined in terms of a Source/Sink pair.
1.39 +// Template paramters:
1.40 +// Source - A model of Source, with the same char_type and traits_type
1.41 +// as Sink.
1.42 +// Sink - A model of Sink, with the same char_type and traits_type
1.43 +// as Source.
1.44 +//
1.45 +template<typename Source, typename Sink>
1.46 +class combined_device {
1.47 +public:
1.48 + typedef typename char_type_of<Source>::type char_type;
1.49 + struct category
1.50 + : bidirectional,
1.51 + device_tag,
1.52 + closable_tag,
1.53 + localizable_tag
1.54 + { };
1.55 + combined_device(const Source& src, const Sink& snk);
1.56 + std::streamsize read(char_type* s, std::streamsize n);
1.57 + std::streamsize write(const char_type* s, std::streamsize n);
1.58 + void close(BOOST_IOS::openmode);
1.59 + #ifndef BOOST_NO_STD_LOCALE
1.60 + void imbue(const std::locale& loc);
1.61 + #endif
1.62 +private:
1.63 + typedef typename char_type_of<Sink>::type sink_char_type;
1.64 + BOOST_STATIC_ASSERT((is_same<char_type, sink_char_type>::value));
1.65 + Source src_;
1.66 + Sink sink_;
1.67 +};
1.68 +
1.69 +//
1.70 +// Template name: combined_filter.
1.71 +// Description: Model of Device defined in terms of a Source/Sink pair.
1.72 +// Template paramters:
1.73 +// InputFilter - A model of InputFilter, with the same char_type as
1.74 +// OutputFilter.
1.75 +// OutputFilter - A model of OutputFilter, with the same char_type as
1.76 +// InputFilter.
1.77 +//
1.78 +template<typename InputFilter, typename OutputFilter>
1.79 +class combined_filter {
1.80 +private:
1.81 + typedef typename category_of<InputFilter>::type in_category;
1.82 + typedef typename category_of<OutputFilter>::type out_category;
1.83 +public:
1.84 + typedef typename char_type_of<InputFilter>::type char_type;
1.85 + struct category
1.86 + : multichar_bidirectional_filter_tag,
1.87 + closable_tag,
1.88 + localizable_tag
1.89 + { };
1.90 + combined_filter(const InputFilter& in, const OutputFilter& out);
1.91 +
1.92 + template<typename Source>
1.93 + std::streamsize read(Source& src, char_type* s, std::streamsize n)
1.94 + { return boost::iostreams::read(in_, src, s, n); }
1.95 +
1.96 + template<typename Sink>
1.97 + std::streamsize write(Sink& snk, const char_type* s, std::streamsize n)
1.98 + { return boost::iostreams::write(out_, snk, s, n); }
1.99 +
1.100 + template<typename Sink>
1.101 + void close(Sink& snk, BOOST_IOS::openmode which)
1.102 + {
1.103 + if (which & BOOST_IOS::in)
1.104 + iostreams::close(in_, snk, which);
1.105 + if (which & BOOST_IOS::out)
1.106 + iostreams::close(out_, snk, which);
1.107 + }
1.108 + #ifndef BOOST_NO_STD_LOCALE
1.109 + void imbue(const std::locale& loc);
1.110 + #endif
1.111 +private:
1.112 + typedef typename char_type_of<OutputFilter>::type output_char_type;
1.113 + BOOST_STATIC_ASSERT((is_same<char_type, output_char_type>::value));
1.114 + InputFilter in_;
1.115 + OutputFilter out_;
1.116 +};
1.117 +
1.118 +template<typename In, typename Out>
1.119 +struct combination_traits
1.120 + : mpl::if_<
1.121 + is_device<In>,
1.122 + combined_device<
1.123 + typename wrapped_type<In>::type,
1.124 + typename wrapped_type<Out>::type
1.125 + >,
1.126 + combined_filter<
1.127 + typename wrapped_type<In>::type,
1.128 + typename wrapped_type<Out>::type
1.129 + >
1.130 + >
1.131 + { };
1.132 +
1.133 +} // End namespace detail.
1.134 +
1.135 +template<typename In, typename Out>
1.136 +struct combination : detail::combination_traits<In, Out>::type {
1.137 + typedef typename detail::combination_traits<In, Out>::type base_type;
1.138 + typedef typename detail::wrapped_type<In>::type in_type;
1.139 + typedef typename detail::wrapped_type<Out>::type out_type;
1.140 + combination(const in_type& in, const out_type& out)
1.141 + : base_type(in, out) { }
1.142 +};
1.143 +
1.144 +namespace detail {
1.145 +
1.146 +// Workaround for VC6 ETI bug.
1.147 +template<typename In, typename Out>
1.148 +struct combine_traits {
1.149 + typedef combination<
1.150 + BOOST_DEDUCED_TYPENAME detail::unwrapped_type<In>::type,
1.151 + BOOST_DEDUCED_TYPENAME detail::unwrapped_type<Out>::type
1.152 + > type;
1.153 +};
1.154 +
1.155 +} // End namespace detail.
1.156 +
1.157 +//
1.158 +// Template name: combine.
1.159 +// Description: Takes a Source/Sink pair or InputFilter/OutputFilter pair and
1.160 +// returns a Reource or Filter which performs input using the first member
1.161 +// of the pair and output using the second member of the pair.
1.162 +// Template paramters:
1.163 +// In - A model of Source or InputFilter, with the same char_type as Out.
1.164 +// Out - A model of Sink or OutputFilter, with the same char_type as In.
1.165 +//
1.166 +template<typename In, typename Out>
1.167 +typename detail::combine_traits<In, Out>::type
1.168 +combine(const In& in, const Out& out)
1.169 +{
1.170 + typedef typename detail::combine_traits<In, Out>::type return_type;
1.171 + return return_type(in, out);
1.172 +}
1.173 +
1.174 +//----------------------------------------------------------------------------//
1.175 +
1.176 +namespace detail {
1.177 +
1.178 +//--------------Implementation of combined_device-----------------------------//
1.179 +
1.180 +template<typename Source, typename Sink>
1.181 +inline combined_device<Source, Sink>::combined_device
1.182 + (const Source& src, const Sink& snk)
1.183 + : src_(src), sink_(snk) { }
1.184 +
1.185 +template<typename Source, typename Sink>
1.186 +inline std::streamsize
1.187 +combined_device<Source, Sink>::read(char_type* s, std::streamsize n)
1.188 +{ return iostreams::read(src_, s, n); }
1.189 +
1.190 +template<typename Source, typename Sink>
1.191 +inline std::streamsize
1.192 +combined_device<Source, Sink>::write(const char_type* s, std::streamsize n)
1.193 +{ return iostreams::write(sink_, s, n); }
1.194 +
1.195 +template<typename Source, typename Sink>
1.196 +inline void
1.197 +combined_device<Source, Sink>::close(BOOST_IOS::openmode which)
1.198 +{
1.199 + if (which & BOOST_IOS::in)
1.200 + iostreams::close(src_, which);
1.201 + if (which & BOOST_IOS::out)
1.202 + iostreams::close(sink_, which);
1.203 +}
1.204 +
1.205 +#ifndef BOOST_NO_STD_LOCALE
1.206 + template<typename Source, typename Sink>
1.207 + void combined_device<Source, Sink>::imbue(const std::locale& loc)
1.208 + {
1.209 + iostreams::imbue(src_, loc);
1.210 + iostreams::imbue(sink_, loc);
1.211 + }
1.212 +#endif
1.213 +
1.214 +//--------------Implementation of filter_pair---------------------------------//
1.215 +
1.216 +template<typename InputFilter, typename OutputFilter>
1.217 +inline combined_filter<InputFilter, OutputFilter>::combined_filter
1.218 + (const InputFilter& in, const OutputFilter& out) : in_(in), out_(out)
1.219 + { }
1.220 +
1.221 +#ifndef BOOST_NO_STD_LOCALE
1.222 + template<typename InputFilter, typename OutputFilter>
1.223 + void combined_filter<InputFilter, OutputFilter>::imbue
1.224 + (const std::locale& loc)
1.225 + {
1.226 + iostreams::imbue(in_, loc);
1.227 + iostreams::imbue(out_, loc);
1.228 + }
1.229 +#endif
1.230 +
1.231 +
1.232 +} // End namespace detail.
1.233 +
1.234 +} } // End namespaces iostreams, boost.
1.235 +
1.236 +#endif // #ifndef BOOST_IOSTREAMS_COMBINE_HPP_INCLUDED