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 write_device_impl; Chris@16: Chris@16: template Chris@16: struct write_filter_impl; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: template Chris@16: bool put(T& t, typename char_type_of::type c) Chris@16: { Chris@16: typedef typename detail::unwrapped_type::type unwrapped; Chris@16: return detail::write_device_impl::inner::put(detail::unwrap(t), c); Chris@16: } Chris@16: Chris@16: template Chris@16: inline std::streamsize write Chris@16: (T& t, const typename char_type_of::type* s, std::streamsize n) Chris@16: { Chris@16: typedef typename detail::unwrapped_type::type unwrapped; Chris@16: return detail::write_device_impl::inner::write(detail::unwrap(t), s, n); Chris@16: } Chris@16: Chris@16: template Chris@16: inline std::streamsize Chris@16: write( T& t, Sink& snk, const typename char_type_of::type* s, Chris@16: std::streamsize n ) Chris@16: { Chris@16: typedef typename detail::unwrapped_type::type unwrapped; Chris@16: return detail::write_filter_impl::inner::write(detail::unwrap(t), snk, s, n); Chris@16: } Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: //------------------Definition of write_device_impl---------------------------// Chris@16: Chris@16: template Chris@16: struct write_device_impl Chris@16: : mpl::if_< Chris@16: is_custom, Chris@16: operations, Chris@16: write_device_impl< Chris@16: BOOST_DEDUCED_TYPENAME Chris@16: dispatch< Chris@16: T, ostream_tag, streambuf_tag, output Chris@16: >::type Chris@16: > Chris@16: >::type Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: struct write_device_impl { Chris@16: template Chris@16: struct inner { Chris@16: static bool put(T& t, typename char_type_of::type c) Chris@16: { Chris@16: typedef typename char_type_of::type char_type; Chris@16: typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type; Chris@16: return !traits_type::eq_int_type( t.rdbuf()->s.sputc(), Chris@16: traits_type::eof() ); Chris@16: } Chris@16: Chris@16: static std::streamsize write Chris@16: (T& t, const typename char_type_of::type* s, std::streamsize n) Chris@16: { return t.rdbuf()->sputn(s, n); } Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct write_device_impl { Chris@16: template Chris@16: struct inner { Chris@16: static bool put(T& t, typename char_type_of::type c) Chris@16: { Chris@16: typedef typename char_type_of::type char_type; Chris@16: typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type) traits_type; Chris@16: return !traits_type::eq_int_type(t.sputc(c), traits_type::eof()); Chris@16: } Chris@16: Chris@16: template Chris@16: static std::streamsize write Chris@16: (T& t, const typename char_type_of::type* s, std::streamsize n) Chris@16: { return t.sputn(s, n); } Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct write_device_impl { Chris@16: template Chris@16: struct inner { Chris@16: static bool put(T& t, typename char_type_of::type c) Chris@16: { return t.write(&c, 1) == 1; } Chris@16: Chris@16: template Chris@16: static std::streamsize Chris@16: write(T& t, const typename char_type_of::type* s, std::streamsize n) Chris@16: { return t.write(s, n); } Chris@16: }; Chris@16: }; Chris@16: Chris@16: //------------------Definition of write_filter_impl---------------------------// Chris@16: Chris@16: template Chris@16: struct write_filter_impl Chris@16: : mpl::if_< Chris@16: is_custom, Chris@16: operations, Chris@16: write_filter_impl< Chris@16: BOOST_DEDUCED_TYPENAME Chris@16: dispatch< Chris@16: T, multichar_tag, any_tag Chris@16: >::type Chris@16: > Chris@16: >::type Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: struct write_filter_impl { Chris@16: template Chris@16: struct inner { Chris@16: template Chris@16: static std::streamsize Chris@16: write( T& t, Sink& snk, const typename char_type_of::type* s, Chris@16: std::streamsize n ) Chris@16: { return t.write(snk, s, n); } Chris@16: }; Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct write_filter_impl { Chris@16: template Chris@16: struct inner { Chris@16: template Chris@16: static std::streamsize Chris@16: write( T& t, Sink& snk, const typename char_type_of::type* s, Chris@16: std::streamsize n ) Chris@16: { Chris@16: for (std::streamsize off = 0; off < n; ++off) Chris@16: if (!t.put(snk, s[off])) Chris@16: return off; Chris@16: return n; Chris@16: } Chris@16: }; Chris@16: }; Chris@16: Chris@16: } // End namespace detail. Chris@16: Chris@16: } } // End namespaces iostreams, boost.