Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

OW32::auto_buf< E > Class Template Reference

A growable buffer class. More...

#include <auto_buf.h>

List of all members.

Public Types

enum  seekdir { beg, cur, end }
 Direction constants for seekp. More...

Public Member Functions

 auto_buf ()
 Default constructor to create an empty buffer.
 auto_buf (const E *s)
 Constructor that copies a zero terminated element string using write.
 auto_buf (const E *s, size_t n)
 Constructor that copies an element string using write.
 auto_buf (const auto_buf &rhs)
 Constructor to copy one buffer to another.
auto_bufoperator= (const auto_buf &rhs)
 Assignment operator, copies one buffer to another.
 ~auto_buf ()
 Destructor that frees any allocated storage.
size_t length () const
 Returns the length of the controlled sequence.
size_t count () const
 Returns the length of the controlled sequence.
size_t size () const
 Returns the length of the controlled sequence.
E * detach ()
 Detach the encapsulated buffer and return.
void attach (E *buf, size_t capacity)
 Attach the given buffer.
void resize (size_t n)
 Resize the controlled sequence to N elements.
void reserve (size_t n)
 Reserve space for at least N chars.
size_t capacity () const
 Return the reserved size of the buffer.
void clear ()
 Clear the buffer.
void reset ()
 Reset the buffer.
void put (E c)
 Put a single element.
size_t write (const E *s, size_t n)
 Put a block of elements.
size_t write (const E *s)
 Put a block of elements, terminated by a 0.
size_t tellp () const
 Return the current seek position.
void seekp (size_t p)
 Seek to an absolute offset.
void seekp (int off, seekdir way)
 Seek to an absolute offset.
E * str () const
 Return a pointer to the base of the controlled sequence.
E * cstr () const
 Return a pointer to the current buffer position.
auto_bufoperator<< (const E &c)
 Insertion operator for a single element.
auto_bufoperator<< (const E *s)
 Insertion operator for a 0 terminated element string.
E & operator[] (size_t offset)
 Array operator.
const E & operator[] (size_t offset) const
 Array operator (const version).

Protected Member Functions

void grow (size_t n)
 Reserve at least n bytes in the buffer.
void extendp (size_t n)
 Extend the buffer by n bytes from the current position.

Protected Attributes

size_t m_length
 Length of the controlled sequence.
size_t m_capacity
 Reserved space.
size_t m_pos
 Current output position.
E * m_buf
 The base of the controlled sequence.


Detailed Description

template<class E>
class OW32::auto_buf< E >

A growable buffer class.

Parameters:
E The type of element to store
This is basically a munged version of ostrstream, which is not thread safe (deliberately), does not format and doesn't require freeze().


Member Enumeration Documentation

template<class E>
enum OW32::auto_buf::seekdir
 

Direction constants for seekp.

Enumeration values:
beg  From the start of the buffer.
cur  From the current position.
end  From the end of the buffer.


Constructor & Destructor Documentation

template<class E>
OW32::auto_buf< E >::auto_buf  )  [inline]
 

Default constructor to create an empty buffer.

Throws no exceptions.

template<class E>
OW32::auto_buf< E >::auto_buf const E *  s  )  [inline]
 

Constructor that copies a zero terminated element string using write.

Parameters:
s The string to copy
May throw std::bad_alloc.

template<class E>
OW32::auto_buf< E >::auto_buf const E *  s,
size_t  n
[inline]
 

Constructor that copies an element string using write.

Parameters:
s The string to copy
n The length of the element string
May throw std::bad_alloc.

template<class E>
OW32::auto_buf< E >::auto_buf const auto_buf< E > &  rhs  )  [inline]
 

Constructor to copy one buffer to another.

Parameters:
rhs The buffer to copy


Member Function Documentation

template<class E>
void OW32::auto_buf< E >::attach E *  buf,
size_t  capacity
[inline]
 

Attach the given buffer.

Parameters:
buf The buffer to attach
capacity The capacity of the buffer
By default, the length is set to the capacity and the seek position points to the buffer's start. Use resize and seekp respectively to adjust these values.

The encapsulated buffer will be freed with free().

template<class E>
size_t OW32::auto_buf< E >::capacity  )  const [inline]
 

Return the reserved size of the buffer.

Returns:
The reserved size of the buffer

template<class E>
void OW32::auto_buf< E >::clear  )  [inline]
 

Clear the buffer.

Note: does not reallocate, buffer will keep the same reserve capacity. See also reset.

