read
The two overloads of the function template read provide a uniform interface for reading a sequence of characters from a Source or InputFilter.
Although read 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 read in the definition of a Multi-Character InputFilter.
#include <ctype.h> // tolower #include <boost/iostreams/concepts.hpp> // multichar_input_filter #include <boost/iostreams/operations.hpp> // read using namespace std; using namespace boost::io; struct tolower_filter : public multichar_input_filter { template<typename Source> streamsize read(Source& src, char* s, streamsize n) { streamsize result = boost::iostreams::read(src, s, n); for (streamsize z = 0; z < result; ++z) s[z] = tolower(s[z]); return result; } };
<boost/iostreams/operations.hpp>T, returning the number of characters read.
namespace boost { namespace iostreams { template<typename T> std::streamsize read( T& t, typename io_char<T>::type* s, std::streamsize n ); template<typename T, typename Source> std::streamsize read( T& t, Source& src, typename io_char<T>::type* s, std::streamsize n ); } } // End namespace boost::io
| T | - | For the first overload, a model of Source or a standard input stream or stream buffer type. For the second overload, a model of InputFilter. |
| Source | - | A model of Source with the same character type as T whose i/o mode refines that of T. Source must also model Peekable.
|
| t | - | An instance of the Filter or Device type T |
| s | - | The buffer into which characters should be read |
| n | - | The maximum number of characters to read |
| src | - | An instance of Source
|
template<typename T> std::streamsize read( T& t, typename io_char<T>::type* s, std::streamsize n );
The semantics of read depends on the category of T as follows:
io_category<T>::type | semantics |
|---|---|
convertible to istream_tag |
invokes t.read(s, n) and returns t.gcount() |
convertible to streambuf_tag but not to istream_tag |
returns t.sgetn(s, n) |
not convertible to direct_tag |
returns t.read(s, n) |
| otherwise | compile-time error |
template<typename T> std::streamsize read( T& t, Source& src, typename io_char<T>::type* s, std::streamsize n );
The semantics of read depends on the category of T as follows:
io_category<T>::type | semantics |
|---|---|
convertible to multichar_tag |
returns t.read(src, s, n) |
| otherwise | reads up to n characters into s by invoking t.get(src) repeatedly, halting if an end-of-stream indicator is returned; returns the number of characters successfully read |
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)