My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BufStr Class Reference

Buffer used to store strings. More...

#include <bufstr.h>

Public Member Functions

 BufStr (int size)
 
 ~BufStr ()
 
void addChar (char c)
 
void addArray (const char *a, int len)
 
void skip (uint s)
 
void shrink (uint newlen)
 
void resize (uint newlen)
 
int size () const
 
char * data () const
 
char & at (uint i) const
 
bool isEmpty () const
 
 operator const char * () const
 
uint curPos () const
 
void dropFromStart (uint bytes)
 

Private Member Functions

void makeRoomFor (uint size)
 

Private Attributes

uint m_size
 
uint m_writeOffset
 
const int m_spareRoom
 
char * m_buf
 

Detailed Description

Buffer used to store strings.

This buffer is used append characters and strings. It will automatically resize itself, yet provide efficient random access to the content.

Definition at line 30 of file bufstr.h.

Constructor & Destructor Documentation

BufStr::BufStr ( int  size)
inline

Definition at line 33 of file bufstr.h.

References m_buf.

{
m_buf = (char *)calloc(size,1);
}
BufStr::~BufStr ( )
inline

Definition at line 38 of file bufstr.h.

References m_buf.

{
free(m_buf);
}

Member Function Documentation

void BufStr::addArray ( const char *  a,
int  len 
)
inline

Definition at line 47 of file bufstr.h.

References m_buf, m_writeOffset, and makeRoomFor().

Referenced by readInputFile().

{
memcpy(m_buf+m_writeOffset,a,len);
}
void BufStr::addChar ( char  c)
inline

Definition at line 42 of file bufstr.h.

References m_buf, m_writeOffset, and makeRoomFor().

Referenced by readInputFile().

char& BufStr::at ( uint  i) const
inline

Definition at line 85 of file bufstr.h.

References m_buf.

Referenced by readInputFile().

{
return m_buf[i];
}
uint BufStr::curPos ( ) const
inline

Definition at line 97 of file bufstr.h.

References m_writeOffset.

Referenced by readInputFile().

{
return m_writeOffset;
}
char* BufStr::data ( ) const
inline

Definition at line 81 of file bufstr.h.

References m_buf.

Referenced by readInputFile(), removeEmptyLines(), and transcodeCharacterBuffer().

{
return m_buf;
}
void BufStr::dropFromStart ( uint  bytes)
inline

Definition at line 101 of file bufstr.h.

References m_buf, m_size, and m_writeOffset.

Referenced by readInputFile().

{
if (bytes>m_size) bytes=m_size;
if (bytes>0) qmemmove(m_buf,m_buf+bytes,m_size-bytes);
m_size-=bytes;
m_writeOffset-=bytes;
}
bool BufStr::isEmpty ( ) const
inline

Definition at line 89 of file bufstr.h.

References m_writeOffset.

{
return m_writeOffset==0;
}
void BufStr::makeRoomFor ( uint  size)
inlineprivate

Definition at line 109 of file bufstr.h.

References m_size, m_spareRoom, m_writeOffset, and resize().

Referenced by addArray(), addChar(), and skip().

BufStr::operator const char * ( ) const
inline

Definition at line 93 of file bufstr.h.

References m_buf.

{
return m_buf;
}
void BufStr::resize ( uint  newlen)
inline

Definition at line 63 of file bufstr.h.

References m_buf, m_size, m_spareRoom, and m_writeOffset.

Referenced by makeRoomFor(), and shrink().

{
uint oldsize = m_size;
m_size=newlen;
if (m_writeOffset>=m_size) // offset out of range -> enlarge
{
}
m_buf = (char *)realloc(m_buf,m_size);
if (m_size>oldsize)
{
memset(m_buf+oldsize,0,m_size-oldsize);
}
}
void BufStr::shrink ( uint  newlen)
inline

Definition at line 58 of file bufstr.h.

References m_writeOffset, and resize().

Referenced by readInputFile(), and transcodeCharacterBuffer().

{
m_writeOffset=newlen;
resize(newlen);
}
int BufStr::size ( ) const
inline

Definition at line 77 of file bufstr.h.

References m_size.

{
return m_size;
}
void BufStr::skip ( uint  s)
inline

Definition at line 53 of file bufstr.h.

References m_writeOffset, and makeRoomFor().

Referenced by readInputFile().

Member Data Documentation

char* BufStr::m_buf
private
uint BufStr::m_size
private

Definition at line 116 of file bufstr.h.

Referenced by dropFromStart(), makeRoomFor(), resize(), and size().

const int BufStr::m_spareRoom
private

Definition at line 118 of file bufstr.h.

Referenced by makeRoomFor(), and resize().

uint BufStr::m_writeOffset
private

Definition at line 117 of file bufstr.h.

Referenced by addArray(), addChar(), curPos(), dropFromStart(), isEmpty(), makeRoomFor(), resize(), shrink(), and skip().


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