/* libzz
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2000-2006, Toni Thomsson <toni@tonjac.org> 
*/

#ifndef zz_buffer_h
#define zz_buffer_h

#include <zz_export.h>

/**
    General data buffer with automatic memory handeling.

    @author Toni Thomsson, toni@tonjac.org
*/
class ZZ_API CzzBuffer
{
public:

    /**
        Create a buffer

        @param initsize Initial size in bytes
        @param realloc  Size of reallocation block
    */
    CzzBuffer( unsigned long initsize, unsigned long realloc );
    
    /**
        Create a buffer. Reallocation size of 1024 bytes.

        @param initsize Initial size in bytes
    */
    CzzBuffer( unsigned long initsize );

    virtual ~CzzBuffer();

    /**
        Append data to the buffer

        @param more Data to be appended
        @param size Size of the data
    */
    void append( char* more,
                    unsigned long size );

    /** Clears the buffer */
    void clear( void );

    /**
        Pointer to the raw data
    */
    char* getData( void ) { return m_Data; };

    /** Buffer size */
    unsigned long getSize( void ) { return m_Used; };

private:

    unsigned long m_Used;
    unsigned long m_Size;
    unsigned long m_Realloc;
    char* m_Tmp;
    char* m_Data;
};

#endif // zz_buffer_h