File indexing completed on 2025-01-18 09:38:53
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED
0010
0011 #if defined(_MSC_VER)
0012 # pragma once
0013 #endif
0014
0015 #include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC.
0016 #include <boost/detail/workaround.hpp>
0017 #include <boost/iostreams/detail/dispatch.hpp>
0018 #include <boost/iostreams/detail/streambuf.hpp>
0019 #include <boost/iostreams/detail/wrap_unwrap.hpp>
0020 #include <boost/iostreams/operations_fwd.hpp>
0021 #include <boost/iostreams/traits.hpp>
0022 #include <boost/mpl/if.hpp>
0023
0024
0025 #include <boost/iostreams/detail/config/disable_warnings.hpp>
0026
0027 namespace boost { namespace iostreams {
0028
0029 namespace detail {
0030
0031 template<typename T>
0032 struct flush_device_impl;
0033
0034 template<typename T>
0035 struct flush_filter_impl;
0036
0037 }
0038
0039 template<typename T>
0040 bool flush(T& t)
0041 { return detail::flush_device_impl<T>::flush(detail::unwrap(t)); }
0042
0043 template<typename T, typename Sink>
0044 bool flush(T& t, Sink& snk)
0045 { return detail::flush_filter_impl<T>::flush(detail::unwrap(t), snk); }
0046
0047 namespace detail {
0048
0049
0050
0051 template<typename T>
0052 struct flush_device_impl
0053 : mpl::if_<
0054 is_custom<T>,
0055 operations<T>,
0056 flush_device_impl<
0057 BOOST_DEDUCED_TYPENAME
0058 dispatch<
0059 T, ostream_tag, streambuf_tag, flushable_tag, any_tag
0060 >::type
0061 >
0062 >::type
0063 { };
0064
0065 template<>
0066 struct flush_device_impl<ostream_tag> {
0067 template<typename T>
0068 static bool flush(T& t)
0069 { return t.rdbuf()->BOOST_IOSTREAMS_PUBSYNC() == 0; }
0070 };
0071
0072 template<>
0073 struct flush_device_impl<streambuf_tag> {
0074 template<typename T>
0075 static bool flush(T& t)
0076 { return t.BOOST_IOSTREAMS_PUBSYNC() == 0; }
0077 };
0078
0079 template<>
0080 struct flush_device_impl<flushable_tag> {
0081 template<typename T>
0082 static bool flush(T& t) { return t.flush(); }
0083 };
0084
0085 template<>
0086 struct flush_device_impl<any_tag> {
0087 template<typename T>
0088 static bool flush(T&) { return true; }
0089 };
0090
0091
0092
0093 template<typename T>
0094 struct flush_filter_impl
0095 : mpl::if_<
0096 is_custom<T>,
0097 operations<T>,
0098 flush_filter_impl<
0099 BOOST_DEDUCED_TYPENAME
0100 dispatch<
0101 T, flushable_tag, any_tag
0102 >::type
0103 >
0104 >::type
0105 { };
0106
0107 template<>
0108 struct flush_filter_impl<flushable_tag> {
0109 template<typename T, typename Sink>
0110 static bool flush(T& t, Sink& snk) { return t.flush(snk); }
0111 };
0112
0113 template<>
0114 struct flush_filter_impl<any_tag> {
0115 template<typename T, typename Sink>
0116 static bool flush(T&, Sink&) { return false; }
0117 };
0118
0119 }
0120
0121 } }
0122
0123 #include <boost/iostreams/detail/config/enable_warnings.hpp>
0124
0125 #endif