Public Member Functions | Private Attributes | List of all members
GrowBuf Class Reference

#include <growbuf.h>

Public Member Functions

 GrowBuf ()
 
 ~GrowBuf ()
 
void clear ()
 
void addChar (char c)
 
void addStr (const char *s)
 
void addStr (const char *s, int n)
 
const char * get ()
 
int getPos () const
 
char at (int i) const
 

Private Attributes

char * str
 
int pos
 
int len
 

Detailed Description

Class representing a string buffer optimised for growing.

Definition at line 10 of file growbuf.h.

Constructor & Destructor Documentation

GrowBuf::GrowBuf ( )
inline

Definition at line 13 of file growbuf.h.

13 : str(0), pos(0), len(0) {}
int pos
Definition: growbuf.h:43
int len
Definition: growbuf.h:44
char * str
Definition: growbuf.h:42
GrowBuf::~GrowBuf ( )
inline

Definition at line 14 of file growbuf.h.

14 { free(str); str=0; pos=0; len=0; }
int pos
Definition: growbuf.h:43
int len
Definition: growbuf.h:44
char * str
Definition: growbuf.h:42

Member Function Documentation

void GrowBuf::addChar ( char  c)
inline

Definition at line 16 of file growbuf.h.

16  { if (pos>=len) { len+=GROW_AMOUNT; str = (char*)realloc(str,len); }
17  str[pos++]=c;
18  }
int pos
Definition: growbuf.h:43
#define GROW_AMOUNT
Definition: growbuf.h:7
int len
Definition: growbuf.h:44
char * str
Definition: growbuf.h:42
void GrowBuf::addStr ( const char *  s)
inline

Definition at line 19 of file growbuf.h.

19  {
20  if (s)
21  {
22  int l=strlen(s);
23  if (pos+l>=len) { len+=l+GROW_AMOUNT; str = (char*)realloc(str,len); }
24  strcpy(&str[pos],s);
25  pos+=l;
26  }
27  }
int pos
Definition: growbuf.h:43
static QStrList * l
Definition: config.cpp:1044
#define GROW_AMOUNT
Definition: growbuf.h:7
int len
Definition: growbuf.h:44
char * str
Definition: growbuf.h:42
static QCString * s
Definition: config.cpp:1042
void GrowBuf::addStr ( const char *  s,
int  n 
)
inline

Definition at line 28 of file growbuf.h.

28  {
29  if (s)
30  {
31  int l=strlen(s);
32  if (n<l) l=n;
33  if (pos+l>=len) { len+=l+GROW_AMOUNT; str = (char*)realloc(str,len); }
34  strncpy(&str[pos],s,n);
35  pos+=l;
36  }
37  }
int pos
Definition: growbuf.h:43
static QStrList * l
Definition: config.cpp:1044
#define GROW_AMOUNT
Definition: growbuf.h:7
int len
Definition: growbuf.h:44
std::void_t< T > n
char * str
Definition: growbuf.h:42
static QCString * s
Definition: config.cpp:1042
char GrowBuf::at ( int  i) const
inline

Definition at line 40 of file growbuf.h.

40 { return str[i]; }
char * str
Definition: growbuf.h:42
void GrowBuf::clear ( )
inline

Definition at line 15 of file growbuf.h.

15 { pos=0; }
int pos
Definition: growbuf.h:43
const char* GrowBuf::get ( )
inline

Definition at line 38 of file growbuf.h.

38 { return str; }
char * str
Definition: growbuf.h:42
int GrowBuf::getPos ( ) const
inline

Definition at line 39 of file growbuf.h.

39 { return pos; }
int pos
Definition: growbuf.h:43

Member Data Documentation

int GrowBuf::len
private

Definition at line 44 of file growbuf.h.

int GrowBuf::pos
private

Definition at line 43 of file growbuf.h.

char* GrowBuf::str
private

Definition at line 42 of file growbuf.h.


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