Skip to main content

The GrowBuf Class Reference

Class representing a string buffer optimized for growing. More...

Declaration

class GrowBuf { ... }

Included Headers

#include <src/growbuf.h>

Public Constructors Index

GrowBuf ()
GrowBuf (size_t initialSize)
GrowBuf (const GrowBuf &other)
GrowBuf (GrowBuf &&other)

Public Destructor Index

~GrowBuf ()

Public Operators Index

GrowBuf &operator= (const GrowBuf &other)
GrowBuf &operator= (GrowBuf &&other)

Public Member Functions Index

voidreserve (size_t size)
voidclear ()
voidaddChar (char c)
voidaddStr (const QCString &s)
voidaddStr (const std::string &s)
voidaddStr (const char *s)
voidaddStr (const char *s, size_t n)
voidaddInt (const char *fmt, int value)
char *get ()
const char *get () const
size_tgetPos () const
voidsetPos (size_t newPos)
const char &at (size_t i) const
boolempty () const

Private Member Attributes Index

char *m_str
size_tm_pos
size_tm_len

Description

Class representing a string buffer optimized for growing.

Definition at line 27 of file growbuf.h.

Public Constructors

GrowBuf()

GrowBuf::GrowBuf ()
inline

Definition at line 30 of file growbuf.h.

30 GrowBuf() : m_str(nullptr), m_pos(0), m_len(0) {}

References m_len, m_pos and m_str.

Referenced by GrowBuf, GrowBuf, operator= and operator=.

GrowBuf()

GrowBuf::GrowBuf (size_t initialSize)
inline

Definition at line 31 of file growbuf.h.

31 GrowBuf(size_t initialSize) : m_pos(0), m_len(initialSize) { m_str=static_cast<char*>(malloc(m_len)); }

References m_len, m_pos and m_str.

GrowBuf()

GrowBuf::GrowBuf (const GrowBuf & other)
inline

Definition at line 33 of file growbuf.h.

33 GrowBuf(const GrowBuf &other)
34 {
35 m_len = other.m_len;
36 m_pos = other.m_pos;
37 m_str = static_cast<char*>(malloc(m_len));
38 memcpy(m_str,other.m_str,m_len);
39 }

References GrowBuf, m_len, m_pos and m_str.

GrowBuf()

GrowBuf::GrowBuf (GrowBuf && other)
inline

Definition at line 52 of file growbuf.h.

52 GrowBuf(GrowBuf &&other)
53 : m_str(std::exchange(other.m_str,static_cast<char*>(nullptr)))
54 , m_pos(std::exchange(other.m_pos,0))
55 , m_len(std::exchange(other.m_len,0))
56 {
57 }

References GrowBuf, m_len, m_pos and m_str.

Public Destructor

~GrowBuf()

GrowBuf::~GrowBuf ()
inline

Definition at line 32 of file growbuf.h.

32 ~GrowBuf() { free(m_str); }

Reference m_str.

Public Operators

operator=()

GrowBuf & GrowBuf::operator= (const GrowBuf & other)
inline

Definition at line 40 of file growbuf.h.

40 GrowBuf &operator=(const GrowBuf &other)
41 {
42 if (this!=&other)
43 {
44 free(m_str);
45 m_len = other.m_len;
46 m_pos = other.m_pos;
47 m_str = static_cast<char*>(malloc(m_len));
48 memcpy(m_str,other.m_str,m_len);
49 }
50 return *this;
51 }

References GrowBuf, m_len, m_pos and m_str.

operator=()

GrowBuf & GrowBuf::operator= (GrowBuf && other)
inline

Definition at line 58 of file growbuf.h.

59 {
60 if (this==&other)
61 return *this;
62 m_len = std::exchange(other.m_len,0);
63 m_pos = std::exchange(other.m_pos,0);
64 m_str = std::exchange(other.m_str,static_cast<char*>(nullptr));
65 return *this;
66 }

References GrowBuf, m_len, m_pos and m_str.

Public Member Functions

addChar()

addInt()

void GrowBuf::addInt (const char * fmt, int value)
inline

Definition at line 109 of file growbuf.h.

