diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-03-27 21:05:10 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-03-27 21:05:10 +0000 |
commit | bebc878b054a06ff8e541db695b1e586fff2b022 (patch) | |
tree | 031e2e141fc18450954e0323ea6de60328822575 /src/flexbuf.cpp | |
parent | 57191021fe365eb8d448a9f2a66002a59e2ab065 (diff) | |
download | libbu++-bebc878b054a06ff8e541db695b1e586fff2b022.tar.gz libbu++-bebc878b054a06ff8e541db695b1e586fff2b022.tar.bz2 libbu++-bebc878b054a06ff8e541db695b1e586fff2b022.tar.xz libbu++-bebc878b054a06ff8e541db695b1e586fff2b022.zip |
Added a new helper to the flexbuf, and likewise to the connection class, since
it uses it heavily.
Diffstat (limited to 'src/flexbuf.cpp')
-rw-r--r-- | src/flexbuf.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/flexbuf.cpp b/src/flexbuf.cpp index acd55a7..6d55294 100644 --- a/src/flexbuf.cpp +++ b/src/flexbuf.cpp | |||
@@ -204,3 +204,26 @@ int FlexBuf::findChar( char cTarget ) | |||
204 | return -1; | 204 | return -1; |
205 | } | 205 | } |
206 | 206 | ||
207 | void FlexBuf::ensureCapacity( int nAmount ) | ||
208 | { | ||
209 | if( nLastChar + nAmount + 1 > nSize ) | ||
210 | { | ||
211 | if( nFill + nAmount + 1 < nSize ) | ||
212 | { | ||
213 | memcpy( lpBuf, lpBuf+nFirstChar, nFill ); | ||
214 | nLastChar -= nFirstChar; | ||
215 | nFirstChar = 0; | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | nSize += nAmount+1; | ||
220 | char *lpNewBuf = new char[nSize]; | ||
221 | memcpy( lpNewBuf, lpBuf+nFirstChar, nFill ); | ||
222 | delete[] lpBuf; | ||
223 | lpBuf = lpNewBuf; | ||
224 | nLastChar -= nFirstChar; | ||
225 | nFirstChar = 0; | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | |||