Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions

BufferString Class Reference

String with variable length but guaranteed minimum buffer size. More...

List of all members.

Public Member Functions

 BufferString ()
 BufferString (const char *)
 BufferString (int minlen, bool setnull)
 BufferString (const BufferString &bs)
template<class T >
 BufferString (const char *, T, const char *s=0)
virtual ~BufferString ()
BufferStringoperator= (const char *)
BufferStringoperator= (const BufferString &bs)
template<class T >
BufferStringoperator= (T)
bool operator== (const BufferString &) const
bool operator!= (const BufferString &) const
bool operator== (const char *) const
bool operator!= (const char *) const
template<class T >
bool operator== (T) const
template<class T >
bool operator!= (T t) const
char * buf ()
 Allocation of min length guaranteed.
const char * buf () const
const char * str () const
 operator const char * () const
char & operator[] (int idx)
const char & operator[] (int idx) const
bool isEmpty () const
void setEmpty ()
bool isEqual (const char *, bool caseinsens=false) const
bool isStartOf (const char *, bool caseinsens=false) const
bool matches (const char *, bool caseinsens=false) const
BufferStringadd (const char *)
template<class T >
BufferStringadd (T)
BufferStringoperator+= (const char *s)
template<class T >
BufferStringoperator+= (T t)
unsigned int size () const
unsigned int bufSize () const
void setBufSize (unsigned int)
unsigned int minBufSize () const
void setMinBufSize (unsigned int)
void insertAt (int idx, const char *)
void replaceAt (int idx, const char *, bool cutoff=true)
bool operator> (const char *) const
bool operator< (const char *) const
template<class T >
bool operator> (T) const
template<class T >
bool operator< (T) const

Static Public Member Functions

static const BufferStringempty ()

Protected Attributes

char * buf_
unsigned int len_
const unsigned int minlen_

Private Member Functions

void init ()
void destroy ()

Detailed Description

String with variable length but guaranteed minimum buffer size.

The minimum buffer size makes life easier in worlds where strcpy etc. rule. Overhead is 4 extra bytes for variable length and 4 bytes for minimum length.

Passing a (char*) null pointer is no problem.

Don't try to add constructors with a single basic type - this leads to nasty hidden bugs because the compiler will try to convert all kinds of things into BufferStrings. If you just need a string from an int, float, ..., just use str = toString( var ). If you need the BufferString later, use: BufferString istr( "", intvar );


Constructor & Destructor Documentation

BufferString::BufferString (  )  [inline]
BufferString::BufferString ( const char *  s  )  [inline]
BufferString::BufferString ( int  minlen,
bool  setnull 
)
BufferString::BufferString ( const BufferString bs  ) 
template<class T >
BufferString::BufferString ( const char *  s1,
t,
const char *  s = 0 
) [inline]
virtual BufferString::~BufferString (  )  [virtual]

Member Function Documentation

BufferString& BufferString::add ( const char *   ) 
template<class T >
BufferString & BufferString::add ( t  )  [inline]
char* BufferString::buf (  ) 

Allocation of min length guaranteed.

const char* BufferString::buf (  )  const [inline]
unsigned int BufferString::bufSize (  )  const [inline]
void BufferString::destroy (  )  [inline, private]
static const BufferString& BufferString::empty (  )  [static]
void BufferString::init (  )  [private]
void BufferString::insertAt ( int  idx,
const char *   
)
bool BufferString::isEmpty (  )  const
bool BufferString::isEqual ( const char *  ,
bool  caseinsens = false 
) const
bool BufferString::isStartOf ( const char *  ,
bool  caseinsens = false 
) const
bool BufferString::matches ( const char *  ,
bool  caseinsens = false 
) const
unsigned int BufferString::minBufSize (  )  const [inline]
BufferString::operator const char * (  )  const [inline]
bool BufferString::operator!= ( const BufferString s  )  const [inline]
template<class T >
bool BufferString::operator!= ( t  )  const [inline]
bool BufferString::operator!= ( const char *  s  )  const [inline]
BufferString& BufferString::operator+= ( const char *  s  )  [inline]
template<class T >
BufferString& BufferString::operator+= ( t  )  [inline]
bool BufferString::operator< ( const char *   )  const
template<class T >
bool BufferString::operator< ( t  )  const [inline]
BufferString& BufferString::operator= ( const char *   ) 
BufferString & BufferString::operator= ( const BufferString bs  )  [inline]
template<class T >
BufferString & BufferString::operator= ( t  )  [inline]
bool BufferString::operator== ( const BufferString s  )  const [inline]
template<class T >
bool BufferString::operator== ( t  )  const [inline]
bool BufferString::operator== ( const char *   )  const
bool BufferString::operator> ( const char *   )  const
template<class T >
bool BufferString::operator> ( t  )  const [inline]
char& BufferString::operator[] ( int  idx  )  [inline]
const char& BufferString::operator[] ( int  idx  )  const [inline]
void BufferString::replaceAt ( int  idx,
const char *  ,
bool  cutoff = true 
)
void BufferString::setBufSize ( unsigned  int  ) 
void BufferString::setEmpty (  ) 
void BufferString::setMinBufSize ( unsigned  int  ) 
unsigned int BufferString::size (  )  const
const char * BufferString::str (  )  const [inline]
Returns:
null pointer if empty

Member Data Documentation

char* BufferString::buf_ [protected]
unsigned int BufferString::len_ [protected]
const unsigned int BufferString::minlen_ [protected]