Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/iostreams/flush.hpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.1 KB
Line 
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
26namespace boost { namespace iostreams {
27
28namespace detail {
29
30template<typename T>
31struct flush_device_impl;
32
33template<typename T>
34struct flush_filter_impl;
35
36} // End namespace detail.
37
38template<typename T>
39bool flush(T& t)
40{ return detail::flush_device_impl<T>::flush(detail::unwrap(t)); }
41
42template<typename T, typename Sink>
43bool flush(T& t, Sink& snk)
44{ return detail::flush_filter_impl<T>::flush(detail::unwrap(t), snk); }
45
46namespace detail {
47
48//------------------Definition of flush_device_impl---------------------------//
49
50template<typename T>
51struct 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
64template<>
65struct 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
71template<>
72struct flush_device_impl<streambuf_tag> {
73    template<typename T>
74    static bool flush(T& t)
75    { return t.BOOST_IOSTREAMS_PUBSYNC() == 0; }
76};
77
78template<>
79struct flush_device_impl<flushable_tag> {
80    template<typename T>
81    static bool flush(T& t) { return t.flush(); }
82};
83
84template<>
85struct 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
92template<typename T>
93struct 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
106template<>
107struct 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
112template<>
113struct 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
Note: See TracBrowser for help on using the repository browser.