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_FLUSH_HPP_INCLUDED |
---|
8 | #define BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED |
---|
9 | |
---|
10 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
11 | # pragma once |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC. |
---|
15 | #include <boost/detail/workaround.hpp> |
---|
16 | #include <boost/iostreams/detail/dispatch.hpp> |
---|
17 | #include <boost/iostreams/detail/streambuf.hpp> |
---|
18 | #include <boost/iostreams/detail/wrap_unwrap.hpp> |
---|
19 | #include <boost/iostreams/operations_fwd.hpp> |
---|
20 | #include <boost/iostreams/traits.hpp> |
---|
21 | #include <boost/mpl/if.hpp> |
---|
22 | |
---|
23 | // Must come last. |
---|
24 | #include <boost/iostreams/detail/config/disable_warnings.hpp> |
---|
25 | |
---|
26 | namespace boost { namespace iostreams { |
---|
27 | |
---|
28 | namespace detail { |
---|
29 | |
---|
30 | template<typename T> |
---|
31 | struct flush_device_impl; |
---|
32 | |
---|
33 | template<typename T> |
---|
34 | struct flush_filter_impl; |
---|
35 | |
---|
36 | } // End namespace detail. |
---|
37 | |
---|
38 | template<typename T> |
---|
39 | bool flush(T& t) |
---|
40 | { return detail::flush_device_impl<T>::flush(detail::unwrap(t)); } |
---|
41 | |
---|
42 | template<typename T, typename Sink> |
---|
43 | bool flush(T& t, Sink& snk) |
---|
44 | { return detail::flush_filter_impl<T>::flush(detail::unwrap(t), snk); } |
---|
45 | |
---|
46 | namespace detail { |
---|
47 | |
---|
48 | //------------------Definition of flush_device_impl---------------------------// |
---|
49 | |
---|
50 | template<typename T> |
---|
51 | struct flush_device_impl |
---|
52 | : mpl::if_< |
---|
53 | is_custom<T>, |
---|
54 | operations<T>, |
---|
55 | flush_device_impl< |
---|
56 | BOOST_DEDUCED_TYPENAME |
---|
57 | dispatch< |
---|
58 | T, ostream_tag, streambuf_tag, flushable_tag, any_tag |
---|
59 | >::type |
---|
60 | > |
---|
61 | >::type |
---|
62 | { }; |
---|
63 | |
---|
64 | template<> |
---|
65 | struct flush_device_impl<ostream_tag> { |
---|
66 | template<typename T> |
---|
67 | static bool flush(T& t) |
---|
68 | { return t.rdbuf()->BOOST_IOSTREAMS_PUBSYNC() == 0; } |
---|
69 | }; |
---|
70 | |
---|
71 | template<> |
---|
72 | struct flush_device_impl<streambuf_tag> { |
---|
73 | template<typename T> |
---|
74 | static bool flush(T& t) |
---|
75 | { return t.BOOST_IOSTREAMS_PUBSYNC() == 0; } |
---|
76 | }; |
---|
77 | |
---|
78 | template<> |
---|
79 | struct flush_device_impl<flushable_tag> { |
---|
80 | template<typename T> |
---|
81 | static bool flush(T& t) { return t.flush(); } |
---|
82 | }; |
---|
83 | |
---|
84 | template<> |
---|
85 | struct flush_device_impl<any_tag> { |
---|
86 | template<typename T> |
---|
87 | static bool flush(T&) { return true; } |
---|
88 | }; |
---|
89 | |
---|
90 | //------------------Definition of flush_filter_impl---------------------------// |
---|
91 | |
---|
92 | template<typename T> |
---|
93 | struct flush_filter_impl |
---|
94 | : mpl::if_< |
---|
95 | is_custom<T>, |
---|
96 | operations<T>, |
---|
97 | flush_filter_impl< |
---|
98 | BOOST_DEDUCED_TYPENAME |
---|
99 | dispatch< |
---|
100 | T, flushable_tag, any_tag |
---|
101 | >::type |
---|
102 | > |
---|
103 | >::type |
---|
104 | { }; |
---|
105 | |
---|
106 | template<> |
---|
107 | struct flush_filter_impl<flushable_tag> { |
---|
108 | template<typename T, typename Sink> |
---|
109 | static bool flush(T& t, Sink& snk) { return t.flush(snk); } |
---|
110 | }; |
---|
111 | |
---|
112 | template<> |
---|
113 | struct flush_filter_impl<any_tag> { |
---|
114 | template<typename T, typename Sink> |
---|
115 | static bool flush(T&, Sink&) { return false; } |
---|
116 | }; |
---|
117 | |
---|
118 | } // End namespace detail. |
---|
119 | |
---|
120 | } } // End namespaces iostreams, boost. |
---|
121 | |
---|
122 | #include <boost/iostreams/detail/config/enable_warnings.hpp> |
---|
123 | |
---|
124 | #endif // #ifndef BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED |
---|