Honeycomb  0.1
Component-Model Framework
Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
honey::net::StreamBuf_< Alloc > Class Template Reference

automatically resizable buffer class based on ByteStreamBuf More...

#include <Stream.h>

Inheritance diagram for honey::net::StreamBuf_< Alloc >:
Inheritance graph
[legend]
Collaboration diagram for honey::net::StreamBuf_< Alloc >:
Collaboration graph
[legend]

Public Member Functions

 StreamBuf_ (szt maxSize=numeral< szt >().max(), const Alloc &alloc=Alloc())
 
szt size () const
 Get the size of the input sequence. More...
 
szt maxSize () const
 Get the max sum of sizes of the input and output sequences. More...
 
ByteBufConst data () const
 Get the data that represents the input sequence. More...
 
ByteBuf prepare (szt n)
 Get a buffer that represents the output sequence with the given size. More...
 
void commit (szt n)
 Move characters from the output sequence to the input sequence. More...
 
void consume (szt n)
 Remove characters from the input sequence. More...
 
- Public Member Functions inherited from honey::ByteStreamBuf
 ByteStreamBuf (ios_base::openmode mode=0)
 
 ByteStreamBuf (const Bytes &bs, ios_base::openmode mode=0)
 
 ByteStreamBuf (ByteStreamBuf &&rhs)
 
ByteStreamBufoperator= (ByteStreamBuf &&rhs)
 
Bytes bytes () const
 
void bytes (const Bytes &bs)
 
std::streamsize sgetn (byte *s, std::streamsize n)
 
int sputbackc (byte c)
 
int sputc (byte c)
 
std::streamsize sputn (const byte *s, std::streamsize n)
 
byteeback () const
 
bytegptr () const
 
byteegptr () const
 
void setg (byte *gbeg, byte *gnext, byte *gend)
 
bytepbase () const
 
bytepptr () const
 
byteepptr () const
 
void setp (byte *new_pbase, byte *new_epptr)
 

Protected Member Functions

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

Static Protected Attributes

static const int buf_delta = 128
 

Additional Inherited Members

- Public Types inherited from honey::ByteStreamBuf
typedef std::stringbuf Super
 

Detailed Description

template<class Alloc = std::allocator<byte>>
class honey::net::StreamBuf_< Alloc >

automatically resizable buffer class based on ByteStreamBuf

Examples:

Writing directly from a StreamBuf to a socket:

net::StreamBuf b;
ostream os(&b);
os << "Hello, World!";

szt n = sock.send(b.data()); //try sending some data from input sequence
b.consume(n); //sent data is removed from input sequence

Reading from a socket directly into a StreamBuf:

net::StreamBuf b;
ByteBuf buf = b.prepare(512); //reserve 512 bytes in output sequence

szt n = sock.receive(buf); //receive some data into buffer
b.commit(n); //received data is "committed" from output sequence to input sequence

istream is(&b);
String s;
is >> s;

Constructor & Destructor Documentation

template<class Alloc = std::allocator<byte>>
honey::net::StreamBuf_< Alloc >::StreamBuf_ ( szt  maxSize = numeral<szt>().max(),
const Alloc &  alloc = Alloc() 
)
inline

Member Function Documentation

template<class Alloc = std::allocator<byte>>
void honey::net::StreamBuf_< Alloc >::commit ( szt  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 sequences.

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.
template<class Alloc = std::allocator<byte>>
void honey::net::StreamBuf_< Alloc >::consume ( szt  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.
template<class Alloc = std::allocator<byte>>
ByteBufConst honey::net::StreamBuf_< Alloc >::data ( ) const
inline

Get the data that represents the input sequence.

template<class Alloc = std::allocator<byte>>
szt honey::net::StreamBuf_< Alloc >::maxSize ( ) const
inline

Get the max sum of sizes of the input and output sequences.

template<class Alloc = std::allocator<byte>>
int_type honey::net::StreamBuf_< Alloc >::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() > maxSize() to be true.

template<class Alloc = std::allocator<byte>>
ByteBuf honey::net::StreamBuf_< Alloc >::prepare ( szt  n)
inline

Get a buffer that represents the output sequence with the given size.

Ensures that the output sequence can accommodate n characters, reallocating as necessary.

Exceptions
std::length_errorif size() + n > maxSize()
Note
The returned buffer is invalidated by any function that modifies the input or output sequences.
template<class Alloc = std::allocator<byte>>
void honey::net::StreamBuf_< Alloc >::reserve ( szt  n)
inlineprotected
template<class Alloc = std::allocator<byte>>
szt honey::net::StreamBuf_< Alloc >::size ( ) const
inline

Get the size of the input sequence.

template<class Alloc = std::allocator<byte>>
int_type honey::net::StreamBuf_< Alloc >::underflow ( )
inlineprotected

Override std::streambuf behaviour.

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

Member Data Documentation

template<class Alloc = std::allocator<byte>>
const int honey::net::StreamBuf_< Alloc >::buf_delta = 128
staticprotected

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