109 void addInt(const char *fmt,int value) {
110 char tmp[50];
111 snprintf(tmp,50,fmt,value);
112 addStr(tmp);
113 }

Reference addStr.

Referenced by formatDateTime.

addStr()

addStr()

void GrowBuf::addStr (const std::string & s)
inline

Definition at line 81 of file growbuf.h.

81 void addStr(const std::string &s) {
82 if (!s.empty())
83 {
84 size_t l=s.length();
85 if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = static_cast<char*>(realloc(m_str,m_len)); }
86 strcpy(&m_str[m_pos],s.c_str());
87 m_pos+=l;
88 }
89 }

References GROW_AMOUNT, m_len, m_pos and m_str.

addStr()

void GrowBuf::addStr (const char * s)
inline

Definition at line 90 of file growbuf.h.

90 void addStr(const char *s) {
91 if (s)
92 {
93 size_t l=strlen(s);
94 if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = static_cast<char*>(realloc(m_str,m_len)); }
95 strcpy(&m_str[m_pos],s);
96 m_pos+=l;
97 }
98 }

References GROW_AMOUNT, m_len, m_pos and m_str.

addStr()

void GrowBuf::addStr (const char * s, size_t n)
inline

Definition at line 99 of file growbuf.h.

99 void addStr(const char *s,size_t n) {
100 if (s)
101 {
102 size_t l=strlen(s);
103 if (n<l) l=n;
104 if (m_pos+l>=m_len) { m_len+=l+GROW_AMOUNT; m_str = static_cast<char*>(realloc(m_str,m_len)); }
105 strncpy(&m_str[m_pos],s,n);
106 m_pos+=l;
107 }
108 }

References GROW_AMOUNT, m_len, m_pos and m_str.

at()

const char & GrowBuf::at (size_t i)
inline

Definition at line 118 of file growbuf.h.

118 const char &at(size_t i) const { return m_str[i]; }

Reference m_str.

Referenced by filter2008VhdlComment.

clear()

void GrowBuf::clear ()
inline

Definition at line 68 of file growbuf.h.

68 void clear() { m_pos=0; }

Reference m_pos.

Referenced by filterId and CitationManager::getFormulas.

empty()

bool GrowBuf::empty ()
inline

Definition at line 119 of file growbuf.h.

119 bool empty() const { return m_pos==0; }

Reference m_pos.

get()

get()

const char * GrowBuf::get ()
inline

Definition at line 115 of file growbuf.h.

115 const char *get() const { return m_str; }

Reference m_str.

getPos()

size_t GrowBuf::getPos ()
inline

Definition at line 116 of file growbuf.h.

116 size_t getPos() const { return m_pos; }

Reference m_pos.

Referenced by SearchIndexExternal::addWord, filter2008VhdlComment and DocParser::processCopyDoc.

reserve()

void GrowBuf::reserve (size_t size)
inline

Definition at line 67 of file growbuf.h.

67 void reserve(size_t size) { if (m_len<size) { m_len = size; m_str = static_cast<char*>(realloc(m_str,m_len)); } }

References m_len and m_str.

setPos()

void GrowBuf::setPos (size_t newPos)
inline

Definition at line 117 of file growbuf.h.

117 void setPos(size_t newPos) { m_pos = newPos; }

Reference m_pos.

Referenced by filter2008VhdlComment.

Private Member Attributes

m_len

size_t GrowBuf::m_len

Definition at line 123 of file growbuf.h.

123 size_t m_len;

Referenced by addChar, addStr, addStr, addStr, addStr, GrowBuf, GrowBuf, GrowBuf, GrowBuf, operator=, operator= and reserve.

m_pos

size_t GrowBuf::m_pos

Definition at line 122 of file growbuf.h.

122 size_t m_pos;

Referenced by addChar, addStr, addStr, addStr, addStr, clear, empty, getPos, GrowBuf, GrowBuf, GrowBuf, GrowBuf, operator=, operator= and setPos.

m_str

char* GrowBuf::m_str

Definition at line 121 of file growbuf.h.

121 char *m_str;

Referenced by addChar, addStr, addStr, addStr, addStr, at, get, get, GrowBuf, GrowBuf, GrowBuf, GrowBuf, operator=, operator=, reserve and ~GrowBuf.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.