os/ossrv/ossrv_pub/boost_apis/boost/iostreams/detail/resolve.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/iostreams/detail/resolve.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,235 @@
     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 +#ifndef BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
    1.11 +#define BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
    1.12 +
    1.13 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
    1.14 +# pragma once
    1.15 +#endif              
    1.16 +
    1.17 +#include <boost/config.hpp> // partial spec, put size_t in std.
    1.18 +#include <cstddef>          // std::size_t.
    1.19 +#include <boost/detail/is_incrementable.hpp>
    1.20 +#include <boost/detail/workaround.hpp>
    1.21 +#include <boost/iostreams/detail/adapter/mode_adapter.hpp>
    1.22 +#include <boost/iostreams/detail/adapter/output_iterator_adapter.hpp>
    1.23 +#include <boost/iostreams/detail/adapter/range_adapter.hpp>
    1.24 +#include <boost/iostreams/detail/config/gcc.hpp>
    1.25 +#include <boost/iostreams/detail/config/overload_resolution.hpp>
    1.26 +#include <boost/iostreams/detail/config/wide_streams.hpp>
    1.27 +#include <boost/iostreams/detail/enable_if_stream.hpp>
    1.28 +#include <boost/iostreams/detail/is_dereferenceable.hpp>
    1.29 +#include <boost/iostreams/detail/is_iterator_range.hpp>
    1.30 +#include <boost/iostreams/detail/select.hpp>
    1.31 +#include <boost/iostreams/detail/wrap_unwrap.hpp>
    1.32 +#include <boost/iostreams/device/array.hpp>
    1.33 +#include <boost/iostreams/traits.hpp>
    1.34 +#include <boost/mpl/and.hpp>
    1.35 +#include <boost/mpl/bool.hpp> // true_.
    1.36 +#include <boost/mpl/if.hpp>
    1.37 +#include <boost/range/iterator_range.hpp>
    1.38 +#include <boost/type_traits/is_array.hpp>
    1.39 +
    1.40 +// Must come last.
    1.41 +#include <boost/iostreams/detail/config/disable_warnings.hpp> // VC7.1 C4224.
    1.42 +
    1.43 +namespace boost { namespace iostreams { namespace detail {
    1.44 +
    1.45 +//------------------Definition of resolve-------------------------------------//
    1.46 +
    1.47 +#ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //-------------------------//
    1.48 +
    1.49 +template<typename Mode, typename Ch, typename T>
    1.50 +struct resolve_traits {
    1.51 +    typedef typename 
    1.52 +            mpl::if_<
    1.53 +                mpl::and_<
    1.54 +                    boost::detail::is_incrementable<T>, // Must come first
    1.55 +                    is_dereferenceable<T>               // for CW 9.[0-4]
    1.56 +                >,
    1.57 +                output_iterator_adapter<Mode, Ch, T>,
    1.58 +                const T&
    1.59 +            >::type type;
    1.60 +};
    1.61 +
    1.62 +# ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------//
    1.63 +
    1.64 +template<typename Mode, typename Ch, typename T>
    1.65 +typename resolve_traits<Mode, Ch, T>::type
    1.66 +resolve( const T& t 
    1.67 +         BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
    1.68 +
    1.69 +         // I suspect that the compilers which require this workaround may
    1.70 +         // be correct, but I'm not sure why :(
    1.71 +         #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(810)) ||\
    1.72 +             BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) || \
    1.73 +             BOOST_WORKAROUND(BOOST_IOSTREAMS_GCC, BOOST_TESTED_AT(400)) \
    1.74 +             /**/
    1.75 +         , typename disable_if< is_iterator_range<T> >::type* = 0
    1.76 +         #endif
    1.77 +         )
    1.78 +{
    1.79 +    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
    1.80 +    return return_type(t);
    1.81 +}
    1.82 +
    1.83 +template<typename Mode, typename Ch, typename Tr>
    1.84 +mode_adapter< Mode, std::basic_streambuf<Ch, Tr> > 
    1.85 +resolve(std::basic_streambuf<Ch, Tr>& sb)
    1.86 +{ return mode_adapter< Mode, std::basic_streambuf<Ch, Tr> >(wrap(sb)); }
    1.87 +
    1.88 +template<typename Mode, typename Ch, typename Tr>
    1.89 +mode_adapter< Mode, std::basic_istream<Ch, Tr> > 
    1.90 +resolve(std::basic_istream<Ch, Tr>& is)
    1.91 +{ return mode_adapter< Mode, std::basic_istream<Ch, Tr> >(wrap(is)); }
    1.92 +
    1.93 +template<typename Mode, typename Ch, typename Tr>
    1.94 +mode_adapter< Mode, std::basic_ostream<Ch, Tr> > 
    1.95 +resolve(std::basic_ostream<Ch, Tr>& os)
    1.96 +{ return mode_adapter< Mode, std::basic_ostream<Ch, Tr> >(wrap(os)); }
    1.97 +
    1.98 +template<typename Mode, typename Ch, typename Tr>
    1.99 +mode_adapter< Mode, std::basic_iostream<Ch, Tr> > 
   1.100 +resolve(std::basic_iostream<Ch, Tr>& io)
   1.101 +{ return mode_adapter< Mode, std::basic_iostream<Ch, Tr> >(wrap(io)); }
   1.102 +
   1.103 +template<typename Mode, typename Ch, std::size_t N>
   1.104 +array_adapter<Mode, Ch> resolve(Ch (&array)[N])
   1.105 +{ return array_adapter<Mode, Ch>(array); }
   1.106 +
   1.107 +template<typename Mode, typename Ch, typename Iter>
   1.108 +range_adapter< Mode, boost::iterator_range<Iter> > 
   1.109 +resolve(const boost::iterator_range<Iter>& rng)
   1.110 +{ return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
   1.111 +
   1.112 +# else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------//
   1.113 +
   1.114 +template<typename Mode, typename Ch, typename T>
   1.115 +typename resolve_traits<Mode, Ch, T>::type
   1.116 +resolve( const T& t 
   1.117 +         BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
   1.118 +         #if defined(__GNUC__)
   1.119 +         , typename disable_if< is_iterator_range<T> >::type* = 0
   1.120 +         #endif
   1.121 +         )
   1.122 +{
   1.123 +    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
   1.124 +    return return_type(t);
   1.125 +}
   1.126 +
   1.127 +template<typename Mode, typename Ch>
   1.128 +mode_adapter<Mode, std::streambuf> 
   1.129 +resolve(std::streambuf& sb) 
   1.130 +{ return mode_adapter<Mode, std::streambuf>(wrap(sb)); }
   1.131 +
   1.132 +template<typename Mode, typename Ch>
   1.133 +mode_adapter<Mode, std::istream> 
   1.134 +resolve(std::istream& is)
   1.135 +{ return mode_adapter<Mode, std::istream>(wrap(is)); }
   1.136 +
   1.137 +template<typename Mode, typename Ch>
   1.138 +mode_adapter<Mode, std::ostream> 
   1.139 +resolve(std::ostream& os)
   1.140 +{ return mode_adapter<Mode, std::ostream>(wrap(os)); }
   1.141 +
   1.142 +template<typename Mode, typename Ch>
   1.143 +mode_adapter<Mode, std::iostream> 
   1.144 +resolve(std::iostream& io)
   1.145 +{ return mode_adapter<Mode, std::iostream>(wrap(io)); }
   1.146 +
   1.147 +template<typename Mode, typename Ch, std::size_t N>
   1.148 +array_adapter<Mode, Ch> resolve(Ch (&array)[N])
   1.149 +{ return array_adapter<Mode, Ch>(array); }
   1.150 +
   1.151 +template<typename Mode, typename Ch, typename Iter>
   1.152 +range_adapter< Mode, boost::iterator_range<Iter> > 
   1.153 +resolve(const boost::iterator_range<Iter>& rng)
   1.154 +{ return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
   1.155 +
   1.156 +# endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------//
   1.157 +#else // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //----------------//
   1.158 +
   1.159 +template<typename Mode, typename Ch, typename T>
   1.160 +struct resolve_traits {
   1.161 +    // Note: test for is_iterator_range must come before test for output
   1.162 +    // iterator.
   1.163 +    typedef typename 
   1.164 +            iostreams::select<  // Disambiguation for Tru64.
   1.165 +                is_std_io<T>,
   1.166 +                mode_adapter<Mode, T>,
   1.167 +                is_iterator_range<T>,
   1.168 +                range_adapter<Mode, T>,
   1.169 +                mpl::and_<
   1.170 +                    is_dereferenceable<T>,
   1.171 +                    boost::detail::is_incrementable<T>
   1.172 +                >,
   1.173 +                output_iterator_adapter<Mode, Ch, T>,
   1.174 +                is_array<T>,
   1.175 +                array_adapter<Mode, T>,
   1.176 +                else_,
   1.177 +                #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
   1.178 +                    const T&
   1.179 +                #else
   1.180 +                    T
   1.181 +                #endif
   1.182 +            >::type type;
   1.183 +};
   1.184 +
   1.185 +template<typename Mode, typename Ch, typename T>
   1.186 +typename resolve_traits<Mode, Ch, T>::type 
   1.187 +resolve(const T& t, mpl::true_)
   1.188 +{   // Bad overload resolution.
   1.189 +    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
   1.190 +    return return_type(wrap(const_cast<T&>(t)));
   1.191 +}
   1.192 +
   1.193 +template<typename Mode, typename Ch, typename T>
   1.194 +typename resolve_traits<Mode, Ch, T>::type 
   1.195 +resolve(const T& t, mpl::false_)
   1.196 +{ 
   1.197 +    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
   1.198 +    return return_type(t);
   1.199 +}
   1.200 +
   1.201 +template<typename Mode, typename Ch, typename T>
   1.202 +typename resolve_traits<Mode, Ch, T>::type 
   1.203 +resolve(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
   1.204 +{ return resolve<Mode, Ch>(t, is_std_io<T>()); }
   1.205 +
   1.206 +# if !BOOST_WORKAROUND(__BORLANDC__, < 0x600) && \
   1.207 +     !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \
   1.208 +     !defined(__GNUC__) // ---------------------------------------------------//
   1.209 +
   1.210 +template<typename Mode, typename Ch, typename T>
   1.211 +typename resolve_traits<Mode, Ch, T>::type 
   1.212 +resolve(T& t, mpl::true_)
   1.213 +{ 
   1.214 +    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
   1.215 +    return return_type(wrap(t));
   1.216 +}
   1.217 +
   1.218 +template<typename Mode, typename Ch, typename T>
   1.219 +typename resolve_traits<Mode, Ch, T>::type 
   1.220 +resolve(T& t, mpl::false_)
   1.221 +{ 
   1.222 +    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
   1.223 +    return return_type(t);
   1.224 +}
   1.225 +
   1.226 +template<typename Mode, typename Ch, typename T>
   1.227 +typename resolve_traits<Mode, Ch, T>::type 
   1.228 +resolve(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T))
   1.229 +{ return resolve<Mode, Ch>(t, is_std_io<T>()); }
   1.230 +
   1.231 +# endif // Borland 5.x, VC6-7.0 or GCC 2.9x //--------------------------------//
   1.232 +#endif // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //---------------//
   1.233 +
   1.234 +} } } // End namespaces detail, iostreams, boost.
   1.235 +
   1.236 +#include <boost/iostreams/detail/config/enable_warnings.hpp> // VC7.1 4224.
   1.237 +
   1.238 +#endif // BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED