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