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.

34  : m_size(size), m_writeOffset(0), m_spareRoom(10240), m_buf(0)
35  {
36  m_buf = (char *)calloc(size,1);
37  }
uint m_writeOffset
Definition: bufstr.h:117
int size() const
Definition: bufstr.h:77
uint m_size
Definition: bufstr.h:116
const int m_spareRoom
Definition: bufstr.h:118
char * m_buf
Definition: bufstr.h:119
BufStr::~BufStr ( )
inline

Definition at line 38 of file bufstr.h.

39  {
40  free(m_buf);
41  }
char * m_buf
Definition: bufstr.h:119

Member Function Documentation

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

Definition at line 47 of file bufstr.h.

48  {
49  makeRoomFor(len);
50  memcpy(m_buf+m_writeOffset,a,len);
51  m_writeOffset+=len;
52  }
uint m_writeOffset
Definition: bufstr.h:117
void makeRoomFor(uint size)
Definition: bufstr.h:109
const double a
char * m_buf
Definition: bufstr.h:119
void BufStr::addChar ( char  c)
inline

Definition at line 42 of file bufstr.h.

43  {
44  makeRoomFor(1);
46  }
uint m_writeOffset
Definition: bufstr.h:117
void makeRoomFor(uint size)
Definition: bufstr.h:109
char * m_buf
Definition: bufstr.h:119
char& BufStr::at ( uint  i) const
inline

Definition at line 85 of file bufstr.h.

86  {
87  return m_buf[i];
88  }
char * m_buf
Definition: bufstr.h:119
uint BufStr::curPos ( ) const
inline

Definition at line 97 of file bufstr.h.

98  {
99  return m_writeOffset;
100  }
uint m_writeOffset
Definition: bufstr.h:117
char* BufStr::data ( ) const
inline

Definition at line 81 of file bufstr.h.

82  {
83  return m_buf;
84  }
char * m_buf
Definition: bufstr.h:119
void BufStr::dropFromStart ( uint  bytes)
inline

Definition at line 101 of file bufstr.h.

102  {
103  if (bytes>m_size) bytes=m_size;
105  m_size-=bytes;
107  }
uint m_writeOffset
Definition: bufstr.h:117
uint m_size
Definition: bufstr.h:116
void * qmemmove(void *dst, const void *src, uint len)
Definition: qcstring.cpp:530
char * m_buf
Definition: bufstr.h:119
byte bytes
Alias for common language habits.
Definition: datasize.h:101
bool BufStr::isEmpty ( ) const
inline

Definition at line 89 of file bufstr.h.

90  {
91  return m_writeOffset==0;
92  }
uint m_writeOffset
Definition: bufstr.h:117
void BufStr::makeRoomFor ( uint  size)
inlineprivate

Definition at line 109 of file bufstr.h.

110  {
111  if (m_writeOffset+size>=m_size)
112  {
114  }
115  }
void resize(uint newlen)
Definition: bufstr.h:63
uint m_writeOffset
Definition: bufstr.h:117
int size() const
Definition: bufstr.h:77
uint m_size
Definition: bufstr.h:116
const int m_spareRoom
Definition: bufstr.h:118
BufStr::operator const char * ( ) const
inline

Definition at line 93 of file bufstr.h.

94  {
95  return m_buf;
96  }
char * m_buf
Definition: bufstr.h:119
void BufStr::resize ( uint  newlen)
inline

Definition at line 63 of file bufstr.h.

64  {
65  uint oldsize = m_size;
66  m_size=newlen;
67  if (m_writeOffset>=m_size) // offset out of range -> enlarge
68  {
70  }
71  m_buf = (char *)realloc(m_buf,m_size);
72  if (m_size>oldsize)
73  {
74  memset(m_buf+oldsize,0,m_size-oldsize);
75  }
76  }
uint m_writeOffset
Definition: bufstr.h:117
uint m_size
Definition: bufstr.h:116
const int m_spareRoom
Definition: bufstr.h:118
char * m_buf
Definition: bufstr.h:119
unsigned uint
Definition: qglobal.h:351
void BufStr::shrink ( uint  newlen)
inline

Definition at line 58 of file bufstr.h.

59  {
60  m_writeOffset=newlen;
61  resize(newlen);
62  }
void resize(uint newlen)
Definition: bufstr.h:63
uint m_writeOffset
Definition: bufstr.h:117
int BufStr::size ( ) const
inline

Definition at line 77 of file bufstr.h.

78  {
79  return m_size;
80  }
uint m_size
Definition: bufstr.h:116
void BufStr::skip ( uint  s)
inline

Definition at line 53 of file bufstr.h.

54  {
55  makeRoomFor(s);
57  }
uint m_writeOffset
Definition: bufstr.h:117
void makeRoomFor(uint size)
Definition: bufstr.h:109
static QCString * s
Definition: config.cpp:1042

Member Data Documentation

char* BufStr::m_buf
private

Definition at line 119 of file bufstr.h.

uint BufStr::m_size
private

Definition at line 116 of file bufstr.h.

const int BufStr::m_spareRoom
private

Definition at line 118 of file bufstr.h.

uint BufStr::m_writeOffset
private

Definition at line 117 of file bufstr.h.


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