summaryrefslogtreecommitdiffstats
path: root/src/bufstr.h
diff options
context:
space:
mode:
authordimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7>2004-12-06 18:20:45 (GMT)
committerdimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7>2004-12-06 18:20:45 (GMT)
commit6813ee0d373629968dc3ff9235285819e45f5707 (patch)
treedb6a4cf330b3c7b7dc387321cabe709ba675e957 /src/bufstr.h
parent4a50fc78170244f82c376bbecd28be43cc849da3 (diff)
downloadDoxygen-6813ee0d373629968dc3ff9235285819e45f5707.zip
Doxygen-6813ee0d373629968dc3ff9235285819e45f5707.tar.gz
Doxygen-6813ee0d373629968dc3ff9235285819e45f5707.tar.bz2
Doxygen-1.3.9.1-20041206
Diffstat (limited to 'src/bufstr.h')
-rw-r--r--src/bufstr.h90
1 files changed, 59 insertions, 31 deletions
diff --git a/src/bufstr.h b/src/bufstr.h
index 2426fac..ec372b9 100644
--- a/src/bufstr.h
+++ b/src/bufstr.h
@@ -19,56 +19,84 @@
#define _BUFSTR_H
#include "qtbc.h"
+#include <stdio.h>
+#include <stdlib.h>
-/*! String that can deal more efficiently with large large numbers
- * of resizing.
+/*! @brief 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.
*/
-class BufStr : public QCString
+class BufStr
{
public:
- BufStr(int size) : QCString(size), offset(0), spareRoom(10240) {}
+ BufStr(int size)
+ : m_size(size), m_writeOffset(0), m_spareRoom(10240), m_buf(0)
+ {
+ m_buf = (char *)malloc(size);
+ }
+ ~BufStr()
+ {
+ free(m_buf);
+ }
void addChar(char c)
{
- if (offset>=size())
- {
- QCString::resize(size()+spareRoom);
- }
- QCString::data()[offset++]=c;
+ makeRoomFor(1);
+ m_buf[m_writeOffset++]=c;
}
void addArray(const char *a,int len)
{
- if (offset+len>=size())
- {
- QCString::resize(size()+len+spareRoom);
- }
- memcpy(QCString::data()+offset,a,len);
- offset+=len;
+ makeRoomFor(len);
+ memcpy(m_buf+m_writeOffset,a,len);
+ m_writeOffset+=len;
}
- uint curPos() { return offset; }
void skip(uint s)
{
- if (offset+s>=size())
- {
- QCString::resize(size()+s+spareRoom);
- }
- offset+=s;
+ makeRoomFor(s);
+ m_writeOffset+=s;
}
void resize( uint newlen )
{
- //QCString::resize(newlen);
- //if (offset>newlen)
- //{
- // offset=newlen;
- //}
- offset=newlen;
- if (offset>=size())
+ m_size=newlen;
+ if (m_writeOffset>=m_size) // offset out of range -> enlarge
{
- QCString::resize(size()+spareRoom);
+ m_size=m_writeOffset+m_spareRoom;
}
+ m_buf = (char *)realloc(m_buf,m_size);
+ }
+ char *data() const
+ {
+ return m_buf;
+ }
+ char &at(uint i) const
+ {
+ return m_buf[i];
+ }
+ bool isEmpty() const
+ {
+ return m_writeOffset==0;
+ }
+ operator const char *() const
+ {
+ return m_buf;
+ }
+ uint curPos() const
+ {
+ return m_writeOffset;
}
private:
- uint offset;
- const int spareRoom; // 10Kb extra room to avoid frequent resizing
+ void makeRoomFor(uint size)
+ {
+ if (m_writeOffset+size>=m_size)
+ {
+ resize(m_size+size+m_spareRoom);
+ }
+ }
+ uint m_size;
+ uint m_writeOffset;
+ const int m_spareRoom; // 10Kb extra room to avoid frequent resizing
+ char *m_buf;
};
+
#endif