Chris@16: // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com) Chris@16: // (C) Copyright 2005-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: namespace boost { namespace iostreams { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct close_impl; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: template Chris@16: void close(T& t) { detail::close_all(t); } Chris@16: Chris@16: template Chris@16: void close(T& t, BOOST_IOS::openmode which) Chris@16: { Chris@16: typedef typename detail::unwrapped_type::type unwrapped; Chris@16: detail::close_impl::inner::close(detail::unwrap(t), which); Chris@16: } Chris@16: Chris@16: template Chris@16: void close(T& t, Sink& snk, BOOST_IOS::openmode which) Chris@16: { Chris@16: typedef typename detail::unwrapped_type::type unwrapped; Chris@16: detail::close_impl::inner::close(detail::unwrap(t), snk, which); Chris@16: } Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: //------------------Definition of close_impl----------------------------------// Chris@16: Chris@16: template Chris@16: struct close_tag { Chris@16: typedef typename category_of::type category; Chris@16: typedef typename Chris@16: mpl::eval_if< Chris@16: is_convertible, Chris@16: mpl::if_< Chris@16: mpl::or_< Chris@16: is_convertible, Chris@16: is_convertible Chris@16: >, Chris@16: two_sequence, Chris@16: closable_tag Chris@16: >, Chris@16: mpl::identity Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct close_impl Chris@16: : mpl::if_< Chris@16: is_custom, Chris@16: operations, Chris@16: close_impl::type> Chris@16: >::type Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: struct close_impl { Chris@16: template Chris@16: struct inner { Chris@16: static void close(T& t, BOOST_IOS::openmode which) Chris@16: { Chris@16: if (which == BOOST_IOS::out) Chris@16: iostreams::flush(t); Chris@16: } Chris@16: Chris@16: template Chris@16: static void close(T& t, Sink& snk, BOOST_IOS::openmode which) Chris@16: { Chris@16: if (which == BOOST_IOS::out) { Chris@16: non_blocking_adapter nb(snk); Chris@16: iostreams::flush(t, nb); Chris@16: } Chris@16: } Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct close_impl { Chris@16: template Chris@16: struct inner { Chris@16: static void close(T& t, BOOST_IOS::openmode which) Chris@16: { Chris@16: typedef typename category_of::type category; Chris@16: const bool in = is_convertible::value && Chris@16: !is_convertible::value; Chris@16: if (in == (which == BOOST_IOS::in)) Chris@16: t.close(); Chris@16: } Chris@16: template Chris@16: static void close(T& t, Sink& snk, BOOST_IOS::openmode which) Chris@16: { Chris@16: typedef typename category_of::type category; Chris@16: const bool in = is_convertible::value && Chris@16: !is_convertible::value; Chris@16: if (in == (which == BOOST_IOS::in)) { Chris@16: non_blocking_adapter nb(snk); Chris@16: t.close(nb); Chris@16: } Chris@16: } Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct close_impl { Chris@16: template Chris@16: struct inner { Chris@16: static void close(T& t, BOOST_IOS::openmode which) { t.close(which); } Chris@16: Chris@16: template Chris@16: static void close(T& t, Sink& snk, BOOST_IOS::openmode which) Chris@16: { Chris@16: non_blocking_adapter nb(snk); Chris@16: t.close(nb, which); Chris@16: } Chris@16: }; Chris@16: }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: } } // End namespaces iostreams, boost.