#include <TString.h>
Public Methods | |
bool | set (PCSTR) |
bool | set (PCWSTR) |
bool | set (const WCHAR) |
bool | set (const CHAR) |
bool | set (const int) |
int | getBufferSize () const |
int | getLength () const |
PCTSTR | get () const |
operator PCTSTR () const | |
Overloaded static cast operator. More... | |
TCHAR | operator[] (const int) const |
const TString & | operator= (const TString &) |
const TString & | operator= (PCSTR) |
const TString & | operator= (PCWSTR) |
const TString & | operator= (const WCHAR) |
const TString & | operator= (const CHAR) |
bool | operator! () const |
clear () | |
TString (const WCHAR) | |
TString (const CHAR) | |
TString (const int) | |
TString (PCSTR) | |
TString (PCWSTR) | |
TString (const TString &) | |
TString () | |
virtual | ~TString () |
const TString & | operator+= (const TString &) |
const TString & | operator+= (PCSTR) |
const TString & | operator+= (PCWSTR) |
const TString & | operator+= (const WCHAR) |
const TString & | operator+= (const CHAR) |
Private Methods | |
int | stringCopy (PCSTR, const int=-1) |
int | stringCopy (PCWSTR, const int=-1) |
int | memoryAlloc (PCSTR, const bool=true) |
int | memoryAlloc (PCWSTR, const bool=true) |
bool | alloc (const int) |
memoryDealloc () | |
Private Attributes | |
PTSTR | string |
The actual string. | |
int | bufferLength |
string length + null terminator. | |
Static Private Attributes | |
PTSTR | EMPTYSTRING = TEXT("") |
Friends | |
TString | operator+ (const TString &, const TString &) |
TString | operator+ (const TString &, PCSTR) |
TString | operator+ (const TString &, PCWSTR) |
TString | operator+ (PCSTR, const TString &) |
TString | operator+ (PCWSTR, const TString &) |
TString | operator+ (const TString &, const WCHAR) |
TString | operator+ (const TString &, const CHAR) |
TString | operator+ (const WCHAR, const TString &) |
TString | operator+ (const CHAR, const TString &) |
Definition at line 21 of file TString.h.
|
ANSI Character constructor Definition at line 79 of file TString.cpp. References bufferLength, EMPTYSTRING, set(), and string.
00080 { 00081 bufferLength = 1; 00082 string = EMPTYSTRING; 00083 set(unicodeChar); 00084 } |
|
Unicode Character constructor Definition at line 89 of file TString.cpp. References bufferLength, EMPTYSTRING, set(), and string.
00090 { 00091 bufferLength = 1; 00092 string = EMPTYSTRING; 00093 set(ansiChar); 00094 } |
|
Expilict integer constructor /todo remove construtor and replace capability with a printf style function Definition at line 100 of file TString.cpp. References bufferLength, EMPTYSTRING, set(), and string.
00101 { 00102 bufferLength = 1; 00103 string = EMPTYSTRING; 00104 set(integer); 00105 } |
|
ANSI String constructor Definition at line 59 of file TString.cpp. References bufferLength, EMPTYSTRING, set(), and string.
00060 { 00061 bufferLength = 1; 00062 string = EMPTYSTRING; 00063 set(ansiString); 00064 } |
|
Unicode String constructor Definition at line 69 of file TString.cpp. References bufferLength, EMPTYSTRING, set(), and string.
00070 { 00071 bufferLength = 1; 00072 string = EMPTYSTRING; 00073 set(unicodeString); 00074 } |
|
Copy constructor Definition at line 49 of file TString.cpp. References bufferLength, EMPTYSTRING, get(), set(), and string.
00050 { 00051 bufferLength = 1; 00052 string = EMPTYSTRING; 00053 set(copy.get()); 00054 } |
|
Default constructor creates an empty string Definition at line 40 of file TString.cpp. References bufferLength, EMPTYSTRING, and string. Referenced by operator+=().
00041 { 00042 bufferLength = 1; 00043 string = EMPTYSTRING; 00044 } |
|
Object Destructor Definition at line 111 of file TString.cpp. References memoryDealloc().
00112 { 00113 memoryDealloc(); 00114 } |
|
The Actual memory allocation function. If you wish to use heap allocation functions then only this and memoryDealloc() require alteration Definition at line 567 of file TString.cpp. References bufferLength, EMPTYSTRING, string, and TSTRING_BUFFERSIZE. Referenced by memoryAlloc(), operator+(), operator+=(), and set().
00568 { 00569 // Allocate memory 00570 string = new TCHAR[TSTRING_BUFFERSIZE(length)]; 00571 // Check Allocation 00572 if ( string == NULL ){ 00573 bufferLength = 1; 00574 string = EMPTYSTRING; 00575 return false; 00576 } else { 00577 bufferLength = length; 00578 return true; 00579 } 00580 } |
|
Release the Strings buffer and set it to equal an empty string Definition at line 446 of file TString.cpp. References memoryDealloc(). Referenced by set().
00447 { 00448 memoryDealloc(); 00449 } |
|
Gets a constant pointer to the String. Unicode if compiled with UNICODE, ANSI otherwise.
Definition at line 440 of file TString.cpp. References string. Referenced by operator PCTSTR(), operator=(), and TString().
00441 { 00442 return string; 00443 } |
|
Return the size (in bytes) of the buffer required to hold the current string Definition at line 452 of file TString.cpp. References bufferLength, and TSTRING_BUFFERSIZE.
00453 { 00454 return TSTRING_BUFFERSIZE(bufferLength); 00455 } |
|
Return the length of the String excluding the terminating character Definition at line 458 of file TString.cpp. References bufferLength.
00459 { 00460 return bufferLength - 1; 00461 } |
|
Allocate the memory required to store the string. Along with it's overloaded version this is the only point that requires modification to change the way TString reallocates memory each time its contents is changed.
Definition at line 525 of file TString.cpp. References alloc(), bufferLength, memoryDealloc(), TSTRING_BUFFERLENGTHW, and TSTRING_BUFFERSIZE.
00526 { 00527 int length; 00528 00529 #ifdef UNICODE 00530 00531 length = TSTRING_BUFFERLENGTHW(unicodeString); 00532 00533 if( !allocate ) 00534 return TSTRING_BUFFERSIZE(length); 00535 00536 #else 00537 00538 length = WideCharToMultiByte( 00539 CP_ACP, // code page 00540 0, // performance and mapping flags 00541 unicodeString, // wide-character string 00542 -1, // calculate number of chars in string 00543 NULL, // buffer for new string (not used yet) 00544 0, // return size of required buffer in bytes 00545 NULL, // default for unmappable chars 00546 NULL); // set when default char used 00547 00548 if( !allocate || length == 0) 00549 return TSTRING_BUFFERSIZE(length); 00550 00551 #endif 00552 00553 memoryDealloc(); 00554 00555 if( alloc(length) ) 00556 return TSTRING_BUFFERSIZE(bufferLength); 00557 else 00558 return -1; 00559 00560 } |
|
Allocate the memory required to store the string. Along with it's overloaded version this is the only point that requires modification to change the way TString reallocates memory each time its contents is changed.
Definition at line 477 of file TString.cpp. References alloc(), bufferLength, memoryDealloc(), and TSTRING_BUFFERSIZE. Referenced by set().
00478 { 00479 int length; 00480 00481 #ifdef UNICODE 00482 00483 // Calculate string length 00484 length = MultiByteToWideChar( 00485 CP_ACP, // code page 00486 0, // character-type options 00487 ansiString, // string to map 00488 -1, // calculate number characters in string (inc terminator) 00489 NULL, // wide-character buffer (not used yet) 00490 0); // return size of required buffer in bytes 00491 00492 if( !allocate || length == 0) 00493 return TSTRING_BUFFERSIZE(length); 00494 00495 #else 00496 00497 length = calculateTotalLength(ansiString); 00498 00499 if( !allocate ) 00500 return TSTRING_BUFFERSIZE(length); 00501 00502 #endif 00503 00504 memoryDealloc(); 00505 00506 if( alloc(length) ) 00507 return TSTRING_BUFFERSIZE(bufferLength); 00508 else 00509 return -1; 00510 00511 } |
|
The memory deallocation function. Release the memory, and set this to equal the empty string. If you wish to use heap allocation functions then only this and alloc() require alteration. Definition at line 588 of file TString.cpp. References bufferLength, EMPTYSTRING, and string. Referenced by clear(), memoryAlloc(), operator+=(), and ~TString().
00589 { 00590 if( string != EMPTYSTRING ){ 00591 delete [] string; 00592 string = EMPTYSTRING; 00593 bufferLength = 1; 00594 } 00595 } |
|
Allows a TString to be used anywhere a constant String is expected Definition at line 48 of file TString.h. References EMPTYSTRING, and get().
00048 { return get(); } |
|
Is not empty operator
Definition at line 324 of file TString.cpp. References bufferLength.
00325 { 00326 return bufferLength == 1; 00327 } |
|
Overloading of the += operator. Appends the right string to this TString Definition at line 292 of file TString.cpp. References TString().
00293 { 00294 *this += TString(right); 00295 return *this; 00296 } |
|
Overloading of the += operator. Appends the right string to this TString Definition at line 286 of file TString.cpp. References TString().
00287 { 00288 *this += TString(right); 00289 return *this; 00290 } |
|
Overloading of the += operator. Appends the right string to this TString Definition at line 280 of file TString.cpp. References TString().
00281 { 00282 *this += TString(right); 00283 return *this; 00284 } |
|
Overloading of the += operator. Appends the right string to this TString Definition at line 274 of file TString.cpp. References TString().
00275 { 00276 *this += TString(right); 00277 return *this; 00278 } |
|
Overloading of the += operator. Appends the right string to this TString Definition at line 247 of file TString.cpp. References alloc(), bufferLength, memoryDealloc(), string, and stringCopy().
00248 { 00249 TString left( *this ); 00250 00251 memoryDealloc(); 00252 00253 const int totalLength = left.bufferLength - 1 + right.bufferLength; 00254 00255 assert( alloc( totalLength ) ); 00256 00257 assert( stringCopy ( left, left.bufferLength ) == left.bufferLength ); 00258 00259 #ifdef UNICODE 00260 00261 wcscat( string, right.string ); 00262 00263 #else 00264 00265 strcat( string, right.string ); 00266 00267 #endif 00268 00269 return *this; 00270 } |
|
ANSI character assignment operator Definition at line 230 of file TString.cpp. References set().
00231 { 00232 set(ansiChar); 00233 return *this; 00234 } |
|
Unicode character assignment operator Definition at line 237 of file TString.cpp. References set().
00238 { 00239 set(unicodeChar); 00240 return *this; 00241 } |
|
Unicode assignment operator Definition at line 216 of file TString.cpp.
|
|
ANSI assignment operator Definition at line 202 of file TString.cpp.
|
|
Assignment operator Definition at line 193 of file TString.cpp.
|
|
Array access operator (doesn't allow modification)
Definition at line 310 of file TString.cpp. References bufferLength, and string.
00311 { 00312 if( index < 0 || index > bufferLength - 1 ) 00313 RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL); 00314 00315 TCHAR rtrn = string[index]; 00316 return rtrn; 00317 } |
|
Sets this TString to a string representation of an integer
Definition at line 419 of file TString.cpp. References set().
00420 { 00421 TCHAR temp[12]; // temp: longest string needed to represent int 00422 00423 #ifdef UNICODE 00424 swprintf(temp, L"%d", integer); 00425 #else 00426 sprintf(temp, "%d", integer); 00427 #endif 00428 00429 return set(temp); 00430 } |
|
Sets this TString to the given ANSI Character plus a terminating character
Definition at line 384 of file TString.cpp. References alloc(), string, and stringCopy().
00385 { 00386 if( alloc(1+1) ){ 00387 *(string + 1) = TEXT(''); 00388 return stringCopy(&ansiChar, 1) == 1; 00389 } else 00390 return false; 00391 } |
|
Sets this TString to the given Unicode Character plus a terminating character
Definition at line 400 of file TString.cpp. References alloc(), string, and stringCopy().
00401 { 00402 if( alloc(1+1) ){ 00403 *(string + 1) = TEXT(''); 00404 return stringCopy(&unicodeChar, 1) == 1; 00405 } else 00406 return false; 00407 } |
|
Sets this TString to the given Unicode String. If the string is a null pointer the TString is simply emptied
Definition at line 362 of file TString.cpp. References clear(), memoryAlloc(), stringCopy(), TSTRING_BUFFERLENGTHW, and TSTRING_BUFFERSIZE.
00363 { 00364 if( unicodeString == NULL ){ 00365 clear(); 00366 return true; 00367 } 00368 00369 int unicodeLength = TSTRING_BUFFERLENGTHW(unicodeString); 00370 00371 if( memoryAlloc(unicodeString) == TSTRING_BUFFERSIZE(unicodeLength) ) 00372 return stringCopy(unicodeString, unicodeLength) == unicodeLength; 00373 else 00374 return false; 00375 } |
|
Sets this TString to the given ANSI String. If the string is a null pointer the TString is simply emptied
Definition at line 339 of file TString.cpp. References clear(), memoryAlloc(), stringCopy(), TSTRING_BUFFERLENGTHA, and TSTRING_BUFFERSIZE. Referenced by operator=(), set(), and TString().
00340 { 00341 if( ansiString == NULL ){ 00342 clear(); 00343 return true; 00344 } 00345 00346 int ansiLength = TSTRING_BUFFERLENGTHA(ansiString); 00347 00348 if( memoryAlloc(ansiString) == TSTRING_BUFFERSIZE(ansiLength) ) 00349 return stringCopy(ansiString, ansiLength) == ansiLength; 00350 else 00351 return false; 00352 } |
|
Relies on this buffer being large enough to hold the string
Definition at line 634 of file TString.cpp. References bufferLength, string, TSTRING_BUFFERLENGTHW, and TSTRING_BUFFERSIZE.
00635 { 00636 #ifdef UNICODE 00637 00638 int unicodeLength = length; 00639 if( unicodeLength < 0 ){ 00640 unicodeLength = TSTRING_BUFFERLENGTHW(unicodeString); 00641 } 00642 00643 __try{ 00644 CopyMemory(string, unicodeString, TSTRING_BUFFERSIZE(unicodeLength)); 00645 } 00646 __except( (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) 00647 ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00648 return -1; 00649 } 00650 00651 return unicodeLength; 00652 00653 #else 00654 00655 // Convert Unicode to ANSI 00656 return WideCharToMultiByte(CP_ACP, 0, unicodeString, length, string, TSTRING_BUFFERSIZE(bufferLength), NULL, NULL); 00657 00658 #endif 00659 } |
|
Relies on this buffer being large enough to hold the string
Definition at line 602 of file TString.cpp. References bufferLength, string, and TSTRING_BUFFERSIZE. Referenced by operator+(), operator+=(), and set().
00603 { 00604 #ifdef UNICODE 00605 00606 // Convert ANSI to Unicode 00607 return MultiByteToWideChar(CP_ACP, 0, ansiString, length, string, TSTRING_BUFFERSIZE(bufferLength)); 00608 00609 #else 00610 00611 int ansiLength = length; 00612 if( ansiLength < 0 ){ 00613 ansiLength = calculateTotalLength(ansiString); 00614 } 00615 00616 __try{ 00617 CopyMemory(string, ansiString, TSTRING_BUFFERSIZE(ansiLength)); 00618 } 00619 __except( (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION) 00620 ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { 00621 return -1; 00622 } 00623 00624 return ansiLength; 00625 00626 #endif 00627 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 185 of file TString.cpp.
00186 { 00187 return TString(left) + right; 00188 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 180 of file TString.cpp.
00181 { 00182 return TString(left) + right; 00183 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 175 of file TString.cpp.
00176 { 00177 return left + TString(right); 00178 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 170 of file TString.cpp.
00171 { 00172 return left + TString(right); 00173 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 165 of file TString.cpp.
00166 { 00167 return TString(left) + right; 00168 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 160 of file TString.cpp.
00161 { 00162 return TString(left) + right; 00163 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 155 of file TString.cpp.
00156 { 00157 return left + TString(right); 00158 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 150 of file TString.cpp.
00151 { 00152 return left + TString(right); 00153 } |
|
Overloading of the + operator to perform the concatenation of two strings Definition at line 122 of file TString.cpp.
00123 { 00124 // Length of right (less term) + this length (includes term) 00125 const int totalLength = left.bufferLength - 1 + right.bufferLength; 00126 00127 TString rtrn; 00128 00129 // Alloc sufficient memory 00130 assert( rtrn.alloc( totalLength ) ); 00131 00132 // Copy left to rtrn (inc term) 00133 assert( rtrn.stringCopy( left, left.bufferLength ) == left.bufferLength ); 00134 00135 #ifdef UNICODE 00136 00137 wcscat( rtrn.string, right.string ); 00138 00139 #else 00140 00141 strcat( rtrn.string, right.string ); 00142 00143 #endif 00144 00145 return rtrn; 00146 } |
|
A static variable holding an empty string Definition at line 120 of file TString.cpp. Referenced by alloc(), memoryDealloc(), operator PCTSTR(), and TString(). |