/[winpt]/trunk/Generic/StringBuffer.h
ViewVC logotype

Contents of /trunk/Generic/StringBuffer.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 316 - (show annotations)
Fri May 25 14:50:43 2007 UTC (17 years, 9 months ago) by twoaday
File MIME type: text/plain
File size: 2361 byte(s)


1 #ifndef __STRING_BUFFER_H
2 #define __STRING_BUFFER_H
3
4 /* Copyright (C) 2006, 2007 Timo Schulz
5 Released under the GNU General Public License, Version 2. */
6
7 #define DEFSIZE 128
8
9 /* A simple string buffer implementation which allows to manipulate
10 the underlying buffer in a unified and easy way. The code is written
11 for clarity and simplicty, _not_ speed. */
12 class StringBuffer
13 {
14 private:
15 char *private_contents;
16 int alloced_size;
17 int size;
18
19 private:
20 /* Add the converted data at the end of the internal buffer.
21 Allocate more memory if needed, plus some extra bytes. */
22 void addCharacters (const char *buffer, int bufsize);
23
24 public:
25 StringBuffer ();
26
27 /* Create an empty buffer object with an inital size. */
28 StringBuffer (int bufsize);
29
30
31 /* Create a buffer object with the given contents. */
32 StringBuffer (const char *contents);
33
34 /* Destructor which fres the used memory. */
35 ~StringBuffer ();
36
37 /* Overwrite buffer contents in a safe manner. */
38 void wipeContents (void);
39
40 /* Return a constant pointer to the 'char*' data of the buffer. */
41 const char *getBuffer (void);
42
43 /* Return a copy of the buffer which must be freed after use. */
44 char* getBufferCopy (void);
45
46 /* Return the size of the underlying string. */
47 int getSize (void);
48
49 /* Reset the buffer contents. */
50 void reset (void);
51
52 /* Add an integer to the buffer. */
53 void add (int val);
54
55 /* Add a single character to the buffer. */
56 void add (char val);
57
58 /* Add a long-integer to the buffer. */
59 void add (long val);
60
61 /* Add a string to the buffer. */
62 void add (const char *val);
63
64 /* Add an unsigned integer to the buffer. */
65 void add (unsigned long val);
66
67 /* Add an unsigned integer in hex format to the buffer. */
68 void addHex (unsigned long val);
69
70 /* Overloaded operators to provide an easier interface
71 for manipulating the underlying buffer. */
72 StringBuffer& operator +(int val);
73
74 StringBuffer& operator +(unsigned long val);
75
76 StringBuffer& operator +(const char *val);
77
78 StringBuffer& operator +=(int val);
79
80 StringBuffer& operator +=(unsigned long val);
81
82 StringBuffer& operator +=(const char *val);
83
84 StringBuffer& operator +=(char val);
85
86 StringBuffer& operator=(const char *val);
87 };
88
89
90 #endif /*__STRING_BUFFER_H*/

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26