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