Buffer Management

This file contains the definition of a GWEN_BUFFER, a dynamically resizeable text buffer. More...

Defines

#define GWEN_BUFFER_MAX_BOOKMARKS   4
#define GWEN_BUFFER_MODE_ABORT_ON_MEMFULL   0x0002
#define GWEN_BUFFER_MODE_DEFAULT
#define GWEN_BUFFER_MODE_DYNAMIC   0x0001
#define GWEN_BUFFER_MODE_USE_BIO   0x0004

Typedefs

typedef GWEN_BUFFER GWEN_BUFFER
 A dynamically resizeable text buffer.

Functions

GWENHYWFAR_API void GWEN_Buffer_AddMode (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 mode)
GWENHYWFAR_API int GWEN_Buffer_AdjustUsedBytes (GWEN_BUFFER *bf)
GWENHYWFAR_API int GWEN_Buffer_AllocRoom (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 size)
GWENHYWFAR_API int GWEN_Buffer_AppendBuffer (GWEN_BUFFER *bf, GWEN_BUFFER *sf)
GWENHYWFAR_API int GWEN_Buffer_AppendByte (GWEN_BUFFER *bf, char c)
GWENHYWFAR_API int GWEN_Buffer_AppendBytes (GWEN_BUFFER *bf, const char *buffer, GWEN_TYPE_UINT32 size)
GWENHYWFAR_API int GWEN_Buffer_AppendString (GWEN_BUFFER *bf, const char *buffer)
GWENHYWFAR_API int GWEN_Buffer_Crop (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 pos, GWEN_TYPE_UINT32 l)
GWENHYWFAR_API int GWEN_Buffer_DecrementPos (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 i)
GWENHYWFAR_API void GWEN_Buffer_Dump (GWEN_BUFFER *bf, FILE *f, unsigned int insert)
GWENHYWFAR_API GWEN_BUFFERGWEN_Buffer_dup (GWEN_BUFFER *bf)
GWENHYWFAR_API int GWEN_Buffer_FillLeftWithBytes (GWEN_BUFFER *bf, unsigned char c, GWEN_TYPE_UINT32 size)
GWENHYWFAR_API int GWEN_Buffer_FillWithBytes (GWEN_BUFFER *bf, unsigned char c, GWEN_TYPE_UINT32 size)
GWENHYWFAR_API void GWEN_Buffer_free (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetBookmark (GWEN_BUFFER *bf, unsigned int idx)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetBytesLeft (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetHardLimit (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetMaxUnsegmentedWrite (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetMode (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetPos (GWEN_BUFFER *bf)
GWENHYWFAR_API char * GWEN_Buffer_GetPosPointer (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetSize (GWEN_BUFFER *bf)
GWENHYWFAR_API char * GWEN_Buffer_GetStart (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetStep (GWEN_BUFFER *bf)
GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetUsedBytes (GWEN_BUFFER *bf)
GWENHYWFAR_API int GWEN_Buffer_IncrementPos (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 i)
GWENHYWFAR_API int GWEN_Buffer_InsertBuffer (GWEN_BUFFER *bf, GWEN_BUFFER *sf)
GWENHYWFAR_API int GWEN_Buffer_InsertByte (GWEN_BUFFER *bf, char c)
GWENHYWFAR_API int GWEN_Buffer_InsertBytes (GWEN_BUFFER *bf, const char *buffer, GWEN_TYPE_UINT32 size)
GWENHYWFAR_API int GWEN_Buffer_InsertRoom (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 size)
GWENHYWFAR_API int GWEN_Buffer_InsertString (GWEN_BUFFER *bf, const char *buffer)
GWENHYWFAR_API GWEN_BUFFERGWEN_Buffer_new (char *buffer, GWEN_TYPE_UINT32 size, GWEN_TYPE_UINT32 used, int take_ownership)
GWENHYWFAR_API int GWEN_Buffer_PeekByte (GWEN_BUFFER *bf)
GWENHYWFAR_API int GWEN_Buffer_ReadByte (GWEN_BUFFER *bf)
GWENHYWFAR_API int GWEN_Buffer_ReadBytes (GWEN_BUFFER *bf, char *buffer, GWEN_TYPE_UINT32 *size)
GWENHYWFAR_API int GWEN_Buffer_ReserveBytes (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 res)
GWENHYWFAR_API void GWEN_Buffer_Reset (GWEN_BUFFER *bf)
GWENHYWFAR_API void GWEN_Buffer_Rewind (GWEN_BUFFER *bf)
GWENHYWFAR_API void GWEN_Buffer_SetBookmark (GWEN_BUFFER *bf, unsigned int idx, GWEN_TYPE_UINT32 v)
GWENHYWFAR_API void GWEN_Buffer_SetHardLimit (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 l)
GWENHYWFAR_API void GWEN_Buffer_SetMode (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 mode)
GWENHYWFAR_API int GWEN_Buffer_SetPos (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 i)
GWENHYWFAR_API void GWEN_Buffer_SetSourceBIO (GWEN_BUFFER *bf, GWEN_BUFFEREDIO *bio, int take)
GWENHYWFAR_API void GWEN_Buffer_SetStep (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 step)
GWENHYWFAR_API int GWEN_Buffer_SetUsedBytes (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 i)
GWENHYWFAR_API void GWEN_Buffer_SubMode (GWEN_BUFFER *bf, GWEN_TYPE_UINT32 mode)

Detailed Description

This file contains the definition of a GWEN_BUFFER, a dynamically resizeable text buffer.


Define Documentation

#define GWEN_BUFFER_MAX_BOOKMARKS   4

Definition at line 67 of file buffer.h.

#define GWEN_BUFFER_MODE_ABORT_ON_MEMFULL   0x0002

Definition at line 70 of file buffer.h.

#define GWEN_BUFFER_MODE_DEFAULT

Value:

Definition at line 73 of file buffer.h.

#define GWEN_BUFFER_MODE_DYNAMIC   0x0001

Definition at line 69 of file buffer.h.

#define GWEN_BUFFER_MODE_USE_BIO   0x0004

Definition at line 71 of file buffer.h.


Typedef Documentation

typedef struct GWEN_BUFFER GWEN_BUFFER

A dynamically resizeable text buffer.

Definition at line 41 of file buffer.h.


Function Documentation

GWENHYWFAR_API void GWEN_Buffer_AddMode ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  mode 
)

Adds the give mode to the current mode of the buffer (such as GWEN_BUFFER_MODE_DYNAMIC).

GWENHYWFAR_API int GWEN_Buffer_AdjustUsedBytes ( GWEN_BUFFER bf  ) 

GWENHYWFAR_API int GWEN_Buffer_AllocRoom ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  size 
)

Make sure that the buffer has enough room for the given bytes.

GWENHYWFAR_API int GWEN_Buffer_AppendBuffer ( GWEN_BUFFER bf,
GWEN_BUFFER sf 
)

Append the content of the buffer sf at the end of the buffer bf. The size of bf will be increased accordingly. Returns zero on success or nonzero if this failed (e.g. because of out of memory error).

GWENHYWFAR_API int GWEN_Buffer_AppendByte ( GWEN_BUFFER bf,
char  c 
)

Appends a single byte to this GWEN_BUFFER, if there is enough room. The position pointer is adjusted accordingly.

Returns:
0 if ok, !=0 on error

GWENHYWFAR_API int GWEN_Buffer_AppendBytes ( GWEN_BUFFER bf,
const char *  buffer,
GWEN_TYPE_UINT32  size 
)

Copies the contents of the given buffer to this GWEN_BUFFER, if there is enough room. The position pointer is adjusted accordingly.

Returns:
0 if ok, !=0 on error

GWENHYWFAR_API int GWEN_Buffer_AppendString ( GWEN_BUFFER bf,
const char *  buffer 
)

Appends a string to the buffer (without the trailing null char!) The position pointer is adjusted accordingly.

Returns:
0 if ok, !=0 on error

GWENHYWFAR_API int GWEN_Buffer_Crop ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  pos,
GWEN_TYPE_UINT32  l 
)

GWENHYWFAR_API int GWEN_Buffer_DecrementPos ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  i 
)

Move the position pointer backward by the given number i.

GWENHYWFAR_API void GWEN_Buffer_Dump ( GWEN_BUFFER bf,
FILE *  f,
unsigned int  insert 
)

Print the current content of buffer bf into the file f.

GWENHYWFAR_API GWEN_BUFFER* GWEN_Buffer_dup ( GWEN_BUFFER bf  ) 

Create a new copy as a duplicate of the buffer bf.

GWENHYWFAR_API int GWEN_Buffer_FillLeftWithBytes ( GWEN_BUFFER bf,
unsigned char  c,
GWEN_TYPE_UINT32  size 
)

GWENHYWFAR_API int GWEN_Buffer_FillWithBytes ( GWEN_BUFFER bf,
unsigned char  c,
GWEN_TYPE_UINT32  size 
)

GWENHYWFAR_API void GWEN_Buffer_free ( GWEN_BUFFER bf  ) 

Frees the given buffer.

If the internal storage was allocated for this new buffer, then it will freed here. If the internal storage is used from a different buffer, then it will only be freed if the argument take_ownership of GWEN_Buffer_new() was nonzero.

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetBookmark ( GWEN_BUFFER bf,
unsigned int  idx 
)

Returns the given bookmark

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetBytesLeft ( GWEN_BUFFER bf  ) 

Returns the number of bytes from pos to the end of the used area.

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetHardLimit ( GWEN_BUFFER bf  ) 

Returns the hard limit. This is the maximum size of a GWEN_BUFFER in dynamic mode.

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetMaxUnsegmentedWrite ( GWEN_BUFFER bf  ) 

Returns the maximum number of bytes which can be written to the buffer at once (i.e. without reallocation).

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetMode ( GWEN_BUFFER bf  ) 

Returns the current mode of the buffer (such as GWEN_BUFFER_MODE_DYNAMIC).

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetPos ( GWEN_BUFFER bf  ) 

Returns the current position within the buffer. This pointer is adjusted by the various read and write functions.

GWENHYWFAR_API char* GWEN_Buffer_GetPosPointer ( GWEN_BUFFER bf  ) 

Returns a pointer to the current position within the buffer.

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetSize ( GWEN_BUFFER bf  ) 

Returns the size of the buffer (i.e. the number of bytes allocated).

GWENHYWFAR_API char* GWEN_Buffer_GetStart ( GWEN_BUFFER bf  ) 

Returns the start of the buffer. You can use the function GWEN_Buffer_GetPos to navigate within the buffer.

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetStep ( GWEN_BUFFER bf  ) 

In dynamic mode, whenever there is new data to allocate then this value specifies how much data to allocate in addition. The allocated data in total for this buffer will be aligned to this value.

GWENHYWFAR_API GWEN_TYPE_UINT32 GWEN_Buffer_GetUsedBytes ( GWEN_BUFFER bf  ) 

GWENHYWFAR_API int GWEN_Buffer_IncrementPos ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  i 
)

Move the position pointer forward by the given number i.

GWENHYWFAR_API int GWEN_Buffer_InsertBuffer ( GWEN_BUFFER bf,
GWEN_BUFFER sf 
)

Insert the content of the buffer sf into the buffer bf at the position of its current position pointer. The size of bf will be increased accordingly. Returns zero on success or nonzero if this failed (e.g. because of out of memory error).

GWENHYWFAR_API int GWEN_Buffer_InsertByte ( GWEN_BUFFER bf,
char  c 
)

Inserts a byte at the current position. If the current position is 0 and there is reserved space at the beginning of the buffer then that space will be used. Otherwise the data at the current position will be moved out of the way and the new byte inserted. The position pointer will not be altered, but after calling this function at that position there is the begin of the newly inserted byte. All pointers obtained from this module (e.g. via GWEN_Buffer_GetStart) become invalid !

GWENHYWFAR_API int GWEN_Buffer_InsertBytes ( GWEN_BUFFER bf,
const char *  buffer,
GWEN_TYPE_UINT32  size 
)

Inserts multiple bytes at the current position. If the current position is 0 and there is reserved space at the beginning of the buffer then that space will be used. Otherwise the data at the current position will be moved out of the way and the new bytes inserted. The position pointer will not be altered, but all pointers obtained from this module (e.g. via GWEN_Buffer_GetStart) become invalid !

GWENHYWFAR_API int GWEN_Buffer_InsertRoom ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  size 
)

This function makes room for the given number of bytes at the current buffer position. It moves any existing data at the current position out of the way. The position pointer will not be altered, but after calling this function at that position there is the begin of the newly inserted room. All pointers obtained from this module (e.g. via GWEN_Buffer_GetStart) become invalid !

GWENHYWFAR_API int GWEN_Buffer_InsertString ( GWEN_BUFFER bf,
const char *  buffer 
)

Inserts the given string at the current position (without the trailing null byte) The position pointer will not be altered, but after calling this function at that position there is the begin of the newly inserted string. All pointers obtained from this module (e.g. via GWEN_Buffer_GetStart) become invalid !

GWENHYWFAR_API GWEN_BUFFER* GWEN_Buffer_new ( char *  buffer,
GWEN_TYPE_UINT32  size,
GWEN_TYPE_UINT32  used,
int  take_ownership 
)

Creates a new GWEN_BUFFER, which is a dynamically resizeable text buffer.

Parameters:
buffer If non-NULL, then this buffer will be used as actual storage space. Otherwise a new buffer will be allocated (with size bytes)
size If buffer was non-NULL, then this argument must specifiy the size of that buffer. If buffer was NULL, then this argument specifies the number of bytes that will be allocated.
used Number of bytes of the buffer actually used. This is interesting when reading from a buffer.
take_ownership If buffer was non-NULL and this argument is nonzero, then the new GWEN_BUFFER object takes over the ownership of the given buffer so that it will be freed on GWEN_Buffer_free(). If this argument is zero, the given buffer will not be freed. If buffer was NULL, this argument has no effect.

GWENHYWFAR_API int GWEN_Buffer_PeekByte ( GWEN_BUFFER bf  ) 

Returns the byte from the current position without changing the position pointer. So multiple calls to this function will result in returning the same character.

Returns:
-1 on error, read char otherwise (in low byte)

GWENHYWFAR_API int GWEN_Buffer_ReadByte ( GWEN_BUFFER bf  ) 

Returns the byte from the current position. The position pointer is adjusted accordingly.

Returns:
-1 on error, read char otherwise (in low byte)

GWENHYWFAR_API int GWEN_Buffer_ReadBytes ( GWEN_BUFFER bf,
char *  buffer,
GWEN_TYPE_UINT32 size 
)

Returns the bytes from the current position. The position pointer is adjusted accordingly.

Returns:
-1 on error, 0 if ok

GWENHYWFAR_API int GWEN_Buffer_ReserveBytes ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  res 
)

