fix doc example typo
[boost.git] / boost / iostreams / flush.hpp
blob73d160051c5e7576ab909bdf306cfbab3c95705b
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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
12 # pragma once
13 #endif
15 #include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC.
16 #include <boost/detail/workaround.hpp>
17 #include <boost/iostreams/detail/dispatch.hpp>
18 #include <boost/iostreams/detail/streambuf.hpp>
19 #include <boost/iostreams/detail/wrap_unwrap.hpp>
20 #include <boost/iostreams/operations_fwd.hpp>
21 #include <boost/iostreams/traits.hpp>
22 #include <boost/mpl/if.hpp>
24 // Must come last.
25 #include <boost/iostreams/detail/config/disable_warnings.hpp>
27 namespace boost { namespace iostreams {
29 namespace detail {
31 template<typename T>
32 struct flush_device_impl;
34 template<typename T>
35 struct flush_filter_impl;
37 } // End namespace detail.
39 template<typename T>
40 bool flush(T& t)
41 { return detail::flush_device_impl<T>::flush(detail::unwrap(t)); }
43 template<typename T, typename Sink>
44 bool flush(T& t, Sink& snk)
45 { return detail::flush_filter_impl<T>::flush(detail::unwrap(t), snk); }
47 namespace detail {
49 //------------------Definition of flush_device_impl---------------------------//
51 template<typename T>
52 struct flush_device_impl
53 : mpl::if_<
54 is_custom<T>,
55 operations<T>,
56 flush_device_impl<
57 BOOST_DEDUCED_TYPENAME
58 dispatch<
59 T, ostream_tag, streambuf_tag, flushable_tag, any_tag
60 >::type
62 >::type
63 { };
65 template<>
66 struct flush_device_impl<ostream_tag> {
67 template<typename T>
68 static bool flush(T& t)
69 { return t.rdbuf()->BOOST_IOSTREAMS_PUBSYNC() == 0; }
72 template<>
73 struct flush_device_impl<streambuf_tag> {
74 template<typename T>
75 static bool flush(T& t)
76 { return t.BOOST_IOSTREAMS_PUBSYNC() == 0; }
79 template<>
80 struct flush_device_impl<flushable_tag> {
81 template<typename T>
82 static bool flush(T& t) { return t.flush(); }
85 template<>
86 struct flush_device_impl<any_tag> {
87 template<typename T>
88 static bool flush(T&) { return true; }
91 //------------------Definition of flush_filter_impl---------------------------//
93 template<typename T>
94 struct flush_filter_impl
95 : mpl::if_<
96 is_custom<T>,
97 operations<T>,
98 flush_filter_impl<
99 BOOST_DEDUCED_TYPENAME
100 dispatch<
101 T, flushable_tag, any_tag
102 >::type
104 >::type
105 { };
107 template<>
108 struct flush_filter_impl<flushable_tag> {
109 template<typename T, typename Sink>
110 static bool flush(T& t, Sink& snk) { return t.flush(snk); }
113 template<>
114 struct flush_filter_impl<any_tag> {
115 template<typename T, typename Sink>
116 static bool flush(T&, Sink&) { return false; }
119 } // End namespace detail.
121 } } // End namespaces iostreams, boost.
123 #include <boost/iostreams/detail/config/enable_warnings.hpp>
125 #endif // #ifndef BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED