Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

databuf Class Reference

Inherits constbuf.

Inherited by dynbuf.

List of all members.


Detailed Description

A mutable data buffer.

Basically equivalent to a pair<void *, size_t>: this is just a convenient way of passing a reference to a mutable data buffer.

A databuf actually contains both a "current length" and a "maximum length" for the data buffer; for instance, one may allocate n bytes of storage, and the constructor databuf(mem, 0, n) to reflect the fact that there is currently no data in the buffer but that it has space for a kilobyte of data. Input routines such as IOHandle::read generally read up to max_length() bytes and use set_length() to reflect the number of bytes actually nead.

    char *mem = malloc(1024);
    databuf buf(mem, 0, 1024);
    my_iohandle.read(buf); // read up to 1024 bytes
    cout << "I just read " << buf.length() << " bytes" << endl;

Note that a databuf may be cast to a constbuf (just as a void * can be implicitly cast to a const void *) but not vice versa.


Public Methods

 databuf ()
 Null constructor.

 databuf (void *dat, unsigned int len)
 Constructs a reference to a mutable data buffer.

 databuf (void *dat, unsigned int len, unsigned int maxlen)
 Constructs a reference to a mutable data buffer whose size may change.

char * data ()
 Returns a pointer to the beginning of the data buffer.

void set_length (unsigned int len)
 Modifies the length of the data buffer.

unsigned int max_length () const
 Returns the maximum length of the data buffer.


Protected Attributes

unsigned int maxlen


Constructor & Destructor Documentation

databuf::databuf  
 

Null constructor.

databuf::databuf void *    dat,
unsigned int    len
 

Constructs a reference to a mutable data buffer.

Both its current length and maximum length are len.

databuf::databuf void *    dat,
unsigned int    len,
unsigned int    maxlen
 

Constructs a reference to a mutable data buffer whose size may change.

Parameters:
dat  a pointer to the data buffer.
len  the current length of the data buffer.
maxlen  the maximum length of the data buffer.


Member Function Documentation

char* databuf::data  
 

Returns a pointer to the beginning of the data buffer.

unsigned int databuf::max_length   const
 

Returns the maximum length of the data buffer.

void databuf::set_length unsigned int    len
 

Modifies the length of the data buffer.


Member Data Documentation

unsigned int databuf::maxlen [protected]
 


The documentation for this class was generated from the following file:
Generated on Fri Dec 20 13:35:11 2002 for NMSTL