Realistic 3D camera system
3D camera system components
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
asio::basic_streambuf< Allocator > Class Template Reference

Automatically resizable buffer class based on std::streambuf. More...

#include <basic_streambuf.hpp>

Inheritance diagram for asio::basic_streambuf< Allocator >:
asio::detail::noncopyable

Public Types

typedef asio::const_buffers_1 const_buffers_type
 
typedef asio::mutable_buffers_1 mutable_buffers_type
 

Public Member Functions

 basic_streambuf (std::size_t maximum_size=(std::numeric_limits< std::size_t >::max)(), const Allocator &allocator=Allocator())
 Construct a basic_streambuf object. More...
 
std::size_t size () const
 Get the size of the input sequence. More...
 
std::size_t max_size () const
 Get the maximum size of the basic_streambuf. More...
 
const_buffers_type data () const
 Get a list of buffers that represents the input sequence. More...
 
mutable_buffers_type prepare (std::size_t n)
 
void commit (std::size_t n)
 Move characters from the output sequence to the input sequence. More...
 
void consume (std::size_t n)
 Remove characters from the input sequence. More...
 

Protected Types

enum  { buffer_delta = 128 }
 

Protected Member Functions

int_type underflow ()
 Override std::streambuf behaviour. More...
 
int_type overflow (int_type c)
 Override std::streambuf behaviour. More...
 
void reserve (std::size_t n)
 

Friends

std::size_t read_size_helper (basic_streambuf &sb, std::size_t max_size)
 

Detailed Description

template<typename Allocator>
class asio::basic_streambuf< Allocator >

Automatically resizable buffer class based on std::streambuf.

The basic_streambuf class is derived from std::streambuf to associate the streambuf's input and output sequences with one or more character arrays. These character arrays are internal to the basic_streambuf object, but direct access to the array elements is provided to permit them to be used efficiently with I/O operations. Characters written to the output sequence of a basic_streambuf object are appended to the input sequence of the same object.

The basic_streambuf class's public interface is intended to permit the following implementation strategies:

The constructor for basic_streambuf accepts a size_t argument specifying the maximum of the sum of the sizes of the input sequence and output sequence. During the lifetime of the basic_streambuf object, the following invariant holds:

size() <= max_size()

Any member function that would, if successful, cause the invariant to be violated shall throw an exception of class std::length_error.

The constructor for basic_streambuf takes an Allocator argument. A copy of this argument is used for any memory allocation performed, by the constructor and by all member functions, during the lifetime of each basic_streambuf object.

Examples
Writing directly from an streambuf to a socket:
std::ostream os(&b);
os << "Hello, World!\n";
// try sending some data in input sequence
size_t n = sock.send(b.data());
b.consume(n); // sent data is removed from input sequence

Reading from a socket directly into a streambuf:

// reserve 512 bytes in output sequence
size_t n = sock.receive(bufs);
// received data is "committed" from output sequence to input sequence
b.commit(n);
std::istream is(&b);
std::string s;
is >> s;

Definition at line 110 of file basic_streambuf.hpp.

Member Typedef Documentation

template<typename Allocator>
typedef asio::const_buffers_1 asio::basic_streambuf< Allocator >::const_buffers_type

Definition at line 122 of file basic_streambuf.hpp.

template<typename Allocator>
typedef asio::mutable_buffers_1 asio::basic_streambuf< Allocator >::mutable_buffers_type

Definition at line 123 of file basic_streambuf.hpp.

Member Enumeration Documentation

template<typename Allocator>
anonymous enum
protected
Enumerator
buffer_delta 

Definition at line 248 of file basic_streambuf.hpp.

Constructor & Destructor Documentation

template<typename Allocator>
asio::basic_streambuf< Allocator >::basic_streambuf ( std::size_t  maximum_size = (std::numeric_limits<std::size_t>::max)(),
const Allocator &  allocator = Allocator() 
)
inlineexplicit