Reserves the given amount of bytes at the beginning of the buffer. Please note that this most likely results in a shift of the current position inside the buffer, so after this call all pointers obtained from this module (e.g. via GWEN_Buffer_GetStart) are invalid ! You can use this function to save some memory copy actions when inserting bytes at the beginning of the buffer.

GWENHYWFAR_API void GWEN_Buffer_Reset ( GWEN_BUFFER bf  ) 

Resets the position pointer and the byte counter.

GWENHYWFAR_API void GWEN_Buffer_Rewind ( GWEN_BUFFER bf  ) 

Resets the pos pointer

GWENHYWFAR_API void GWEN_Buffer_SetBookmark ( GWEN_BUFFER bf,
unsigned int  idx,
GWEN_TYPE_UINT32  v 
)

Set a bookmark. These bookmarks are not used by the GWEN_BUFFER functions, but may be usefull for an application.

GWENHYWFAR_API void GWEN_Buffer_SetHardLimit ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  l 
)

Changes the hard limit. This is the maximum size of a GWEN_BUFFER in dynamic mode.

GWENHYWFAR_API void GWEN_Buffer_SetMode ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  mode 
)

Changes the current mode of the buffer (such as GWEN_BUFFER_MODE_DYNAMIC).

GWENHYWFAR_API int GWEN_Buffer_SetPos ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  i 
)

