home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WBUFFER.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-18
|
6KB
|
246 lines
/*************************************************************************
*
* WBuffer
*
* This class encapsulates operations on a buffer of arbitrary data.
*
*************************************************************************/
#ifndef _WBUFFER_HPP_INCLUDED
#define _WBUFFER_HPP_INCLUDED
#ifndef _WNO_PRAGMA_PUSH
#pragma pack(push,8);
#pragma enum int;
#endif
#ifndef _WOBJECT_HPP_INCLUDED
# include "wobject.hpp"
#endif
extern "C" {
#include <ctype.h>
#include <string.h>
#include <time.h>
};
class WResourceID;
class WModule;
class WBufferReference;
class WBuffer;
class WString;
//
// WBuffer
//
class WCMCLASS WBuffer : public WObject {
WDeclareSubclass( WBuffer, WObject )
public:
//
// WBufferElement
//
// This class represents an individual byte in a buffer.
//
class WBufferElement {
friend class WBuffer;
public:
WBufferElement& operator=( const WByte ch )
{ buffer.SetByte( index, ch ); return *this; }
WBufferElement& operator=( const WBufferElement & e )
{ buffer.SetByte( index,
e.buffer.GetByte( e.index ) );
return *this; }
operator WByte() const
{ return buffer.GetByte( index ); }
private:
WBufferElement( WBuffer *buf ) : buffer( *buf ), index( 0 ) {}
WBufferElement( const WBufferElement & e );
~WBufferElement() {}
private:
WBuffer& buffer;
WULong index;
};
/**********************************************************
* Constructors and Destructors
*********************************************************/
WBuffer();
WBuffer( WULong size, void * buffer, WBool makeCopy=TRUE,
WBool selfDeleteData=FALSE );
WBuffer( const WBuffer & b, WBool makeCopy=FALSE );
WBuffer( const WString & string, WBool includeNull=TRUE );
~WBuffer();
/*********************************************************
* Operators
*********************************************************/
//
// [] operator
//
const WBufferElement& operator[]( int index ) const;
WBufferElement& operator[]( int index );
//
// casting operators
//
operator const WByte *() const { return GetBuffer(); }
//
// = operator
//
WBuffer & operator=( const WBuffer & s )
{ Create( s ); return *this; }
//
// == operator
//
friend int WEXPORT operator==( const WBuffer & a, const WBuffer & b );
//
// != operator
//
friend int WEXPORT operator!=( const WBuffer & a, const WBuffer & b );
//
// += operator
//
WBuffer& operator+=( const WBuffer & a );
//
// + operator
//
WBuffer operator+( const WBuffer & a ) const;
/**********************************************************
* Properties
*********************************************************/
// Buffer
//
// Return a pointer to the actual buffer. Does not
// lock the buffer -- if you want to make changes,
// use Lock instead.
const WByte *GetBuffer() const;
// Byte
//
// Set/get an individual byte in the buffer.
WByte GetByte( WULong index );
WBool SetByte( WULong index, WByte ch );
// Null
//
// True if it is a null buffer.
WBool GetNull() const;
// Size
//
// Returns the size of the buffer in bytes.
WULong GetSize() const;
/**********************************************************
* Methods
*********************************************************/
// Clear
//
// Frees the buffer.
void Clear();
// Concat
//
// Concatenate a buffer onto another.
WBool Concat( const WBuffer & suffix );
// Create
//
// Various constructors for building a new buffer.
// First frees the old buffer.
WBool Create();
WBool Create( WULong size, void * buffer=NULL, WBool makeCopy=TRUE,
WBool selfDeleteData=FALSE );
WBool Create( const WBuffer & s, WBool makeCopy=FALSE );
WBool Create( const WString & str, WBool includeNull=TRUE );
// Fill
//
// Fill the buffer with a given byte.
WBool Fill( const WByte byte );
// Lock
//
// Call this if you want to work directly on the buffer
// inside the WBuffer. It will ensure that no one else
// is referencing it, that it has a minimum size (in bytes),
// and return its pointer. Call Unlock when you're done.
WByte *Lock( WULong minimumSize=0 );
// Unlock
//
// Call this when done writing directly to the buffer.
WBool Unlock();
/**********************************************************
* Static Properties
*********************************************************/
static const WBuffer & GetNullBuffer();
/**********************************************************
* Private
*********************************************************/
protected:
WBool ReallocateRef( WULong minimumSize );
WBool GrowTo( WULong size );
protected:
WBufferReference *_ref;
const WByte *_bufferData; // for easier debugging only!
WBufferElement _element;
};
#ifndef _WNO_PRAGMA_PUSH
#pragma enum pop;
#pragma pack(pop);
#endif
#endif // _WBUFFER_HPP_INCLUDED