template<class E>
size_t OW32::auto_buf< E >::count  )  const [inline]
 

Returns the length of the controlled sequence.

Returns:
The length of the controlled sequence

template<class E>
E* OW32::auto_buf< E >::cstr  )  const [inline]
 

Return a pointer to the current buffer position.

Returns:
Current buffer position

template<class E>
E* OW32::auto_buf< E >::detach  )  [inline]
 

Detach the encapsulated buffer and return.

Returns:
The encapsulated buffer
The application is responsible for freeing the returned buffer using free().

template<class E>
void OW32::auto_buf< E >::extendp size_t  n  )  [inline, protected]
 

Extend the buffer by n bytes from the current position.

Parameters:
n The number of bytes to extend by.

template<class E>
void OW32::auto_buf< E >::grow size_t  n  )  [inline, protected]
 

Reserve at least n bytes in the buffer.

Parameters:
n The number of bytes to reserve.

template<class E>
size_t OW32::auto_buf< E >::length  )  const [inline]
 

Returns the length of the controlled sequence.

Returns:
The length of the controlled sequence

template<class E>
auto_buf& OW32::auto_buf< E >::operator<< const E *  s  )  [inline]
 

Insertion operator for a 0 terminated element string.

Parameters:
s The string to insert

Reimplemented in OW32::auto_byte_buf.

template<class E>
auto_buf& OW32::auto_buf< E >::operator<< const E &  c  )  [inline]
 

Insertion operator for a single element.

Parameters:
c The element to insert

Reimplemented in OW32::auto_byte_buf.

template<class E>
auto_buf& OW32::auto_buf< E >::operator= const auto_buf< E > &  rhs  )  [inline]
 

Assignment operator, copies one buffer to another.

Parameters:
rhs The buffer to copy.

template<class E>
const E& OW32::auto_buf< E >::operator[] size_t  offset  )  const [inline]
 

Array operator (const version).

Returns:
A const reference to the element at offset
Parameters:
offset The offset of the element

template<class E>
E& OW32::auto_buf< E >::operator[] size_t  offset  )  [inline]
 

Array operator.

Returns:
A reference to the element at offset
Parameters:
offset The offset of the element

template<class E>
void OW32::auto_buf< E >::put c  )  [inline]
 

Put a single element.

Parameters:
c The element to put.

template<class E>
void OW32::auto_buf< E >::reserve size_t  n  )  [inline]
 

Reserve space for at least N chars.

Parameters:
n The number of characters to reserve space for

template<class E>
void OW32::auto_buf< E >::reset  )  [inline]
 

Reset the buffer.

As for clear, but frees any allocated storage.

template<class E>
void OW32::auto_buf< E >::resize size_t  n  )  [inline]
 

Resize the controlled sequence to N elements.

Parameters:
n The new length of the sequence.
If the output position was pointing past the end of the controlled sequence, it is reset to point to the new ending position.

template<class E>
void OW32::auto_buf< E >::seekp int  off,
seekdir  way
[inline]
 

Seek to an absolute offset.

Parameters:
off The distance to seek
way The direction to seek in
Seeking past the end of the buffer will extend it.

template<class E>
void OW32::auto_buf< E >::seekp size_t  p  )  [inline]
 

Seek to an absolute offset.

Parameters:
p The offset to seek to.
Seeking past the end of the buffer will extend it.

template<class E>
size_t OW32::auto_buf< E >::size  )  const [inline]
 

Returns the length of the controlled sequence.

Returns:
The length of the controlled sequence

template<class E>
E* OW32::auto_buf< E >::str  )  const [inline]
 

Return a pointer to the base of the controlled sequence.

Returns:
A pointer to the buffer's base

template<class E>
size_t OW32::auto_buf< E >::tellp  )  const [inline]
 

Return the current seek position.

Returns:
The current seek position

template<class E>
size_t OW32::auto_buf< E >::write const E *  s  )  [inline]
 

Put a block of elements, terminated by a 0.

Parameters:
s The block to put
Returns:
The number of elements written
Does not copy the terminating 0 to the buf

Reimplemented in OW32::auto_byte_buf.

template<class E>
size_t OW32::auto_buf< E >::write const E *  s,
size_t  n
[inline]
 

Put a block of elements.

Parameters:
s The block to put
n The number of elements in the block
Returns:
The number of elements written


The documentation for this class was generated from the following file:
Generated on Sun Jun 5 01:29:23 2005 for OW32 by  doxygen 1.3.9.1