Chris@16
|
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
|
Chris@16
|
2 // (C) Copyright 2005-2007 Jonathan Turkanis
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
Chris@16
|
5
|
Chris@16
|
6 // See http://www.boost.org/libs/iostreams for documentation.
|
Chris@16
|
7
|
Chris@16
|
8 // Note: bidirectional streams are not supported.
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_IOSTREAMS_COMPOSE_HPP_INCLUDED
|
Chris@16
|
11 #define BOOST_IOSTREAMS_COMPOSE_HPP_INCLUDED
|
Chris@16
|
12
|
Chris@16
|
13 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
Chris@16
|
14 # pragma once
|
Chris@16
|
15 #endif
|
Chris@16
|
16
|
Chris@16
|
17 #include <algorithm> // min.
|
Chris@16
|
18 #include <utility> // pair.
|
Chris@16
|
19 #include <boost/config.hpp> // DEDUCED_TYPENAME.
|
Chris@16
|
20 #include <boost/iostreams/categories.hpp>
|
Chris@16
|
21 #include <boost/iostreams/detail/adapter/direct_adapter.hpp>
|
Chris@16
|
22 #include <boost/iostreams/detail/call_traits.hpp>
|
Chris@16
|
23 #include <boost/iostreams/detail/enable_if_stream.hpp>
|
Chris@16
|
24 #include <boost/iostreams/detail/execute.hpp>
|
Chris@16
|
25 #include <boost/iostreams/detail/functional.hpp>
|
Chris@16
|
26 #include <boost/iostreams/operations.hpp>
|
Chris@16
|
27 #include <boost/iostreams/traits.hpp> // mode_of, is_direct.
|
Chris@16
|
28 #include <boost/mpl/if.hpp>
|
Chris@16
|
29 #include <boost/ref.hpp>
|
Chris@16
|
30 #include <boost/static_assert.hpp>
|
Chris@16
|
31 #include <boost/type_traits/is_convertible.hpp>
|
Chris@16
|
32
|
Chris@16
|
33 // Must come last.
|
Chris@16
|
34 #include <boost/iostreams/detail/config/disable_warnings.hpp> // MSVC.
|
Chris@16
|
35
|
Chris@16
|
36 namespace boost { namespace iostreams {
|
Chris@16
|
37
|
Chris@16
|
38 namespace detail {
|
Chris@16
|
39
|
Chris@16
|
40 template< typename First,
|
Chris@16
|
41 typename Second,
|
Chris@16
|
42 typename FirstMode =
|
Chris@16
|
43 BOOST_DEDUCED_TYPENAME mode_of<First>::type,
|
Chris@16
|
44 typename SecondMode =
|
Chris@16
|
45 BOOST_DEDUCED_TYPENAME mode_of<Second>::type >
|
Chris@16
|
46 struct composite_mode
|
Chris@16
|
47 : select<
|
Chris@16
|
48 is_convertible<SecondMode, FirstMode>, FirstMode,
|
Chris@16
|
49 is_convertible<FirstMode, SecondMode>, SecondMode,
|
Chris@16
|
50 is_convertible<SecondMode, input>, input,
|
Chris@16
|
51 else_, output
|
Chris@16
|
52 >
|
Chris@16
|
53 { };
|
Chris@16
|
54
|
Chris@16
|
55 //
|
Chris@16
|
56 // Template name: composite_device.
|
Chris@16
|
57 // Description: Provides a Device view of a Filter, Device pair.
|
Chris@16
|
58 // Template parameters:
|
Chris@16
|
59 // Filter - A model of Filter.
|
Chris@16
|
60 // Device - An indirect model of Device.
|
Chris@16
|
61 //
|
Chris@16
|
62 template< typename Filter,
|
Chris@16
|
63 typename Device,
|
Chris@16
|
64 typename Mode =
|
Chris@16
|
65 BOOST_DEDUCED_TYPENAME composite_mode<Filter, Device>::type >
|
Chris@16
|
66 class composite_device {
|
Chris@16
|
67 private:
|
Chris@16
|
68 typedef typename detail::param_type<Device>::type param_type;
|
Chris@16
|
69 typedef typename mode_of<Filter>::type filter_mode;
|
Chris@16
|
70 typedef typename mode_of<Device>::type device_mode;
|
Chris@16
|
71 typedef typename
|
Chris@16
|
72 iostreams::select< // Disambiguation for Tru64.
|
Chris@16
|
73 is_direct<Device>, direct_adapter<Device>,
|
Chris@16
|
74 is_std_io<Device>, Device&,
|
Chris@16
|
75 else_, Device
|
Chris@16
|
76 >::type value_type;
|
Chris@16
|
77 BOOST_STATIC_ASSERT(is_filter<Filter>::value);
|
Chris@16
|
78 BOOST_STATIC_ASSERT(is_device<Device>::value);
|
Chris@16
|
79 public:
|
Chris@16
|
80 typedef typename char_type_of<Filter>::type char_type;
|
Chris@16
|
81 struct category
|
Chris@16
|
82 : Mode,
|
Chris@16
|
83 device_tag,
|
Chris@16
|
84 closable_tag,
|
Chris@16
|
85 flushable_tag,
|
Chris@16
|
86 localizable_tag,
|
Chris@16
|
87 optimally_buffered_tag
|
Chris@16
|
88 { };
|
Chris@16
|
89 composite_device(const Filter& flt, param_type dev);
|
Chris@16
|
90 std::streamsize read(char_type* s, std::streamsize n);
|
Chris@16
|
91 std::streamsize write(const char_type* s, std::streamsize n);
|
Chris@16
|
92 std::streampos seek( stream_offset off, BOOST_IOS::seekdir way,
|
Chris@16
|
93 BOOST_IOS::openmode which =
|
Chris@16
|
94 BOOST_IOS::in | BOOST_IOS::out );
|
Chris@16
|
95
|
Chris@16
|
96 void close();
|
Chris@16
|
97 void close(BOOST_IOS::openmode which);
|
Chris@16
|
98 bool flush();
|
Chris@16
|
99 std::streamsize optimal_buffer_size() const;
|
Chris@16
|
100
|
Chris@16
|
101 template<typename Locale> // Avoid dependency on <locale>
|
Chris@16
|
102 void imbue(const Locale& loc)
|
Chris@16
|
103 {
|
Chris@16
|
104 iostreams::imbue(filter_, loc);
|
Chris@16
|
105 iostreams::imbue(device_, loc);
|
Chris@16
|
106 }
|
Chris@16
|
107
|
Chris@16
|
108 Filter& first() { return filter_; }
|
Chris@16
|
109 Device& second() { return device_; }
|
Chris@16
|
110 private:
|
Chris@16
|
111 Filter filter_;
|
Chris@16
|
112 value_type device_;
|
Chris@16
|
113 };
|
Chris@16
|
114
|
Chris@16
|
115 //
|
Chris@16
|
116 // Template name: composite_device.
|
Chris@16
|
117 // Description: Provides a Device view of a Filter, Device pair.
|
Chris@16
|
118 // Template parameters:
|
Chris@16
|
119 // Filter - A model of Filter.
|
Chris@16
|
120 // Device - An indirect model of Device.
|
Chris@16
|
121 //
|
Chris@16
|
122 template< typename Filter1,
|
Chris@16
|
123 typename Filter2,
|
Chris@16
|
124 typename Mode =
|
Chris@16
|
125 BOOST_DEDUCED_TYPENAME composite_mode<Filter1, Filter2>::type >
|
Chris@16
|
126 class composite_filter {
|
Chris@16
|
127 private:
|
Chris@16
|
128 typedef reference_wrapper<Filter2> filter_ref;
|
Chris@16
|
129 typedef typename mode_of<Filter1>::type first_mode;
|
Chris@16
|
130 typedef typename mode_of<Filter2>::type second_mode;
|
Chris@16
|
131
|
Chris@16
|
132 // A dual-use filter cannot be composed with a read-write filter
|
Chris@16
|
133 BOOST_STATIC_ASSERT(
|
Chris@16
|
134 !(is_convertible<first_mode, dual_use>::value) ||
|
Chris@16
|
135 !(is_convertible<second_mode, input>::value) ||
|
Chris@16
|
136 !(is_convertible<second_mode, output>::value) ||
|
Chris@16
|
137 (is_convertible<second_mode, dual_use>::value)
|
Chris@16
|
138 );
|
Chris@16
|
139 BOOST_STATIC_ASSERT(
|
Chris@16
|
140 !(is_convertible<second_mode, dual_use>::value) ||
|
Chris@16
|
141 !(is_convertible<first_mode, input>::value) ||
|
Chris@16
|
142 !(is_convertible<first_mode, output>::value) ||
|
Chris@16
|
143 (is_convertible<first_mode, dual_use>::value)
|
Chris@16
|
144 );
|
Chris@16
|
145 BOOST_STATIC_ASSERT(is_filter<Filter1>::value);
|
Chris@16
|
146 BOOST_STATIC_ASSERT(is_filter<Filter2>::value);
|
Chris@16
|
147 public:
|
Chris@16
|
148 typedef typename char_type_of<Filter1>::type char_type;
|
Chris@16
|
149 struct category
|
Chris@16
|
150 : Mode,
|
Chris@16
|
151 filter_tag,
|
Chris@16
|
152 multichar_tag,
|
Chris@16
|
153 closable_tag,
|
Chris@16
|
154 flushable_tag,
|
Chris@16
|
155 localizable_tag,
|
Chris@16
|
156 optimally_buffered_tag
|
Chris@16
|
157 { };
|
Chris@16
|
158 composite_filter(const Filter1& filter1, const Filter2& filter2)
|
Chris@16
|
159 : filter1_(filter1), filter2_(filter2)
|
Chris@16
|
160 { }
|
Chris@16
|
161
|
Chris@16
|
162 template<typename Source>
|
Chris@16
|
163 std::streamsize read(Source& src, char_type* s, std::streamsize n)
|
Chris@16
|
164 {
|
Chris@16
|
165 composite_device<filter_ref, Source> cmp(boost::ref(filter2_), src);
|
Chris@16
|
166 return iostreams::read(filter1_, cmp, s, n);
|
Chris@16
|
167 }
|
Chris@16
|
168
|
Chris@16
|
169 template<typename Sink>
|
Chris@16
|
170 std::streamsize write(Sink& snk, const char_type* s, std::streamsize n)
|
Chris@16
|
171 {
|
Chris@16
|
172 composite_device<filter_ref, Sink> cmp(boost::ref(filter2_), snk);
|
Chris@16
|
173 return iostreams::write(filter1_, cmp, s, n);
|
Chris@16
|
174 }
|
Chris@16
|
175
|
Chris@16
|
176 template<typename Device>
|
Chris@16
|
177 std::streampos seek( Device& dev, stream_offset off, BOOST_IOS::seekdir way,
|
Chris@16
|
178 BOOST_IOS::openmode which =
|
Chris@16
|
179 BOOST_IOS::in | BOOST_IOS::out )
|
Chris@16
|
180 {
|
Chris@16
|
181 composite_device<filter_ref, Device> cmp(boost::ref(filter2_), dev);
|
Chris@16
|
182 return iostreams::seek(filter1_, cmp, off, way, which);
|
Chris@16
|
183 }
|
Chris@16
|
184
|
Chris@16
|
185 template<typename Device>
|
Chris@16
|
186 void close(Device& dev)
|
Chris@16
|
187 {
|
Chris@16
|
188 BOOST_STATIC_ASSERT((!is_convertible<category, two_sequence>::value));
|
Chris@16
|
189 BOOST_STATIC_ASSERT((!is_convertible<category, dual_use>::value));
|
Chris@16
|
190
|
Chris@16
|
191 // Create a new device by composing the second filter2_ with dev.
|
Chris@16
|
192 composite_device<filter_ref, Device> cmp(boost::ref(filter2_), dev);
|
Chris@16
|
193
|
Chris@16
|
194 // Close input sequences in reverse order and output sequences in
|
Chris@16
|
195 // forward order
|
Chris@16
|
196 if (!is_convertible<first_mode, dual_use>::value) {
|
Chris@16
|
197 detail::execute_all(
|
Chris@16
|
198 detail::call_close(filter2_, dev, BOOST_IOS::in),
|
Chris@16
|
199 detail::call_close(filter1_, cmp, BOOST_IOS::in),
|
Chris@16
|
200 detail::call_close(filter1_, cmp, BOOST_IOS::out),
|
Chris@16
|
201 detail::call_close(filter2_, dev, BOOST_IOS::out)
|
Chris@16
|
202 );
|
Chris@16
|
203 } else if (is_convertible<second_mode, input>::value) {
|
Chris@16
|
204 detail::execute_all(
|
Chris@16
|
205 detail::call_close(filter2_, dev, BOOST_IOS::in),
|
Chris@16
|
206 detail::call_close(filter1_, cmp, BOOST_IOS::in)
|
Chris@16
|
207 );
|
Chris@16
|
208 } else {
|
Chris@16
|
209 detail::execute_all(
|
Chris@16
|
210 detail::call_close(filter1_, cmp, BOOST_IOS::out),
|
Chris@16
|
211 detail::call_close(filter2_, dev, BOOST_IOS::out)
|
Chris@16
|
212 );
|
Chris@16
|
213 }
|
Chris@16
|
214 }
|
Chris@16
|
215
|
Chris@16
|
216 template<typename Device>
|
Chris@16
|
217 void close(Device& dev, BOOST_IOS::openmode which)
|
Chris@16
|
218 {
|
Chris@16
|
219 BOOST_STATIC_ASSERT(
|
Chris@16
|
220 (is_convertible<category, two_sequence>::value) ||
|
Chris@16
|
221 (is_convertible<category, dual_use>::value)
|
Chris@16
|
222 );
|
Chris@16
|
223
|
Chris@16
|
224 // Create a new device by composing the second filter2_ with dev.
|
Chris@16
|
225 composite_device<filter_ref, Device> cmp(boost::ref(filter2_), dev);
|
Chris@16
|
226
|
Chris@16
|
227 // Close input sequences in reverse order
|
Chris@16
|
228 if ( which == BOOST_IOS::in &&
|
Chris@16
|
229 ( !is_convertible<first_mode, dual_use>::value ||
|
Chris@16
|
230 is_convertible<second_mode, input>::value ) )
|
Chris@16
|
231 {
|
Chris@16
|
232 detail::execute_all(
|
Chris@16
|
233 detail::call_close(filter2_, dev, BOOST_IOS::in),
|
Chris@16
|
234 detail::call_close(filter1_, cmp, BOOST_IOS::in)
|
Chris@16
|
235 );
|
Chris@16
|
236 }
|
Chris@16
|
237
|
Chris@16
|
238 // Close output sequences in forward order
|
Chris@16
|
239 if ( which == BOOST_IOS::out &&
|
Chris@16
|
240 ( !is_convertible<first_mode, dual_use>::value ||
|
Chris@16
|
241 is_convertible<second_mode, output>::value ) )
|
Chris@16
|
242 {
|
Chris@16
|
243 detail::execute_all(
|
Chris@16
|
244 detail::call_close(filter1_, cmp, BOOST_IOS::out),
|
Chris@16
|
245 detail::call_close(filter2_, dev, BOOST_IOS::out)
|
Chris@16
|
246 );
|
Chris@16
|
247 }
|
Chris@16
|
248 }
|
Chris@16
|
249
|
Chris@16
|
250 template<typename Device>
|
Chris@16
|
251 bool flush(Device& dev)
|
Chris@16
|
252 {
|
Chris@16
|
253 composite_device<Filter2, Device> cmp(filter2_, dev);
|
Chris@16
|
254 return iostreams::flush(filter1_, cmp);
|
Chris@16
|
255 }
|
Chris@16
|
256
|
Chris@16
|
257 std::streamsize optimal_buffer_size() const
|
Chris@16
|
258 {
|
Chris@16
|
259 std::streamsize first = iostreams::optimal_buffer_size(filter1_);
|
Chris@16
|
260 std::streamsize second = iostreams::optimal_buffer_size(filter2_);
|
Chris@16
|
261 return first < second ? second : first;
|
Chris@16
|
262 }
|
Chris@16
|
263
|
Chris@16
|
264 template<typename Locale> // Avoid dependency on <locale>
|
Chris@16
|
265 void imbue(const Locale& loc)
|
Chris@16
|
266 { // To do: consider using RAII.
|
Chris@16
|
267 iostreams::imbue(filter1_, loc);
|
Chris@16
|
268 iostreams::imbue(filter2_, loc);
|
Chris@16
|
269 }
|
Chris@16
|
270
|
Chris@16
|
271 Filter1& first() { return filter1_; }
|
Chris@16
|
272 Filter2& second() { return filter2_; }
|
Chris@16
|
273 private:
|
Chris@16
|
274 Filter1 filter1_;
|
Chris@16
|
275 Filter2 filter2_;
|
Chris@16
|
276 };
|
Chris@16
|
277
|
Chris@16
|
278 template<typename Filter, typename FilterOrDevice>
|
Chris@16
|
279 struct composite_traits
|
Chris@16
|
280 : mpl::if_<
|
Chris@16
|
281 is_device<FilterOrDevice>,
|
Chris@16
|
282 composite_device<Filter, FilterOrDevice>,
|
Chris@16
|
283 composite_filter<Filter, FilterOrDevice>
|
Chris@16
|
284 >
|
Chris@16
|
285 { };
|
Chris@16
|
286
|
Chris@16
|
287 } // End namespace detail.
|
Chris@16
|
288
|
Chris@16
|
289 template<typename Filter, typename FilterOrDevice>
|
Chris@16
|
290 struct composite : detail::composite_traits<Filter, FilterOrDevice>::type {
|
Chris@16
|
291 typedef typename detail::param_type<FilterOrDevice>::type param_type;
|
Chris@16
|
292 typedef typename detail::composite_traits<Filter, FilterOrDevice>::type base;
|
Chris@16
|
293 composite(const Filter& flt, param_type dev)
|
Chris@16
|
294 : base(flt, dev)
|
Chris@16
|
295 { }
|
Chris@16
|
296 };
|
Chris@16
|
297
|
Chris@16
|
298 //--------------Implementation of compose-------------------------------------//
|
Chris@16
|
299
|
Chris@16
|
300 // Note: The following workarounds are patterned after resolve.hpp. It has not
|
Chris@16
|
301 // yet been confirmed that they are necessary.
|
Chris@16
|
302
|
Chris@16
|
303 #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //-------------------------//
|
Chris@16
|
304 # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //-------------------------------//
|
Chris@16
|
305
|
Chris@16
|
306 template<typename Filter, typename FilterOrDevice>
|
Chris@16
|
307 composite<Filter, FilterOrDevice>
|
Chris@16
|
308 compose( const Filter& filter, const FilterOrDevice& fod
|
Chris@16
|
309 BOOST_IOSTREAMS_DISABLE_IF_STREAM(FilterOrDevice) )
|
Chris@16
|
310 { return composite<Filter, FilterOrDevice>(filter, fod); }
|
Chris@16
|
311
|
Chris@16
|
312 template<typename Filter, typename Ch, typename Tr>
|
Chris@16
|
313 composite< Filter, std::basic_streambuf<Ch, Tr> >
|
Chris@16
|
314 compose(const Filter& filter, std::basic_streambuf<Ch, Tr>& sb)
|
Chris@16
|
315 { return composite< Filter, std::basic_streambuf<Ch, Tr> >(filter, sb); }
|
Chris@16
|
316
|
Chris@16
|
317 template<typename Filter, typename Ch, typename Tr>
|
Chris@16
|
318 composite< Filter, std::basic_istream<Ch, Tr> >
|
Chris@16
|
319 compose(const Filter& filter, std::basic_istream<Ch, Tr>& is)
|
Chris@16
|
320 { return composite< Filter, std::basic_istream<Ch, Tr> >(filter, is); }
|
Chris@16
|
321
|
Chris@16
|
322 template<typename Filter, typename Ch, typename Tr>
|
Chris@16
|
323 composite< Filter, std::basic_ostream<Ch, Tr> >
|
Chris@16
|
324 compose(const Filter& filter, std::basic_ostream<Ch, Tr>& os)
|
Chris@16
|
325 { return composite< Filter, std::basic_ostream<Ch, Tr> >(filter, os); }
|
Chris@16
|
326
|
Chris@16
|
327 template<typename Filter, typename Ch, typename Tr>
|
Chris@16
|
328 composite< Filter, std::basic_iostream<Ch, Tr> >
|
Chris@16
|
329 compose(const Filter& filter, std::basic_iostream<Ch, Tr>& io)
|
Chris@16
|
330 { return composite< Filter, std::basic_iostream<Ch, Tr> >(filter, io); }
|
Chris@16
|
331
|
Chris@16
|
332 # else // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //---------------------//
|
Chris@16
|
333
|
Chris@16
|
334 template<typename Filter, typename FilterOrDevice>
|
Chris@16
|
335 composite<Filter, FilterOrDevice>
|
Chris@16
|
336 compose( const Filter& filter, const FilterOrDevice& fod
|
Chris@16
|
337 BOOST_IOSTREAMS_DISABLE_IF_STREAM(FilterOrDevice) )
|
Chris@16
|
338 { return composite<Filter, FilterOrDevice>(filter, fod); }
|
Chris@16
|
339
|
Chris@16
|
340 template<typename Filter>
|
Chris@16
|
341 composite<Filter, std::streambuf>
|
Chris@16
|
342 compose(const Filter& filter, std::streambuf& sb)
|
Chris@16
|
343 { return composite<Filter, std::streambuf>(filter, sb); }
|
Chris@16
|
344
|
Chris@16
|
345 template<typename Filter>
|
Chris@16
|
346 composite<Filter, std::istream>
|
Chris@16
|
347 compose(const Filter& filter, std::istream& is)
|
Chris@16
|
348 { return composite<Filter, std::istream>(filter, is); }
|
Chris@16
|
349
|
Chris@16
|
350 template<typename Filter>
|
Chris@16
|
351 composite<Filter, std::ostream>
|
Chris@16
|
352 compose(const Filter& filter, std::ostream& os)
|
Chris@16
|
353 { return composite<Filter, std::ostream>(filter, os); }
|
Chris@16
|
354
|
Chris@16
|
355 template<typename Filter>
|
Chris@16
|
356 composite<Filter, std::iostream>
|
Chris@16
|
357 compose(const Filter& filter, std::iostream& io)
|
Chris@16
|
358 { return composite<Filter, std::iostream>(filter, io); }
|
Chris@16
|
359
|
Chris@16
|
360 # endif // # ifndef BOOST_IOSTREAMS_NO_STREAM_TEMPLATES //--------------------//
|
Chris@16
|
361 #else // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //----------------//
|
Chris@16
|
362
|
Chris@16
|
363 template<typename Filter, typename Stream>
|
Chris@16
|
364 composite<Filter, Stream>
|
Chris@16
|
365 compose(const Filter& flt, const Stream& strm, mpl::true_)
|
Chris@16
|
366 { // Bad overload resolution.
|
Chris@16
|
367 return composite<Filter, Stream>(flt, const_cast<Stream&>(strm));
|
Chris@16
|
368 }
|
Chris@16
|
369
|
Chris@16
|
370 template<typename Filter, typename FilterOrDevice>
|
Chris@16
|
371 composite<Filter, FilterOrDevice>
|
Chris@16
|
372 compose(const Filter& flt, const FilterOrDevice& fod, mpl::false_)
|
Chris@16
|
373 { return composite<Filter, FilterOrDevice>(flt, fod); }
|
Chris@16
|
374
|
Chris@16
|
375 template<typename Filter, typename FilterOrDevice>
|
Chris@16
|
376 composite<Filter, FilterOrDevice>
|
Chris@16
|
377 compose( const Filter& flt, const FilterOrDevice& fod
|
Chris@16
|
378 BOOST_IOSTREAMS_DISABLE_IF_STREAM(T) )
|
Chris@16
|
379 { return compose(flt, fod, is_std_io<FilterOrDevice>()); }
|
Chris@16
|
380
|
Chris@16
|
381 # if !BOOST_WORKAROUND(__BORLANDC__, < 0x600) && \
|
Chris@16
|
382 !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && \
|
Chris@16
|
383 !defined(__GNUC__) // ---------------------------------------------------//
|
Chris@16
|
384
|
Chris@16
|
385 template<typename Filter, typename FilterOrDevice>
|
Chris@16
|
386 composite<Filter, FilterOrDevice>
|
Chris@16
|
387 compose (const Filter& filter, FilterOrDevice& fod)
|
Chris@16
|
388 { return composite<Filter, FilterOrDevice>(filter, fod); }
|
Chris@16
|
389
|
Chris@16
|
390 # endif // Borland 5.x, VC6-7.0 or GCC 2.9x //--------------------------------//
|
Chris@16
|
391 #endif // #ifndef BOOST_IOSTREAMS_BROKEN_OVERLOAD_RESOLUTION //---------------//
|
Chris@16
|
392
|
Chris@16
|
393 //----------------------------------------------------------------------------//
|
Chris@16
|
394
|
Chris@16
|
395 namespace detail {
|
Chris@16
|
396
|
Chris@16
|
397 //--------------Implementation of composite_device---------------------------//
|
Chris@16
|
398
|
Chris@16
|
399 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
400 composite_device<Filter, Device, Mode>::composite_device
|
Chris@16
|
401 (const Filter& flt, param_type dev)
|
Chris@16
|
402 : filter_(flt), device_(dev)
|
Chris@16
|
403 { }
|
Chris@16
|
404
|
Chris@16
|
405 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
406 inline std::streamsize composite_device<Filter, Device, Mode>::read
|
Chris@16
|
407 (char_type* s, std::streamsize n)
|
Chris@16
|
408 { return iostreams::read(filter_, device_, s, n); }
|
Chris@16
|
409
|
Chris@16
|
410 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
411 inline std::streamsize composite_device<Filter, Device, Mode>::write
|
Chris@16
|
412 (const char_type* s, std::streamsize n)
|
Chris@16
|
413 { return iostreams::write(filter_, device_, s, n); }
|
Chris@16
|
414
|
Chris@16
|
415 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
416 std::streampos composite_device<Filter, Device, Mode>::seek
|
Chris@16
|
417 (stream_offset off, BOOST_IOS::seekdir way, BOOST_IOS::openmode which)
|
Chris@16
|
418 { return iostreams::seek(filter_, device_, off, way, which); }
|
Chris@16
|
419
|
Chris@16
|
420 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
421 void composite_device<Filter, Device, Mode>::close()
|
Chris@16
|
422 {
|
Chris@16
|
423 BOOST_STATIC_ASSERT((!is_convertible<Mode, two_sequence>::value));
|
Chris@16
|
424 BOOST_STATIC_ASSERT(
|
Chris@16
|
425 !(is_convertible<filter_mode, dual_use>::value) ||
|
Chris@16
|
426 !(is_convertible<device_mode, input>::value) ||
|
Chris@16
|
427 !(is_convertible<device_mode, output>::value)
|
Chris@16
|
428 );
|
Chris@16
|
429
|
Chris@16
|
430 // Close input sequences in reverse order and output sequences
|
Chris@16
|
431 // in forward order
|
Chris@16
|
432 if (!is_convertible<filter_mode, dual_use>::value) {
|
Chris@16
|
433 detail::execute_all(
|
Chris@16
|
434 detail::call_close(device_, BOOST_IOS::in),
|
Chris@16
|
435 detail::call_close(filter_, device_, BOOST_IOS::in),
|
Chris@16
|
436 detail::call_close(filter_, device_, BOOST_IOS::out),
|
Chris@16
|
437 detail::call_close(device_, BOOST_IOS::out)
|
Chris@16
|
438 );
|
Chris@16
|
439 } else if (is_convertible<device_mode, input>::value) {
|
Chris@16
|
440 detail::execute_all(
|
Chris@16
|
441 detail::call_close(device_, BOOST_IOS::in),
|
Chris@16
|
442 detail::call_close(filter_, device_, BOOST_IOS::in)
|
Chris@16
|
443 );
|
Chris@16
|
444 } else {
|
Chris@16
|
445 detail::execute_all(
|
Chris@16
|
446 detail::call_close(filter_, device_, BOOST_IOS::out),
|
Chris@16
|
447 detail::call_close(device_, BOOST_IOS::out)
|
Chris@16
|
448 );
|
Chris@16
|
449 }
|
Chris@16
|
450 }
|
Chris@16
|
451
|
Chris@16
|
452 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
453 void composite_device<Filter, Device, Mode>::close(BOOST_IOS::openmode which)
|
Chris@16
|
454 {
|
Chris@16
|
455 BOOST_STATIC_ASSERT((is_convertible<Mode, two_sequence>::value));
|
Chris@16
|
456 BOOST_STATIC_ASSERT(!(is_convertible<filter_mode, dual_use>::value));
|
Chris@16
|
457
|
Chris@16
|
458 // Close input sequences in reverse order
|
Chris@16
|
459 if (which == BOOST_IOS::in) {
|
Chris@16
|
460 detail::execute_all(
|
Chris@16
|
461 detail::call_close(device_, BOOST_IOS::in),
|
Chris@16
|
462 detail::call_close(filter_, device_, BOOST_IOS::in)
|
Chris@16
|
463 );
|
Chris@16
|
464 }
|
Chris@16
|
465
|
Chris@16
|
466 // Close output sequences in forward order
|
Chris@16
|
467 if (which == BOOST_IOS::out) {
|
Chris@16
|
468 detail::execute_all(
|
Chris@16
|
469 detail::call_close(filter_, device_, BOOST_IOS::out),
|
Chris@16
|
470 detail::call_close(device_, BOOST_IOS::out)
|
Chris@16
|
471 );
|
Chris@16
|
472 }
|
Chris@16
|
473 }
|
Chris@16
|
474
|
Chris@16
|
475 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
476 bool composite_device<Filter, Device, Mode>::flush()
|
Chris@16
|
477 {
|
Chris@16
|
478 bool r1 = iostreams::flush(filter_, device_);
|
Chris@16
|
479 bool r2 = iostreams::flush(device_);
|
Chris@16
|
480 return r1 && r2;
|
Chris@16
|
481 }
|
Chris@16
|
482
|
Chris@16
|
483 template<typename Filter, typename Device, typename Mode>
|
Chris@16
|
484 std::streamsize
|
Chris@16
|
485 composite_device<Filter, Device, Mode>::optimal_buffer_size() const
|
Chris@16
|
486 { return iostreams::optimal_buffer_size(device_); }
|
Chris@16
|
487
|
Chris@16
|
488 } // End namespace detail.
|
Chris@16
|
489
|
Chris@16
|
490 } } // End namespaces iostreams, boost.
|
Chris@16
|
491
|
Chris@16
|
492 #include <boost/iostreams/detail/config/enable_warnings.hpp>
|
Chris@16
|
493
|
Chris@16
|
494 #endif // #ifndef BOOST_IOSTREAMS_COMPOSE_HPP_INCLUDED
|