fix doc example typo
[boost.git] / boost / iostreams / write.hpp
blob4f3771a94eedf8af8a303906c0cc2040f1811125
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)
12 # pragma once
13 #endif
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>
27 // Must come last.
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 {
36 namespace detail {
38 template<typename T>
39 struct write_device_impl;
41 template<typename T>
42 struct write_filter_impl;
44 } // End namespace detail.
46 template<typename T>
47 bool put(T& t, typename char_type_of<T>::type c)
48 { return detail::write_device_impl<T>::put(detail::unwrap(t), c); }
50 template<typename T>
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,
58 std::streamsize n )
59 { return detail::write_filter_impl<T>::write(detail::unwrap(t), snk, s, n); }
61 namespace detail {
63 //------------------Definition of write_device_impl---------------------------//
65 template<typename T>
66 struct write_device_impl
67 : mpl::if_<
68 is_custom<T>,
69 operations<T>,
70 write_device_impl<
71 BOOST_DEDUCED_TYPENAME
72 dispatch<
73 T, ostream_tag, streambuf_tag, output
74 >::type
76 >::type
77 { };
79 template<>
80 struct write_device_impl<ostream_tag> {
81 template<typename T>
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(),
87 traits_type::eof() );
90 template<typename T>
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); }
96 template<>
97 struct write_device_impl<streambuf_tag> {
98 template<typename T>
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());
106 template<typename T>
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); }
112 template<>
113 struct write_device_impl<output> {
114 template<typename T>
115 static bool put(T& t, typename char_type_of<T>::type c)
116 { return t.write(&c, 1) == 1; }
118 template<typename T>
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---------------------------//
126 template<typename T>
127 struct write_filter_impl
128 : mpl::if_<
129 is_custom<T>,
130 operations<T>,
131 write_filter_impl<
132 BOOST_DEDUCED_TYPENAME
133 dispatch<
134 T, multichar_tag, any_tag
135 >::type
137 >::type
138 { };
140 template<>
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,
145 std::streamsize n )
146 { return t.write(snk, s, n); }
149 template<>
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,
154 std::streamsize n )
156 for (std::streamsize off = 0; off < n; ++off)
157 if (!t.put(snk, s[off]))
158 return off;
159 return n;
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