Back to Arangodb

Function Template write

3rdParty/boost/1.78.0/libs/iostreams/doc/functions/write.html

3.12.9.14.5 KB
Original Source

Function Template write

OverviewExampleHeadersReference

Overview

The two overloads of the function template write provide a uniform interface for writing a sequence of characters to a Sink or OutputFilter.

  • The first overload can be used directly in the definitions of new Filter types (see Example), and figures in the specification of the Device concepts.
  • The second overload is primarily for internal use by the library.

Example

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\>](../../../../boost/iostreams/concepts.hpp)// output\_filter#include[\<boost/iostreams/operations.hpp\>](../../../../boost/iostreams/operations.hpp)// writeusingnamespacestd;usingnamespaceboost::io;structreversing_filter :publicmultichar_output_filter {template<typenameSink>
        std::streamsize write(Sink& snk,constchar* s, streamsize n)
        {
            data.insert(data.end(), s, s + n);returnn;
        }template<typenameSink>voidclose(Sink& snk)
        {
            std::reverse(data.begin(), data.end());
            boost::iostreams::write(&data[0], (streamsize) data.size());
            data.clear();
        }
        std::vector<char> data;
    };

Headers

<boost/iostreams/operations.hpp><boost/iostreams/write.hpp>

Reference

Description

Attempts to write a sequence of characters to a given instance of the template parameter T, returning the number of characters written.

Synopsis

namespaceboost {namespaceiostreams {template<typename[T](#template_params)>     
std::streamsize[write](#write_device)( T&[t](#function_params),consttypename[char\_type\_of](../guide/traits.html#char_type_of_ref)<T>::type*[s](#function_params), 
       std::streamsize[n](#function_params));template<typename[T](#template_params),typename[Sink](#template_params)>
std::streamsize[write](#write_filter)( T&[t](#function_params),
       Sink&[snk](#function_params),consttypename[char\_type\_of](../guide/traits.html#char_type_of_ref)<T>::type*[s](#function_params), 
       std::streamsize[n](#function_params));

} }// End namespace boost::io

Template Parameters

| | | | T | - | For the first overload, a model of Sink. For the second overload, a model of OutputFilter. | | Sink | - | A model of Sink with the same character type as T whose mode refines that of T. |

Function Parameters

| | | | t | - | An instance of T | | s | - | A buffer containing characters to write | | n | - | The number of characters to write | | snk | - | An instance of Sink. |

Semantics — Device Types

template<typenameT>     
std::streamsize
write( T& t,consttypenamechar_type_of<T>::type* s,
       std::streamsize n );

The semantics of write depends on the category of T as follows:

category_of<T>::typesemantics
convertible to ostream_tagreturns t.rdbuf()->sputn(s, n)
convertible to streambuf_tag but not to ostream_tagreturns t.sputn(s, n)
otherwisereturns t.write(s, n)

Semantics — Filter Types

template<typenameT,typenameSink>
std::streamsize
write( T& t,
       Sink& snk,consttypenamechar_type_of<T>::type* s,
       std::streamsize n );

The semantics of write depends on the category of T as follows:

category_of<T>::typesemantics
convertible to multichar_tagreturns t.write(snk, s, n)
otherwiseAttempts to write n characters from s by invoking t.put(snk, s[m]) for each value m in the interval [0, n), halting if put returns false. Returns the number of characters written.

© Copyright 2008 CodeRage, LLC
© Copyright 2004-2007 Jonathan Turkanis

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)