Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 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.) |
| 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 | |
| 27 | namespace ndnboost { namespace iostreams { |
| 28 | |
| 29 | namespace detail { |
| 30 | |
| 31 | template<typename T> |
| 32 | struct flush_device_impl; |
| 33 | |
| 34 | template<typename T> |
| 35 | struct flush_filter_impl; |
| 36 | |
| 37 | } // End namespace detail. |
| 38 | |
| 39 | template<typename T> |
| 40 | bool flush(T& t) |
| 41 | { return detail::flush_device_impl<T>::flush(detail::unwrap(t)); } |
| 42 | |
| 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); } |
| 46 | |
| 47 | namespace detail { |
| 48 | |
| 49 | //------------------Definition of flush_device_impl---------------------------// |
| 50 | |
| 51 | template<typename T> |
| 52 | struct 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 | |
| 65 | template<> |
| 66 | struct 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 | |
| 72 | template<> |
| 73 | struct flush_device_impl<streambuf_tag> { |
| 74 | template<typename T> |
| 75 | static bool flush(T& t) |
| 76 | { return t.NDNBOOST_IOSTREAMS_PUBSYNC() == 0; } |
| 77 | }; |
| 78 | |
| 79 | template<> |
| 80 | struct flush_device_impl<flushable_tag> { |
| 81 | template<typename T> |
| 82 | static bool flush(T& t) { return t.flush(); } |
| 83 | }; |
| 84 | |
| 85 | template<> |
| 86 | struct 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 | |
| 93 | template<typename T> |
| 94 | struct 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 | |
| 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); } |
| 111 | }; |
| 112 | |
| 113 | template<> |
| 114 | struct 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 |