Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

HBuffer< BUF_LEN > Class Template Reference
[Abstract Data Types]

#include <HBuffer.h>

Inheritance diagram for HBuffer< BUF_LEN >:

HObjNoCopy HObj

Detailed Description

template<uint32 BUF_LEN>
class HBuffer< BUF_LEN >

A ring buffer is designed to facilitate the reading/writing of data into (and out of) a statically allocated memory buffer. It is based on code published in the article Fast Ring Buffer for Incoming Winsock Textual Data by Larry Antram.

Definition at line 25 of file HBuffer.h.

Public Member Functions

ErrCode Find (uint8 xWanted, uint32 &uOffset) const
 Returns the first offset of a byte in the buffer.
ErrCode FindLast (const uint8 xWanted, uint32 &uOffset) const
 Returns the last offset of a byte in the buffer.
ErrCode Read (Ptr pBuf, const uint32 uBufLen)
 Reads data from the buffer.
ErrCode ReadLine (TextPtr psz, const int32 nMaxLen, bool bChomp=true)
 Reads a line of text up to a given length.
ErrCode Reset (void)
 Resets the buffer to an 'empty' state.
ErrCode Write (PtrConst pBuf, uint32 uDataLen)
 Writes binary data into the buffer.
ErrCode WriteLine (StringPtr pstr, int32 nMaxLen=-1)
 Writes a line of text up to a given length.
uint8 GetAt (const uint32 uOffset) const
 Returns the byte at a given offset.
uint32 GetSize (void) const
 Returns the maximum amount of data the buffer will hold.
uint32 GetDataBytes (void) const
 Returns the amount of data currently in the buffer.
uint32 GetFreeBytes (void) const
 Returns the amount of free space left in the buffer.
bool CanRead (uint32 uWanted=1) const
 Determines if there is data pending in the buffer.
bool IsEmpty (void) const
 Fast check for data in the buffer.
ErrCode Zero (void)
 Sets the entire buffer to zero.
uint8 operator[] (uint32 udx) const

Protected Attributes

uint32 m_uBytes
 Count of data bytes in buffer.
uint32 m_uRead
 Offset to next read location.
uint32 m_uWrite
 Offset to next write location.
uint8 m_data [BUF_LEN]
 Actual data buffer.


Member Function Documentation

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::Find uint8  xWanted,
uint32 &  uOffset
const
 

Returns:
NO_ERROR if found, error code otherwise
Parameters:
xWanted Byte value to look for
[out] uOffset Offset found at, undefined if not found

Definition at line 65 of file HBuffer.h.

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::FindLast const uint8  xWanted,
uint32 &  uOffset
const
 

Returns:
NO_ERROR if found, error code otherwise
Parameters:
xWanted Byte value to look for
[out] uOffset Offset found at, undefined if not found

Definition at line 87 of file HBuffer.h.

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::Read Ptr  pBuf,
const uint32  uBufLen
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
pBuf Ptr to buffer to receive data
uBufLen Count of bytes to read

Definition at line 107 of file HBuffer.h.

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::ReadLine TextPtr  psz,
const int32  nMaxLen,
bool  bChomp = true
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
psz Ptr to string buffer to receive text
nMaxLen Maximum string length
bChomp True to discard trailing whitespace

Definition at line 181 of file HBuffer.h.

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::Reset void   ) 
 

This method set the buffer's read/write ptrs to zero, which clears all pending data and makes the entire buffer available for writing.

Returns:
Always NO_ERROR

Definition at line 232 of file HBuffer.h.

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::Write PtrConst  pBuf,
uint32  uDataLen
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
pBuf Ptr to data
uDataLen Count of data bytes to write

Definition at line 245 of file HBuffer.h.

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::WriteLine StringPtr  pstr,
int32  nMaxLen = -1
 

Returns:
NO_ERROR on success, error code otherwise
Parameters:
pstr Ptr to string buffer containing text
nMaxLen Maximum character count to write (or <0 for C string)

Definition at line 319 of file HBuffer.h.

template<uint32 BUF_LEN>
uint8 HBuffer< BUF_LEN >::GetAt const uint32  uOffset  )  const
 

Returns:
Byte value, or 0xFF if invalid offset
Parameters:
uOffset Offset of byte to peek at

Definition at line 350 of file HBuffer.h.

template<uint32 BUF_LEN>
uint32 HBuffer< BUF_LEN >::GetSize void   )  const
 

Returns:
Total size of buffer (in bytes)

Definition at line 376 of file HBuffer.h.

template<uint32 BUF_LEN>
uint32 HBuffer< BUF_LEN >::GetDataBytes void   )  const
 

Returns:
Count of data (in bytes) available for reading

Definition at line 383 of file HBuffer.h.

template<uint32 BUF_LEN>
uint32 HBuffer< BUF_LEN >::GetFreeBytes void   )  const
 

Returns:
Total free space available in buffer (in bytes)

Definition at line 390 of file HBuffer.h.

template<uint32 BUF_LEN>
bool HBuffer< BUF_LEN >::CanRead uint32  uWanted = 1  )  const
 

Returns:
True if data avialable, false otherwise
Parameters:
uWanted Count of bytes wanted (defaults to 1)

Definition at line 398 of file HBuffer.h.

template<uint32 BUF_LEN>
bool HBuffer< BUF_LEN >::IsEmpty void   )  const
 

Returns:
True if NO data avialable, false otherwise

Definition at line 402 of file HBuffer.h.

template<uint32 BUF_LEN>
ErrCode HBuffer< BUF_LEN >::Zero void   ) 
 

Returns:
Always NO_ERROR

Definition at line 406 of file HBuffer.h.


The documentation for this class was generated from the following file:
 

2006.01.09-16:37