diff options
author | David <david@xagasoft.com> | 2007-06-18 19:41:34 +0000 |
---|---|---|
committer | David <david@xagasoft.com> | 2007-06-18 19:41:34 +0000 |
commit | 5292e5831934dc719d1ac06332bd252abe4ac3bc (patch) | |
tree | 1acbd783f6c155bcd376bcb4460ae47868e8285a /src/fstring.h | |
parent | 2b90449c30e4a420af4fff7e58588611d71f61fc (diff) | |
download | libbu++-5292e5831934dc719d1ac06332bd252abe4ac3bc.tar.gz libbu++-5292e5831934dc719d1ac06332bd252abe4ac3bc.tar.bz2 libbu++-5292e5831934dc719d1ac06332bd252abe4ac3bc.tar.xz libbu++-5292e5831934dc719d1ac06332bd252abe4ac3bc.zip |
david - writing code documentation...
Diffstat (limited to '')
-rw-r--r-- | src/fstring.h | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/src/fstring.h b/src/fstring.h index 93a0042..9d88bd4 100644 --- a/src/fstring.h +++ b/src/fstring.h | |||
@@ -29,6 +29,11 @@ namespace Bu | |||
29 | * almost no overhead in time or memory since a reference is created and no | 29 | * almost no overhead in time or memory since a reference is created and no |
30 | * data is actually copied. This also means that you never need to put any | 30 | * data is actually copied. This also means that you never need to put any |
31 | * FBasicString into a ref-counting container class. | 31 | * FBasicString into a ref-counting container class. |
32 | * | ||
33 | *@param chr (typename) Type of character (i.e. char) | ||
34 | *@param nMinSize (int) Chunk size (default: 256) | ||
35 | *@param chralloc (typename) Memory Allocator for chr | ||
36 | *@param chunkalloc (typename) Memory Allocator for chr chunks | ||
32 | */ | 37 | */ |
33 | template< typename chr, int nMinSize=256, typename chralloc=std::allocator<chr>, typename chunkalloc=std::allocator<struct FStringChunk<chr> > > | 38 | template< typename chr, int nMinSize=256, typename chralloc=std::allocator<chr>, typename chunkalloc=std::allocator<struct FStringChunk<chr> > > |
34 | class FBasicString : public Archival | 39 | class FBasicString : public Archival |
@@ -113,6 +118,14 @@ namespace Bu | |||
113 | clear(); | 118 | clear(); |
114 | } | 119 | } |
115 | 120 | ||
121 | /** | ||
122 | *@todo void append( const MyType & sData ) | ||
123 | */ | ||
124 | |||
125 | /** | ||
126 | * Append data to your string. | ||
127 | *@param pData (const chr *) The data to append. | ||
128 | */ | ||
116 | void append( const chr *pData ) | 129 | void append( const chr *pData ) |
117 | { | 130 | { |
118 | long nLen; | 131 | long nLen; |
@@ -126,6 +139,11 @@ namespace Bu | |||
126 | appendChunk( pNew ); | 139 | appendChunk( pNew ); |
127 | } | 140 | } |
128 | 141 | ||
142 | /** | ||
143 | * Append data to your string. | ||
144 | *@param pData (const chr *) The data to append. | ||
145 | *@param nLen (long) The length of the data to append. | ||
146 | */ | ||
129 | void append( const chr *pData, long nLen ) | 147 | void append( const chr *pData, long nLen ) |
130 | { | 148 | { |
131 | if( nLen == 0 ) | 149 | if( nLen == 0 ) |
@@ -138,16 +156,28 @@ namespace Bu | |||
138 | appendChunk( pNew ); | 156 | appendChunk( pNew ); |
139 | } | 157 | } |
140 | 158 | ||
159 | /** | ||
160 | * Append a single chr to your string. | ||
161 | *@param cData (const chr &) The character to append. | ||
162 | */ | ||
141 | void append( const chr &cData ) | 163 | void append( const chr &cData ) |
142 | { | 164 | { |
143 | append( &cData, 1 ); | 165 | append( &cData, 1 ); |
144 | } | 166 | } |
145 | 167 | ||
168 | /** | ||
169 | * Prepend another FString to this one. | ||
170 | *@param sData (MyType &) The FString to prepend. | ||
171 | */ | ||
146 | void prepend( const MyType & sData ) | 172 | void prepend( const MyType & sData ) |
147 | { | 173 | { |
148 | prepend( sData.getStr(), sData.getSize() ); | 174 | prepend( sData.getStr(), sData.getSize() ); |
149 | } | 175 | } |
150 | 176 | ||
177 | /** | ||
178 | * Prepend data to your string. | ||
179 | *@param pData (const chr *) The data to prepend. | ||
180 | */ | ||
151 | void prepend( const chr *pData ) | 181 | void prepend( const chr *pData ) |
152 | { | 182 | { |
153 | long nLen; | 183 | long nLen; |
@@ -159,6 +189,11 @@ namespace Bu | |||
159 | prependChunk( pNew ); | 189 | prependChunk( pNew ); |
160 | } | 190 | } |
161 | 191 | ||
192 | /** | ||
193 | * Prepend data to your string. | ||
194 | *@param pData (const chr *) The data to prepend. | ||
195 | *@param nLen (long) The length of the data to prepend. | ||
196 | */ | ||
162 | void prepend( const chr *pData, long nLen ) | 197 | void prepend( const chr *pData, long nLen ) |
163 | { | 198 | { |
164 | Chunk *pNew = newChunk( nLen ); | 199 | Chunk *pNew = newChunk( nLen ); |
@@ -168,11 +203,22 @@ namespace Bu | |||
168 | prependChunk( pNew ); | 203 | prependChunk( pNew ); |
169 | } | 204 | } |
170 | 205 | ||
206 | /** | ||
207 | *@todo void prepend( const chr &cData ) | ||
208 | */ | ||
209 | |||
210 | /** | ||
211 | * Clear all data from the string. | ||
212 | */ | ||
171 | void clear() | 213 | void clear() |
172 | { | 214 | { |
173 | realClear(); | 215 | realClear(); |
174 | } | 216 | } |
175 | 217 | ||
218 | /** | ||
219 | * Force the string to resize | ||
220 | *@param nNewSize (long) The new size of the string. | ||
221 | */ | ||
176 | void resize( long nNewSize ) | 222 | void resize( long nNewSize ) |
177 | { | 223 | { |
178 | if( nLength == nNewSize ) | 224 | if( nLength == nNewSize ) |
@@ -190,11 +236,19 @@ namespace Bu | |||
190 | nLength = nNewSize; | 236 | nLength = nNewSize; |
191 | } | 237 | } |
192 | 238 | ||
239 | /** | ||
240 | * Get the current size of the string. | ||
241 | *@returns (long) The current size of the string. | ||
242 | */ | ||
193 | long getSize() const | 243 | long getSize() const |
194 | { | 244 | { |
195 | return nLength; | 245 | return nLength; |
196 | } | 246 | } |
197 | 247 | ||
248 | /** | ||
249 | * Get a pointer to the string array. | ||
250 | *@returns (chr *) The string data. | ||
251 | */ | ||
198 | chr *getStr() | 252 | chr *getStr() |
199 | { | 253 | { |
200 | if( pFirst == NULL ) | 254 | if( pFirst == NULL ) |
@@ -204,6 +258,10 @@ namespace Bu | |||
204 | return pFirst->pData; | 258 | return pFirst->pData; |
205 | } | 259 | } |
206 | 260 | ||
261 | /** | ||
262 | * Get a const pointer to the string array. | ||
263 | *@returns (const chr *) The string data. | ||
264 | */ | ||
207 | const chr *getStr() const | 265 | const chr *getStr() const |
208 | { | 266 | { |
209 | if( pFirst == NULL ) | 267 | if( pFirst == NULL ) |
@@ -213,6 +271,10 @@ namespace Bu | |||
213 | return pFirst->pData; | 271 | return pFirst->pData; |
214 | } | 272 | } |
215 | 273 | ||
274 | /** | ||
275 | * (std::string compatability) Get a pointer to the string array. | ||
276 | *@returns (chr *) The string data. | ||
277 | */ | ||
216 | chr *c_str() | 278 | chr *c_str() |
217 | { | 279 | { |
218 | if( pFirst == NULL ) | 280 | if( pFirst == NULL ) |
@@ -222,6 +284,10 @@ namespace Bu | |||
222 | return pFirst->pData; | 284 | return pFirst->pData; |
223 | } | 285 | } |
224 | 286 | ||
287 | /** | ||
288 | * (std::string compatability) Get a const pointer to the string array. | ||
289 | *@returns (const chr *) The string data. | ||
290 | */ | ||
225 | const chr *c_str() const | 291 | const chr *c_str() const |
226 | { | 292 | { |
227 | if( pFirst == NULL ) | 293 | if( pFirst == NULL ) |
@@ -231,6 +297,10 @@ namespace Bu | |||
231 | return pFirst->pData; | 297 | return pFirst->pData; |
232 | } | 298 | } |
233 | 299 | ||
300 | /** | ||
301 | * Plus equals operator for FString. | ||
302 | *@param pData (const chr *) The data to append to your FString. | ||
303 | */ | ||
234 | MyType &operator +=( const chr *pData ) | 304 | MyType &operator +=( const chr *pData ) |
235 | { | 305 | { |
236 | append( pData ); | 306 | append( pData ); |
@@ -238,6 +308,10 @@ namespace Bu | |||
238 | return (*this); | 308 | return (*this); |
239 | } | 309 | } |
240 | 310 | ||
311 | /** | ||
312 | * Plus equals operator for FString. | ||
313 | *@param pData (const MyType &) The FString to append to your FString. | ||
314 | */ | ||
241 | MyType &operator +=( const MyType &rSrc ) | 315 | MyType &operator +=( const MyType &rSrc ) |
242 | { | 316 | { |
243 | if( rSrc.nLength == 0 ) | 317 | if( rSrc.nLength == 0 ) |
@@ -248,6 +322,10 @@ namespace Bu | |||
248 | return (*this); | 322 | return (*this); |
249 | } | 323 | } |
250 | 324 | ||
325 | /** | ||
326 | * Plus equals operator for FString. | ||
327 | *@param pData (const chr) The character to append to your FString. | ||
328 | */ | ||
251 | MyType &operator +=( const chr pData ) | 329 | MyType &operator +=( const chr pData ) |
252 | { | 330 | { |
253 | append( &pData, 1 ); | 331 | append( &pData, 1 ); |
@@ -255,6 +333,11 @@ namespace Bu | |||
255 | return (*this); | 333 | return (*this); |
256 | } | 334 | } |
257 | 335 | ||
336 | /** | ||
337 | * Assignment operator. | ||
338 | *@param pData (const chr *) The character array to append to your | ||
339 | * FString. | ||
340 | */ | ||
258 | MyType &operator =( const chr *pData ) | 341 | MyType &operator =( const chr *pData ) |
259 | { | 342 | { |
260 | clear(); | 343 | clear(); |
@@ -263,18 +346,31 @@ namespace Bu | |||
263 | return (*this); | 346 | return (*this); |
264 | } | 347 | } |
265 | 348 | ||
349 | /** | ||
350 | * Reset your FString to this character array. | ||
351 | *@param pData (const chr *) The character array to set your FString to. | ||
352 | */ | ||
266 | void set( const chr *pData ) | 353 | void set( const chr *pData ) |
267 | { | 354 | { |
268 | clear(); | 355 | clear(); |
269 | append( pData ); | 356 | append( pData ); |
270 | } | 357 | } |
271 | 358 | ||
359 | /** | ||
360 | * Reset your FString to this character array. | ||
361 | *@param pData (const chr *) The character array to set your FString to. | ||
362 | *@param nSize (long) The length of the inputted character array. | ||
363 | */ | ||
272 | void set( const chr *pData, long nSize ) | 364 | void set( const chr *pData, long nSize ) |
273 | { | 365 | { |
274 | clear(); | 366 | clear(); |
275 | append( pData, nSize ); | 367 | append( pData, nSize ); |
276 | } | 368 | } |
277 | 369 | ||
370 | /** | ||
371 | * Assignment operator. | ||
372 | *@param rSrc (const MyType &) The FString to set your FString to. | ||
373 | */ | ||
278 | MyType &operator =( const MyType &rSrc ) | 374 | MyType &operator =( const MyType &rSrc ) |
279 | { | 375 | { |
280 | //if( rSrc.isFlat() ) | 376 | //if( rSrc.isFlat() ) |
@@ -290,6 +386,11 @@ namespace Bu | |||
290 | return (*this); | 386 | return (*this); |
291 | } | 387 | } |
292 | 388 | ||
389 | /** | ||
390 | * Equals comparison operator. | ||
391 | *@param pData (const chr *) The character array to compare your FString | ||
392 | * to. | ||
393 | */ | ||
293 | bool operator ==( const chr *pData ) const | 394 | bool operator ==( const chr *pData ) const |
294 | { | 395 | { |
295 | if( pFirst == NULL ) { | 396 | if( pFirst == NULL ) { |
@@ -310,6 +411,10 @@ namespace Bu | |||
310 | return true; | 411 | return true; |
311 | } | 412 | } |
312 | 413 | ||
414 | /** | ||
415 | * Equals comparison operator. | ||
416 | *@param pData (const MyType &) The FString to compare your FString to. | ||
417 | */ | ||
313 | bool operator ==( const MyType &pData ) const | 418 | bool operator ==( const MyType &pData ) const |
314 | { | 419 | { |
315 | if( pFirst == pData.pFirst ) | 420 | if( pFirst == pData.pFirst ) |
@@ -330,16 +435,30 @@ namespace Bu | |||
330 | return true; | 435 | return true; |
331 | } | 436 | } |
332 | 437 | ||
438 | /** | ||
439 | * Not equals comparison operator. | ||
440 | *@param pData (const chr *) The character array to compare your FString | ||
441 | * to. | ||
442 | */ | ||
333 | bool operator !=(const chr *pData ) const | 443 | bool operator !=(const chr *pData ) const |
334 | { | 444 | { |
335 | return !(*this == pData); | 445 | return !(*this == pData); |
336 | } | 446 | } |
337 | 447 | ||
448 | /** | ||
449 | * Not equals comparison operator. | ||
450 | *@param pData (const MyType &) The FString to compare your FString to. | ||
451 | */ | ||
338 | bool operator !=(const MyType &pData ) const | 452 | bool operator !=(const MyType &pData ) const |
339 | { | 453 | { |
340 | return !(*this == pData); | 454 | return !(*this == pData); |
341 | } | 455 | } |
342 | 456 | ||
457 | /** | ||
458 | * Indexing operator | ||
459 | *@param nIndex (long) The index of the character you want. | ||
460 | *@returns (chr &) The character at position (nIndex). | ||
461 | */ | ||
343 | chr &operator[]( long nIndex ) | 462 | chr &operator[]( long nIndex ) |
344 | { | 463 | { |
345 | flatten(); | 464 | flatten(); |
@@ -347,6 +466,11 @@ namespace Bu | |||
347 | return pFirst->pData[nIndex]; | 466 | return pFirst->pData[nIndex]; |
348 | } | 467 | } |
349 | 468 | ||
469 | /** | ||
470 | * Const indexing operator | ||
471 | *@param nIndex (long) The index of the character you want. | ||
472 | *@returns (const chr &) The character at position (nIndex). | ||
473 | */ | ||
350 | const chr &operator[]( long nIndex ) const | 474 | const chr &operator[]( long nIndex ) const |
351 | { | 475 | { |
352 | flatten(); | 476 | flatten(); |
@@ -354,6 +478,11 @@ namespace Bu | |||
354 | return pFirst->pData[nIndex]; | 478 | return pFirst->pData[nIndex]; |
355 | } | 479 | } |
356 | 480 | ||
481 | /** | ||
482 | * Is the character at index (nIndex) white space? | ||
483 | *@param nIndex (long) The index of the character you want to check. | ||
484 | *@returns (bool) Is it white space? | ||
485 | */ | ||
357 | bool isWS( long nIndex ) const | 486 | bool isWS( long nIndex ) const |
358 | { | 487 | { |
359 | flatten(); | 488 | flatten(); |
@@ -362,6 +491,11 @@ namespace Bu | |||
362 | || pFirst->pData[nIndex]=='\r' || pFirst->pData[nIndex]=='\n'; | 491 | || pFirst->pData[nIndex]=='\r' || pFirst->pData[nIndex]=='\n'; |
363 | } | 492 | } |
364 | 493 | ||
494 | /** | ||
495 | * Is the character at index (nIndex) a letter? | ||
496 | *@param nIndex (long) The index of the character you want to check. | ||
497 | *@returns (bool) Is it a letter? | ||
498 | */ | ||
365 | bool isAlpha( long nIndex ) const | 499 | bool isAlpha( long nIndex ) const |
366 | { | 500 | { |
367 | flatten(); | 501 | flatten(); |
@@ -370,6 +504,9 @@ namespace Bu | |||
370 | || (pFirst->pData[nIndex] >= 'A' && pFirst->pData[nIndex] <= 'Z'); | 504 | || (pFirst->pData[nIndex] >= 'A' && pFirst->pData[nIndex] <= 'Z'); |
371 | } | 505 | } |
372 | 506 | ||
507 | /** | ||
508 | * Convert your alpha characters to lower case. | ||
509 | */ | ||
373 | void toLower() | 510 | void toLower() |
374 | { | 511 | { |
375 | flatten(); | 512 | flatten(); |
@@ -382,6 +519,9 @@ namespace Bu | |||
382 | } | 519 | } |
383 | } | 520 | } |
384 | 521 | ||
522 | /** | ||
523 | * Convert your alpha characters to upper case. | ||
524 | */ | ||
385 | void toUpper() | 525 | void toUpper() |
386 | { | 526 | { |
387 | flatten(); | 527 | flatten(); |
@@ -394,6 +534,11 @@ namespace Bu | |||
394 | } | 534 | } |
395 | } | 535 | } |
396 | 536 | ||
537 | /** | ||
538 | * Find the index of the first occurrance of (sText) | ||
539 | *@param sText (const char *) The string to search for. | ||
540 | *@returns (long) The index of the first occurrance. -1 for not found. | ||
541 | */ | ||
397 | long find( const char *sText ) | 542 | long find( const char *sText ) |
398 | { | 543 | { |
399 | long nTLen = strlen( sText ); | 544 | long nTLen = strlen( sText ); |
@@ -406,6 +551,11 @@ namespace Bu | |||
406 | return -1; | 551 | return -1; |
407 | } | 552 | } |
408 | 553 | ||
554 | /** | ||
555 | * Do a reverse search for (sText) | ||
556 | *@param sText (const char *) The string to search for. | ||
557 | *@returns (long) The index of the last occurrance. -1 for not found. | ||
558 | */ | ||
409 | long rfind( const char *sText ) | 559 | long rfind( const char *sText ) |
410 | { | 560 | { |
411 | long nTLen = strlen( sText ); | 561 | long nTLen = strlen( sText ); |
@@ -418,6 +568,10 @@ namespace Bu | |||
418 | return -1; | 568 | return -1; |
419 | } | 569 | } |
420 | 570 | ||
571 | /** | ||
572 | * Function the archiver calls to archive your FString. | ||
573 | *@param ar (Archive) The archive which is archiving your FString. | ||
574 | */ | ||
421 | void archive( class Archive &ar ) | 575 | void archive( class Archive &ar ) |
422 | { | 576 | { |
423 | if( ar.isLoading() ) | 577 | if( ar.isLoading() ) |