Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:50

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2003-2007 Jonathan Turkanis
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0005 
0006 // See http://www.boost.org/libs/iostreams for documentation.
0007 
0008 #ifndef BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
0010 
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif              
0014 
0015 #include <boost/config.hpp> // partial spec, put size_t in std.
0016 #include <cstddef>          // std::size_t.
0017 #include <boost/detail/is_incrementable.hpp>
0018 #include <boost/detail/workaround.hpp>
0019 #include <boost/iostreams/detail/adapter/mode_adapter.hpp>
0020 #include <boost/iostreams/detail/adapter/output_iterator_adapter.hpp>
0021 #include <boost/iostreams/detail/adapter/range_adapter.hpp>
0022 #include <boost/iostreams/detail/config/gcc.hpp>
0023 #include <boost/iostreams/detail/config/overload_resolution.hpp>
0024 #include <boost/iostreams/detail/config/wide_streams.hpp>
0025 #include <boost/iostreams/detail/enable_if_stream.hpp>
0026 #include <boost/iostreams/detail/is_dereferenceable.hpp>
0027 #include <boost/iostreams/detail/is_iterator_range.hpp>
0028 #include <boost/iostreams/detail/select.hpp>
0029 #include <boost/iostreams/detail/wrap_unwrap.hpp>
0030 #include <boost/iostreams/device/array.hpp>
0031 #include <boost/iostreams/traits.hpp>
0032 #include <boost/mpl/and.hpp>
0033 #include <boost/mpl/bool.hpp> // true_.
0034 #include <boost/mpl/if.hpp>
0035 #include <boost/range/iterator_range.hpp>
0036 #include <boost/type_traits/is_array.hpp>
0037 
0038 // Must come last.
0039 #include <boost/iostreams/detail/config/disable_warnings.hpp> // VC7.1 C4224.
0040 
0041 namespace boost { namespace iostreams { namespace detail {
0042 
0043 //------------------Definition of resolve-------------------------------------//
0044 
0045 #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //-------------------------//
0046 
0047 template<typename Mode, typename Ch, typename T>
0048 struct resolve_traits {
0049     typedef typename 
0050             mpl::if_<
0051                 boost::detail::is_incrementable<T>,
0052                 output_iterator_adapter<Mode, Ch, T>,
0053                 const T&
0054             >::type type;
0055 };
0056 
0057 # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------//
0058 
0059 template<typename Mode, typename Ch, typename T>
0060 typename resolve_traits<Mode, Ch, T>::type
0061 resolve( const T& t 
0062          BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
0063 
0064          // I suspect that the compilers which require this workaround may
0065          // be correct, but I'm not sure why :(
0066          #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(810)) ||\
0067              BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) || \
0068              BOOST_WORKAROUND(BOOST_IOSTREAMS_GCC, BOOST_TESTED_AT(400)) ||\
0069              BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(1110))
0070              /**/
0071          , typename disable_if< is_iterator_range<T> >::type* = 0
0072          #endif
0073          )
0074 {
0075     typedef typename resolve_traits<Mode, Ch, T>::type return_type;
0076     return return_type(t);
0077 }
0078 
0079 template<typename Mode, typename Ch, typename Tr>
0080 mode_adapter< Mode, std::basic_streambuf<Ch, Tr> > 
0081 resolve(std::basic_streambuf<Ch, Tr>& sb)
0082 { return mode_adapter< Mode, std::basic_streambuf<Ch, Tr> >(wrap(sb)); }
0083 
0084 template<typename Mode, typename Ch, typename Tr>
0085 mode_adapter< Mode, std::basic_istream<Ch, Tr> > 
0086 resolve(std::basic_istream<Ch, Tr>& is)
0087 { return mode_adapter< Mode, std::basic_istream<Ch, Tr> >(wrap(is)); }
0088 
0089 template<typename Mode, typename Ch, typename Tr>
0090 mode_adapter< Mode, std::basic_ostream<Ch, Tr> > 
0091 resolve(std::basic_ostream<Ch, Tr>& os)
0092 { return mode_adapter< Mode, std::basic_ostream<Ch, Tr> >(wrap(os)); }
0093 
0094 template<typename Mode, typename Ch, typename Tr>
0095 mode_adapter< Mode, std::basic_iostream<Ch, Tr> > 
0096 resolve(std::basic_iostream<Ch, Tr>& io)
0097 { return mode_adapter< Mode, std::basic_iostream<Ch, Tr> >(wrap(io)); }
0098 
0099 template<typename Mode, typename Ch, std::size_t N>
0100 array_adapter<Mode, Ch> resolve(Ch (&array)[N])
0101 { return array_adapter<Mode, Ch>(array); }
0102 
0103 template<typename Mode, typename Ch, typename Iter>
0104 range_adapter< Mode, boost::iterator_range<Iter> >
0105 resolve(const boost::iterator_range<Iter>& rng)
0106 { return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
0107 
0108 # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------//
0109 
0110 template<typename Mode, typename Ch, typename T>
0111 typename resolve_traits<Mode, Ch, T>::type
0112 resolve( const T& t 
0113          BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
0114          #if defined(__GNUC__)
0115          , typename disable_if< is_iterator_range<T> >::type* = 0
0116          #endif
0117          )
0118 {
0119     typedef typename resolve_traits<Mode, Ch, T>::type return_type;
0120     return return_type(t);
0121 }
0122 
0123 template<typename Mode, typename Ch>
0124 mode_adapter<Mode, std::streambuf> 
0125 resolve(std::streambuf& sb) 
0126 { return mode_adapter<Mode, std::streambuf>(wrap(sb)); }
0127 
0128 template<typename Mode, typename Ch>
0129 mode_adapter<Mode, std::istream> 
0130 resolve(std::istream& is)
0131 { return mode_adapter<Mode, std::istream>(wrap(is)); }
0132 
0133 template<typename Mode, typename Ch>
0134 mode_adapter<Mode, std::ostream> 
0135 resolve(std::ostream& os)
0136 { return mode_adapter<Mode, std::ostream>(wrap(os)); }
0137 
0138 template<typename Mode, typename Ch>
0139 mode_adapter<Mode, std::iostream> 
0140 resolve(std::iostream& io)
0141 { return mode_adapter<Mode, std::iostream>(wrap(io)); }
0142 
0143 template<typename Mode, typename Ch, std::size_t N>
0144 array_adapter<Mode, Ch> resolve(Ch (&array)[N])
0145 { return array_adapter<Mode, Ch>(array); }
0146 
0147 template<typename Mode, typename Ch, typename Iter>
0148 range_adapter< Mode, boost::iterator_range<Iter> > 
0149 resolve(const boost::iterator_range<Iter>& rng)
0150 { return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
0151 
0152 # endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------//
0153 #else // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //----------------//
0154 
0155 template<typename Mode, typename Ch, typename T>
0156 struct resolve_traits {
0157     // Note: test for is_iterator_range must come before test for output
0158     // iterator.
0159     typedef typename 
0160             iostreams::select<  // Disambiguation for Tru64.
0161                 is_std_io<T>,
0162                 mode_adapter<Mode, T>,
0163                 is_iterator_range<T>,
0164                 range_adapter<Mode, T>,
0165                 is_dereferenceable<T>,
0166                 output_iterator_adapter<Mode, Ch, T>,
0167                 is_array<T>,
0168                 array_adapter<Mode, T>,
0169                 else_,
0170                 #if !BOOST_WORKAROUND(BOOST_BORLANDC, < 0x600)
0171                     const T&
0172                 #else
0173                     T
0174                 #endif
0175             >::type type;
0176 };
0177 
0178 template<typename Mode, typename Ch, typename T>
0179 typename resolve_traits<Mode, Ch, T>::type 
0180 resolve(const T& t, mpl::true_)
0181 {   // Bad overload resolution.
0182     typedef typename resolve_traits<Mode, Ch, T>::type return_type;
0183     return return_type(wrap(const_cast<T&>(t)));
0184 }
0185 
0186 template<typename Mode, typename Ch, typename T>
0187 typename resolve_traits<Mode, Ch, T>::type 
0188 resolve(const T& t, mpl::false_)
0189 { 
0190     typedef typename resolve_traits<Mode, Ch, T>::type return_type;
0191     return return_type(t);
0192 }
0193 
0194 template<typename Mode, typename Ch, typename T>
0195 typename resolve_traits<Mode, Ch, T>::type 
0196 resolve(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
0197 { return resolve<Mode, Ch>(t, is_std_io<T>()); }
0198 
0199 # if !BOOST_WORKAROUND(BOOST_BORLANDC, < 0x600) && \
0200      !defined(__GNUC__) // ---------------------------------------------------//
0201 
0202 template<typename Mode, typename Ch, typename T>
0203 typename resolve_traits<Mode, Ch, T>::type 
0204 resolve(T& t, mpl::true_)
0205 { 
0206     typedef typename resolve_traits<Mode, Ch, T>::type return_type;
0207     return return_type(wrap(t));
0208 }
0209 
0210 template<typename Mode, typename Ch, typename T>
0211 typename resolve_traits<Mode, Ch, T>::type 
0212 resolve(T& t, mpl::false_)
0213 { 
0214     typedef typename resolve_traits<Mode, Ch, T>::type return_type;
0215     return return_type(t);
0216 }
0217 
0218 template<typename Mode, typename Ch, typename T>
0219 typename resolve_traits<Mode, Ch, T>::type 
0220 resolve(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T))
0221 { return resolve<Mode, Ch>(t, is_std_io<T>()); }
0222 
0223 # endif // Borland 5.x or GCC //--------------------------------//
0224 #endif // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //---------------//
0225 
0226 } } } // End namespaces detail, iostreams, boost.
0227 
0228 #include <boost/iostreams/detail/config/enable_warnings.hpp> // VC7.1 4224.
0229 
0230 #endif // BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED