write
The two overloads of the function template write provide a uniform interface for writing a sequence of characters to a Sink or OutputFilter.
Although write is designed to be overloaded or specialized for new Filter and Device types, the default implementation should be suitable for most purposes.
The following code illustrates the use of the function write in the definition of an OutputFilter which reverses its controlled sequence.
#include <algorithm> // reverse #include <vector> #include <boost/iostreams/concepts.hpp> // output_filter #include <boost/iostreams/operations.hpp> // write using namespace std; using namespace boost::io; struct reversing_filter : public multichar_output_filter { template<typename Sink> void write(Sink& snk, const char* s, streamsize n) { data.insert(data.end(), s, s + n); } template<typename Sink> void close(Sink& snk) { std::reverse(data.begin(), data.end()); boost::iostreams::write(&data[0], (streamsize) data.size()); data.clear(); } std::vector<char> data; };
<boost/iostreams/operations.hpp>T.
namespace boost { namespace iostreams { template<typename T> void write( T& t, const typename char_type_of<T>::type* s, std::streamsize n ); template<typename T, typename Sink> void write( T& t, Sink& snk, const typename char_type_of<T>::type* s, std::streamsize n ); } } // End namespace boost::io
| T | - | For the first overload, a model of Sink or a standard output stream or stream buffer type. For the second overload, a model of OutputFilter. |
| Sink | - | A model of Sink with the same character type as T whose i/o mode refines that of T.
|
| t | - | An instance of the Sink type T |
| s | - | A buffer containing characters to write |
| n | - | The number of characters to write |
| snk | - | An instance of Sink.
|
template<typename T> void write( T& t, const typename char_type_of<T>::type* s, std::streamsize n );
The semantics of write depends on the category of T as follows:
category_of<T>::type | semantics |
|---|---|
convertible to ostream_tag |
invokes t.write(s, n) |
convertible to streambuf_tag but not to ostream_tag |
invokes t.sputn(s, n) |
convertible to insert_iterator_tag |
invokes std::copy(s, s + n, t) |
| otherwise | invokes t.write(s, n) |
template<typename T, typename Sink> void write( T& t, Sink& snk, const typename char_type_of<T>::type* s, std::streamsize n );
The semantics of read depends on the category of T as follows:
category_of<T>::type | semantics |
|---|---|
convertible to multichar_tag |
invokes t.write(snk, s, n) |
| otherwise | writes n characters from s by invoking t.put(snk, s[m]) for each value m in the interval [0, n) |
Revised 20 May, 2004
© Copyright Jonathan Turkanis, 2004
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)