PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/iostreams/detail/resolve.hpp

http://hadesmem.googlecode.com/
C++ Header | 235 lines | 184 code | 39 blank | 12 comment | 7 complexity | 54ddb7e931440fdfef59fedee29f9b75 MD5 | raw file
  1// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2// (C) Copyright 2003-2007 Jonathan Turkanis
  3// Distributed under the Boost Software License, Version 1.0. (See accompanying
  4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5
  6// See http://www.boost.org/libs/iostreams for documentation.
  7
  8#ifndef BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
  9#define BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED
 10
 11#if defined(_MSC_VER) && (_MSC_VER >= 1020)
 12# pragma once
 13#endif              
 14
 15#include <boost/config.hpp> // partial spec, put size_t in std.
 16#include <cstddef>          // std::size_t.
 17#include <boost/detail/is_incrementable.hpp>
 18#include <boost/detail/workaround.hpp>
 19#include <boost/iostreams/detail/adapter/mode_adapter.hpp>
 20#include <boost/iostreams/detail/adapter/output_iterator_adapter.hpp>
 21#include <boost/iostreams/detail/adapter/range_adapter.hpp>
 22#include <boost/iostreams/detail/config/gcc.hpp>
 23#include <boost/iostreams/detail/config/overload_resolution.hpp>
 24#include <boost/iostreams/detail/config/wide_streams.hpp>
 25#include <boost/iostreams/detail/enable_if_stream.hpp>
 26#include <boost/iostreams/detail/is_dereferenceable.hpp>
 27#include <boost/iostreams/detail/is_iterator_range.hpp>
 28#include <boost/iostreams/detail/select.hpp>
 29#include <boost/iostreams/detail/wrap_unwrap.hpp>
 30#include <boost/iostreams/device/array.hpp>
 31#include <boost/iostreams/traits.hpp>
 32#include <boost/mpl/and.hpp>
 33#include <boost/mpl/bool.hpp> // true_.
 34#include <boost/mpl/if.hpp>
 35#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
 36# include <boost/range/iterator_range.hpp>
 37#endif // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
 38#include <boost/type_traits/is_array.hpp>
 39
 40// Must come last.
 41#include <boost/iostreams/detail/config/disable_warnings.hpp> // VC7.1 C4224.
 42
 43namespace boost { namespace iostreams { namespace detail {
 44
 45//------------------Definition of resolve-------------------------------------//
 46
 47#ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //-------------------------//
 48
 49template<typename Mode, typename Ch, typename T>
 50struct resolve_traits {
 51    typedef typename 
 52            mpl::if_<
 53                boost::detail::is_incrementable<T>,
 54                output_iterator_adapter<Mode, Ch, T>,
 55                const T&
 56            >::type type;
 57};
 58
 59# ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------//
 60
 61template<typename Mode, typename Ch, typename T>
 62typename resolve_traits<Mode, Ch, T>::type
 63resolve( const T& t 
 64         BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
 65
 66         // I suspect that the compilers which require this workaround may
 67         // be correct, but I'm not sure why :(
 68         #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(810)) ||\
 69             BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) || \
 70             BOOST_WORKAROUND(BOOST_IOSTREAMS_GCC, BOOST_TESTED_AT(400)) ||\
 71             BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(1110))
 72             /**/
 73         , typename disable_if< is_iterator_range<T> >::type* = 0
 74         #endif
 75         )
 76{
 77    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
 78    return return_type(t);
 79}
 80
 81template<typename Mode, typename Ch, typename Tr>
 82mode_adapter< Mode, std::basic_streambuf<Ch, Tr> > 
 83resolve(std::basic_streambuf<Ch, Tr>& sb)
 84{ return mode_adapter< Mode, std::basic_streambuf<Ch, Tr> >(wrap(sb)); }
 85
 86template<typename Mode, typename Ch, typename Tr>
 87mode_adapter< Mode, std::basic_istream<Ch, Tr> > 
 88resolve(std::basic_istream<Ch, Tr>& is)
 89{ return mode_adapter< Mode, std::basic_istream<Ch, Tr> >(wrap(is)); }
 90
 91template<typename Mode, typename Ch, typename Tr>
 92mode_adapter< Mode, std::basic_ostream<Ch, Tr> > 
 93resolve(std::basic_ostream<Ch, Tr>& os)
 94{ return mode_adapter< Mode, std::basic_ostream<Ch, Tr> >(wrap(os)); }
 95
 96template<typename Mode, typename Ch, typename Tr>
 97mode_adapter< Mode, std::basic_iostream<Ch, Tr> > 
 98resolve(std::basic_iostream<Ch, Tr>& io)
 99{ return mode_adapter< Mode, std::basic_iostream<Ch, Tr> >(wrap(io)); }
100
101template<typename Mode, typename Ch, std::size_t N>
102array_adapter<Mode, Ch> resolve(Ch (&array)[N])
103{ return array_adapter<Mode, Ch>(array); }
104
105#  if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
106    template<typename Mode, typename Ch, typename Iter>
107    range_adapter< Mode, boost::iterator_range<Iter> > 
108    resolve(const boost::iterator_range<Iter>& rng)
109    { return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
110#  endif // #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
111
112# else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------//
113
114template<typename Mode, typename Ch, typename T>
115typename resolve_traits<Mode, Ch, T>::type
116resolve( const T& t 
117         BOOST_IOSTREAMS_DISABLE_IF_STREAM(T)
118         #if defined(__GNUC__)
119         , typename disable_if< is_iterator_range<T> >::type* = 0
120         #endif
121         )
122{
123    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
124    return return_type(t);
125}
126
127template<typename Mode, typename Ch>
128mode_adapter<Mode, std::streambuf> 
129resolve(std::streambuf& sb) 
130{ return mode_adapter<Mode, std::streambuf>(wrap(sb)); }
131
132template<typename Mode, typename Ch>
133mode_adapter<Mode, std::istream> 
134resolve(std::istream& is)
135{ return mode_adapter<Mode, std::istream>(wrap(is)); }
136
137template<typename Mode, typename Ch>
138mode_adapter<Mode, std::ostream> 
139resolve(std::ostream& os)
140{ return mode_adapter<Mode, std::ostream>(wrap(os)); }
141
142template<typename Mode, typename Ch>
143mode_adapter<Mode, std::iostream> 
144resolve(std::iostream& io)
145{ return mode_adapter<Mode, std::iostream>(wrap(io)); }
146
147template<typename Mode, typename Ch, std::size_t N>
148array_adapter<Mode, Ch> resolve(Ch (&array)[N])
149{ return array_adapter<Mode, Ch>(array); }
150
151template<typename Mode, typename Ch, typename Iter>
152range_adapter< Mode, boost::iterator_range<Iter> > 
153resolve(const boost::iterator_range<Iter>& rng)
154{ return range_adapter< Mode, boost::iterator_range<Iter> >(rng); }
155
156# endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------//
157#else // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //----------------//
158
159template<typename Mode, typename Ch, typename T>
160struct resolve_traits {
161    // Note: test for is_iterator_range must come before test for output
162    // iterator.
163    typedef typename 
164            iostreams::select<  // Disambiguation for Tru64.
165                is_std_io<T>,
166                mode_adapter<Mode, T>,
167                is_iterator_range<T>,
168                range_adapter<Mode, T>,
169                is_dereferenceable<T>,
170                output_iterator_adapter<Mode, Ch, T>,
171                is_array<T>,
172                array_adapter<Mode, T>,
173                else_,
174                #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
175                    const T&
176                #else
177                    T
178                #endif
179            >::type type;
180};
181
182template<typename Mode, typename Ch, typename T>
183typename resolve_traits<Mode, Ch, T>::type 
184resolve(const T& t, mpl::true_)
185{   // Bad overload resolution.
186    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
187    return return_type(wrap(const_cast<T&>(t)));
188}
189
190template<typename Mode, typename Ch, typename T>
191typename resolve_traits<Mode, Ch, T>::type 
192resolve(const T& t, mpl::false_)
193{ 
194    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
195    return return_type(t);
196}
197
198template<typename Mode, typename Ch, typename T>
199typename resolve_traits<Mode, Ch, T>::type 
200resolve(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
201{ return resolve<Mode, Ch>(t, is_std_io<T>()); }
202
203# if !BOOST_WORKAROUND(__BORLANDC__, < 0x600) && \
204     !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \
205     !defined(__GNUC__) // ---------------------------------------------------//
206
207template<typename Mode, typename Ch, typename T>
208typename resolve_traits<Mode, Ch, T>::type 
209resolve(T& t, mpl::true_)
210{ 
211    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
212    return return_type(wrap(t));
213}
214
215template<typename Mode, typename Ch, typename T>
216typename resolve_traits<Mode, Ch, T>::type 
217resolve(T& t, mpl::false_)
218{ 
219    typedef typename resolve_traits<Mode, Ch, T>::type return_type;
220    return return_type(t);
221}
222
223template<typename Mode, typename Ch, typename T>
224typename resolve_traits<Mode, Ch, T>::type 
225resolve(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T))
226{ return resolve<Mode, Ch>(t, is_std_io<T>()); }
227
228# endif // Borland 5.x, VC6-7.0 or GCC 2.9x //--------------------------------//
229#endif // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //---------------//
230
231} } } // End namespaces detail, iostreams, boost.
232
233#include <boost/iostreams/detail/config/enable_warnings.hpp> // VC7.1 4224.
234
235#endif // BOOST_IOSTREAMS_DETAIL_RESOLVE_HPP_INCLUDED