aboutsummaryrefslogtreecommitdiff
path: root/src/flexbuf.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
committerMike Buland <eichlan@xagasoft.com>2006-05-01 17:11:04 +0000
commitf7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54 (patch)
tree53cec4864776e07950e3c72f2a990a1017d08045 /src/flexbuf.h
downloadlibbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.gz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.bz2
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.xz
libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.zip
libbu++ is finally laid out the way it should be, trunk, branches, and tags.
Diffstat (limited to '')
-rw-r--r--src/flexbuf.h160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/flexbuf.h b/src/flexbuf.h
new file mode 100644
index 0000000..5ce4a89
--- /dev/null
+++ b/src/flexbuf.h
@@ -0,0 +1,160 @@
1/**\flexbuf.h
2 * Describes the FlexBuf class.
3 *@author Mike Buland
4 */
5
6#ifndef FLEXBUF_H
7#define FLEXBUF_H
8
9/** Stores any amount of data, but starts small, growing as necesarry.
10 * It is optimized to work with stream type situations, with data being
11 * added to the end while it is being taken from the begning.
12 *@todo Set this class up to auto-shrink back to a specified sized buffer each
13 * time it has shrunk below that for enough operations.
14 *@author Mike Buland
15 */
16class FlexBuf
17{
18public:
19 /**
20 * Construct a blank FlexBuf containing about 1k of buffer space.
21 */
22 FlexBuf();
23
24 /**
25 * Clean up the FlexBuf, delete all buffers.
26 */
27 ~FlexBuf();
28
29 /** Appends a whole string of data to the buffer. The string
30 * must be null terminated.
31 *@param lpData The data to append to the buffer.
32 *@param nDSize The size of the data described by lpData. If this
33 * value is -1 lpData is treated as a null-terminated string.
34 *@returns True if no problems occured, false otherwise.
35 */
36 bool appendData( const char *lpData, int nDSize=-1 );
37
38 /** Appends a single character to the end of the buffer.
39 *@param lData The character to append to the buffer.
40 *@returns True if no problems occured, false otherwise.
41 */
42 bool appendData( const char lData );
43
44 /**
45 * Append the short to the buffer.
46 *@param lData The short to add to the buffer queue.
47 *@returns True if everything is ok, false otherwise.
48 */
49 bool appendData( const short lData );
50
51 /**
52 * Append the int to the buffer.
53 *@param lData The int to add to the buffer queue.
54 *@returns True if everything is ok, false otherwise.
55 */
56 bool appendData( const int lData );
57
58 /**
59 * Append the long to the buffer.
60 *@param lData The long to add to the buffer queue.
61 *@returns True if everything is ok, false otherwise.
62 */
63 bool appendData( const long lData );
64
65 /**
66 * Append the float to the buffer.
67 *@param lData The float to add to the buffer queue.
68 *@returns True if everything is ok, false otherwise.
69 */
70 bool appendData( const float lData );
71
72 /**
73 * Append the double to the buffer.
74 *@param lData The double to add to the buffer queue.
75 *@returns True if everything is ok, false otherwise.
76 */
77 bool appendData( const double lData );
78
79 /**
80 * Append the unsigned char to the buffer.
81 *@param lData The unsigned char to add to the buffer queue.
82 *@returns True if everything is ok, false otherwise.
83 */
84 bool appendData( const unsigned char lData );
85
86 /**
87 * Append the unsigned short to the buffer.
88 *@param lData The unsigned short to add to the buffer queue.
89 *@returns True if everything is ok, false otherwise.
90 */
91 bool appendData( const unsigned short lData );
92
93 /**
94 * Append the unsigned int to the buffer.
95 *@param lData The unsigned int to add to the buffer queue.
96 *@returns True if everything is ok, false otherwise.
97 */
98 bool appendData( const unsigned int lData );
99
100 /**
101 * Append the unsigned long to the buffer.
102 *@param lData The unsigned long to add to the buffer queue.
103 *@returns True if everything is ok, false otherwise.
104 */
105 bool appendData( const unsigned long lData );
106
107 /** Removes all pending data from the buffer.
108 *@returns True if no problems occured, false otherwise.
109 */
110 bool clearData();
111
112 /** Gets a pointer to the internal buffer, at the begining of the current
113 * data stream.
114 *@returns A pointer to the internal data buffer.
115 */
116 const char *getData();
117
118 /** Gets the length of the current buffer (how much data is really in the
119 * buffer, not it's current capacity, for that check getCapacity)
120 *@returns The length of the current buffer.
121 */
122 int getLength();
123
124 /** Gets the current capacity of the FlexBuf. If the size nears this value
125 * then the entire buffer is resized to accomidate more data.
126 *@returns The current capacity of the FlexBuf.
127 */
128 int getCapacity();
129
130 /**
131 * Removes nAmount bytes from the begning of the buffer. Actually, if
132 * nAmount happens to be negative it will remove tha absolute value of
133 * nValue bytes from the end of the buffer, like the old delData command.
134 *@param nAmount The number of bytes used.
135 *@returns True if everything was successful, false if there was an error.
136 */
137 bool usedData( int nAmount );
138
139 /** Finds the first instance of the given character in the buffer and
140 * returns an index to it.
141 *@param cTarget The character you're looking for.
142 *@returns The index of the first instance of the given character, or
143 * -1 if it just wasn't found.
144 */
145 int findChar( char cTarget );
146
147private:
148 /** The raw storage location of the FlexBuf. */
149 char *lpBuf;
150 /** The real size of the FlexBuf. */
151 int nSize;
152 /** Where the last char is. */
153 int nLastChar;
154 /** Where the first char is. */
155 int nFirstChar;
156 /** The amount of real data in the FlexBuf. This is effectively nLastChar-nFirstChar. */
157 int nFill;
158};
159
160#endif