Returns:
0 if ok, !=0 on error

GWENHYWFAR_API void GWEN_Buffer_SetSourceBIO ( GWEN_BUFFER bf,
GWEN_BUFFEREDIO bio,
int  take 
)

Sets the buffered input to be used as a source. This BIO is used when a byte is to be returned while the buffer is empty (or the end of the buffer is reached). In such a case the missing bytes are read from this BIO if the mode contains GWEN_BUFFER_MODE_USE_BIO.

GWENHYWFAR_API void GWEN_Buffer_SetStep ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  step 
)

In dynamic mode, whenever there is new data to allocate then this value specifies how much data to allocate in addition. The allocated data in total for this buffer will be aligned to this value. 1024 is a reasonable value. This value NEEDS to be aligned 2^n (i.e. only ONE bit must be set !)

GWENHYWFAR_API int GWEN_Buffer_SetUsedBytes ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  i 
)

Returns:
0 if ok, !=0 on error

GWENHYWFAR_API void GWEN_Buffer_SubMode ( GWEN_BUFFER bf,
GWEN_TYPE_UINT32  mode 
)

Removes the give mode from the current mode of the buffer (such as GWEN_BUFFER_MODE_DYNAMIC).


Generated on Tue May 1 12:56:31 2007 for gwenhywfar by  doxygen 1.5.1