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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_WRITE_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_WRITE_HPP_INCLUDED
11 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
15 #include <boost/config.hpp> // DEDUCED_TYPENAME, MSVC.
16 #include <boost/detail/workaround.hpp>
17 #include <boost/iostreams/categories.hpp>
18 #include <boost/iostreams/detail/char_traits.hpp>
19 #include <boost/iostreams/detail/dispatch.hpp>
20 #include <boost/iostreams/detail/ios.hpp> // streamsize.
21 #include <boost/iostreams/detail/streambuf.hpp>
22 #include <boost/iostreams/detail/wrap_unwrap.hpp>
23 #include <boost/iostreams/operations_fwd.hpp>
24 #include <boost/iostreams/traits.hpp>
25 #include <boost/mpl/if.hpp>
28 #include <boost/iostreams/detail/config/disable_warnings.hpp>
30 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-----------------------------------//
31 # include <boost/iostreams/detail/vc6/write.hpp>
32 #else // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //--------------------------//
34 namespace boost
{ namespace iostreams
{
39 struct write_device_impl
;
42 struct write_filter_impl
;
44 } // End namespace detail.
47 bool put(T
& t
, typename char_type_of
<T
>::type c
)
48 { return detail::write_device_impl
<T
>::put(detail::unwrap(t
), c
); }
51 inline std::streamsize write
52 (T
& t
, const typename char_type_of
<T
>::type
* s
, std::streamsize n
)
53 { return detail::write_device_impl
<T
>::write(detail::unwrap(t
), s
, n
); }
55 template<typename T
, typename Sink
>
56 inline std::streamsize
57 write( T
& t
, Sink
& snk
, const typename char_type_of
<T
>::type
* s
,
59 { return detail::write_filter_impl
<T
>::write(detail::unwrap(t
), snk
, s
, n
); }
63 //------------------Definition of write_device_impl---------------------------//
66 struct write_device_impl
71 BOOST_DEDUCED_TYPENAME
73 T
, ostream_tag
, streambuf_tag
, output
80 struct write_device_impl
<ostream_tag
> {
82 static bool put(T
& t
, typename char_type_of
<T
>::type c
)
84 typedef typename char_type_of
<T
>::type char_type
;
85 typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type
) traits_type
;
86 return !traits_type::eq_int_type( t
.rdbuf()->s
.sputc(),
91 static std::streamsize write
92 (T
& t
, const typename char_type_of
<T
>::type
* s
, std::streamsize n
)
93 { return t
.rdbuf()->sputn(s
, n
); }
97 struct write_device_impl
<streambuf_tag
> {
99 static bool put(T
& t
, typename char_type_of
<T
>::type c
)
101 typedef typename char_type_of
<T
>::type char_type
;
102 typedef BOOST_IOSTREAMS_CHAR_TRAITS(char_type
) traits_type
;
103 return !traits_type::eq_int_type(t
.sputc(c
), traits_type::eof());
107 static std::streamsize write
108 (T
& t
, const typename char_type_of
<T
>::type
* s
, std::streamsize n
)
109 { return t
.sputn(s
, n
); }
113 struct write_device_impl
<output
> {
115 static bool put(T
& t
, typename char_type_of
<T
>::type c
)
116 { return t
.write(&c
, 1) == 1; }
119 static std::streamsize
120 write(T
& t
, const typename char_type_of
<T
>::type
* s
, std::streamsize n
)
121 { return t
.write(s
, n
); }
124 //------------------Definition of write_filter_impl---------------------------//
127 struct write_filter_impl
132 BOOST_DEDUCED_TYPENAME
134 T
, multichar_tag
, any_tag
141 struct write_filter_impl
<multichar_tag
> {
142 template<typename T
, typename Sink
>
143 static std::streamsize
144 write( T
& t
, Sink
& snk
, const typename char_type_of
<T
>::type
* s
,
146 { return t
.write(snk
, s
, n
); }
150 struct write_filter_impl
<any_tag
> {
151 template<typename T
, typename Sink
>
152 static std::streamsize
153 write( T
& t
, Sink
& snk
, const typename char_type_of
<T
>::type
* s
,
156 for (std::streamsize off
= 0; off
< n
; ++off
)
157 if (!t
.put(snk
, s
[off
]))
163 } // End namespace detail.
165 } } // End namespaces iostreams, boost.
167 #endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) //-------------------------//
169 #include <boost/iostreams/detail/config/enable_warnings.hpp>
171 #endif // #ifndef BOOST_IOSTREAMS_WRITE_HPP_INCLUDED