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_WRITE_HPP_INCLUDED Chris@16: #define BOOST_IOSTREAMS_WRITE_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 // streamsize. 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: #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-----------------------------------// Chris@16: # include Chris@16: #else // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //--------------------------// 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: { return detail::write_device_impl::put(detail::unwrap(t), c); } 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: { return detail::write_device_impl::write(detail::unwrap(t), s, n); } 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: { return detail::write_filter_impl::write(detail::unwrap(t), snk, s, n); } 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: 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()->sputc(c), Chris@16: 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.rdbuf()->sputn(s, n); } Chris@16: }; Chris@16: Chris@16: template<> Chris@16: struct write_device_impl { Chris@16: template 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: template<> Chris@16: struct write_device_impl { Chris@16: template 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: //------------------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: 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: template<> Chris@16: struct write_filter_impl { 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: } // End namespace detail. Chris@16: Chris@16: } } // End namespaces iostreams, boost. Chris@16: Chris@16: #endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-------------------------// Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // #ifndef BOOST_IOSTREAMS_WRITE_HPP_INCLUDED