Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2003-2007 Jonathan Turkanis Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) Chris@16: Chris@16: // See http://www.boost.org/libs/iostreams for documentation. Chris@16: Chris@16: #ifndef BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1020) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include // DEDUCED_TYPENAME, MSVC. Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // Must come last. Chris@16: #include Chris@16: Chris@16: namespace boost { namespace iostreams { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct flush_device_impl; Chris@16: Chris@16: template Chris@16: struct flush_filter_impl; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: template Chris@16: bool flush(T& t) Chris@16: { return detail::flush_device_impl::flush(detail::unwrap(t)); } Chris@16: Chris@16: template Chris@16: bool flush(T& t, Sink& snk) Chris@16: { return detail::flush_filter_impl::flush(detail::unwrap(t), snk); } Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: //------------------Definition of flush_device_impl---------------------------// Chris@16: Chris@16: template Chris@16: struct flush_device_impl Chris@16: : mpl::if_< Chris@16: is_custom, Chris@16: operations, Chris@16: flush_device_impl< Chris@16: BOOST_DEDUCED_TYPENAME Chris@16: dispatch< Chris@16: T, ostream_tag, streambuf_tag, flushable_tag, any_tag Chris@16: >::type Chris@16: > Chris@16: >::type Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: struct flush_device_impl { Chris@16: template Chris@16: static bool flush(T& t) Chris@16: { return t.rdbuf()->BOOST_IOSTREAMS_PUBSYNC() == 0; } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct flush_device_impl { Chris@16: template Chris@16: static bool flush(T& t) Chris@16: { return t.BOOST_IOSTREAMS_PUBSYNC() == 0; } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct flush_device_impl { Chris@16: template Chris@16: static bool flush(T& t) { return t.flush(); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct flush_device_impl { Chris@16: template Chris@16: static bool flush(T&) { return true; } Chris@16: }; Chris@16: Chris@16: //------------------Definition of flush_filter_impl---------------------------// Chris@16: Chris@16: template Chris@16: struct flush_filter_impl Chris@16: : mpl::if_< Chris@16: is_custom, Chris@16: operations, Chris@16: flush_filter_impl< Chris@16: BOOST_DEDUCED_TYPENAME Chris@16: dispatch< Chris@16: T, flushable_tag, any_tag Chris@16: >::type Chris@16: > Chris@16: >::type Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: struct flush_filter_impl { Chris@16: template Chris@16: static bool flush(T& t, Sink& snk) { return t.flush(snk); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct flush_filter_impl { Chris@16: template Chris@16: static bool flush(T&, Sink&) { return false; } Chris@16: }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: } } // End namespaces iostreams, boost. Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_FLUSH_HPP_INCLUDED