Construct a basic_streambuf object.

Constructs a streambuf with the specified maximum size. The initial size of the streambuf's input sequence is 0.

Definition at line 131 of file basic_streambuf.hpp.

Member Function Documentation

template<typename Allocator>
void asio::basic_streambuf< Allocator >::commit ( std::size_t  n)
inline

Move characters from the output sequence to the input sequence.

Appends n characters from the start of the output sequence to the input sequence. The beginning of the output sequence is advanced by n characters.

Requires a preceding call prepare(x) where x >= n, and no intervening operations that modify the input or output sequence.

Note
If n is greater than the size of the output sequence, the entire output sequence is moved to the input sequence and no error is issued.

Definition at line 223 of file basic_streambuf.hpp.

template<typename Allocator>
void asio::basic_streambuf< Allocator >::consume ( std::size_t  n)
inline

Remove characters from the input sequence.

Removes n characters from the beginning of the input sequence.

Note
If n is greater than the size of the input sequence, the entire input sequence is consumed and no error is issued.

Definition at line 238 of file basic_streambuf.hpp.

template<typename Allocator>
const_buffers_type asio::basic_streambuf< Allocator >::data ( ) const
inline

Get a list of buffers that represents the input sequence.

Returns
An object of type const_buffers_type that satisfies ConstBufferSequence requirements, representing all character arrays in the input sequence.
Note
The returned object is invalidated by any basic_streambuf member function that modifies the input sequence or output sequence.

Definition at line 182 of file basic_streambuf.hpp.

template<typename Allocator>
std::size_t asio::basic_streambuf< Allocator >::max_size ( ) const
inline

Get the maximum size of the basic_streambuf.

Returns
The allowed maximum of the sum of the sizes of the input sequence and output sequence.

Definition at line 168 of file basic_streambuf.hpp.

template<typename Allocator>
int_type asio::basic_streambuf< Allocator >::overflow ( int_type  c)
inlineprotected

Override std::streambuf behaviour.

Behaves according to the specification of std::streambuf::overflow(), with the specialisation that std::length_error is thrown if appending the character to the input sequence would require the condition size() > max_size() to be true.

Definition at line 274 of file basic_streambuf.hpp.

template<typename Allocator>
mutable_buffers_type asio::basic_streambuf< Allocator >::prepare ( std::size_t  n)
inline

Get a list of buffers that represents the output sequence, with the given size. Ensures that the output sequence can accommodate n characters, reallocating character array objects as necessary.

Returns
An object of type mutable_buffers_type that satisfies MutableBufferSequence requirements, representing character array objects at the start of the output sequence such that the sum of the buffer sizes is n.
Exceptions
std::length_errorIf size() + n > max_size().
Note
The returned object is invalidated by any basic_streambuf member function that modifies the input sequence or output sequence.

Definition at line 204 of file basic_streambuf.hpp.

template<typename Allocator>
void asio::basic_streambuf< Allocator >::reserve ( std::size_t  n)
inlineprotected

Definition at line 299 of file basic_streambuf.hpp.

template<typename Allocator>
std::size_t asio::basic_streambuf< Allocator >::size ( ) const
inline

Get the size of the input sequence.

Returns
The size of the input sequence. The value is equal to that calculated for s in the following code:
size_t s = 0;
while (i != bufs.end())
{
const_buffer buf(*i++);
}

Definition at line 158 of file basic_streambuf.hpp.

template<typename Allocator>
int_type asio::basic_streambuf< Allocator >::underflow ( )
inlineprotected

Override std::streambuf behaviour.

Behaves according to the specification of std::streambuf::underflow().

Definition at line 254 of file basic_streambuf.hpp.

Friends And Related Function Documentation

template<typename Allocator>
std::size_t read_size_helper ( basic_streambuf< Allocator > &  sb,
std::size_t  max_size 
)
friend

Definition at line 344 of file basic_streambuf.hpp.


The documentation for this class was generated from the following file: