Cross-Platform C++

ot
class AutoBuffer< T >

#include "ot/base/AutoBuffer.h"

An efficient buffer that will automatically grow to hold the required data. AutoBuffer is often used internally within OpenTop when building String objects.

In the following example an AutoBuffer is created to hold a string containing all the Unicode characters from U+0000 - U+1000.

    AutoBuffer<CharType> charBuffer;
    for(UCS4Char cp=0; cp<0x1000; ++cp)
    {
        // convert the Unicode code-point into a Character
        Character ch(cp);	
        // append the CharType sequence from ch onto our buffer
        charBuffer.append(ch.data(), ch.length());
    }




Constructor/Destructor Summary
AutoBuffer()
         Default constructor which creates an internal buffer with a default initial size.
AutoBuffer(size_t initialSize)
         Default constructor which creates an internal buffer with an initial size of initialSize.
~AutoBuffer()
         Destructor.

Method Summary
 void append(T data)
         Appends a single element of type T to the internal buffer.
 void append(const T* pData, size_t length)
         Appends an array of elements of type T to the internal buffer.
 size_t capacity() const
         Returns the allocated size of the internal buffer.
 void clear()
         Clears the internal buffer for re-use - the memory is not freed.
 const T* data() const
         Returns a const pointer to the start of the internal buffer.
 void destroy()
         Frees the internal buffer.
 size_t size() const
         Returns the number of buffer elements currently in use.

Typedefs

DataType

typedef T DataType

Constructor/Destructor Detail

AutoBuffer

 AutoBuffer()
Default constructor which creates an internal buffer with a default initial size.


AutoBuffer

 AutoBuffer(size_t initialSize)
Default constructor which creates an internal buffer with an initial size of initialSize.

Parameters:
initialSize - the initial size of the internal buffer.

~AutoBuffer

 ~AutoBuffer()
Destructor. The internal buffer is freed.


Method Detail

append

void append(T data)
Appends a single element of type T to the internal buffer. The buffer is re-sized if necessary.

Parameters:
data - the element to append to the internal buffer

append

void append(const T* pData,
            size_t length)
Appends an array of elements of type T to the internal buffer. The buffer is re-sized if necessary.

Parameters:
pData - a pointer to the first element in the array
length - the number of elements to append

capacity

size_t capacity() const
Returns the allocated size of the internal buffer. This is not necessarily the number of buffer elements that are currently being used.

See also:
size()

clear

void clear()
Clears the internal buffer for re-use - the memory is not freed.


data

const T* data() const
Returns a const pointer to the start of the internal buffer.


destroy

void destroy()
Frees the internal buffer. Subsequent append() operations will cause a new buffer to be allocated.


size

size_t size() const
Returns the number of buffer elements currently in use. This is not the same as the capacity of the buffer.

See also:
capacity()


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements