Simple "C" string container. More...
Public Member Functions | |
SimpleString (void) | |
Default constructor. | |
SimpleString (char cInput) | |
Default constructor for a single char. | |
SimpleString (const char *pInput1) | |
Default constructor for a single "C" string. | |
SimpleString (const char *pInput1, const char *pInput2) | |
Default constructor for concatinated "C" strings. | |
SimpleString (const char *pInput1, const char *pInput2, const char *pInput3) | |
Default constructor for concatinated "C" strings. | |
SimpleString (const char *pInput1, const char *pInput2, const char *pInput3, const char *pInput4) | |
Default constructor for concatinated "C" strings. | |
SimpleString (const char *pInput1, const char *pInput2, const char *pInput3, const char *pInput4, const char *pInput5) | |
Default constructor for concatinated "C" strings. | |
SimpleString (const Burger::SimpleString &rInput) | |
Default copy constructor. | |
~SimpleString () | |
Default destructor. | |
Burger::SimpleString & | operator= (char cInput) |
Assign a new string to an existing Burger::SimpleString. | |
Burger::SimpleString & | operator= (const char *pInput) |
Assign a new string to an existing SimpleString. | |
Burger::SimpleString & | operator= (const Burger::SimpleString &rInput) |
Assign a new string to an existing Burger::SimpleString. | |
operator const char * () const | |
Convert a Burger::SimpleString into a const char *. | |
const char * | GetPtr (void) const |
Convert a Burger::SimpleString into a const char *. | |
char | operator[] (uintptr_t uIndex) const |
Access a character inside of the string. | |
const char & | operator[] (uintptr_t uIndex) |
Access a character reference inside of the string. | |
void | Clear (void) |
Force the assignment of an empty string. | |
uint_t | IsEmpty (void) const |
Determine if a string is empty. | |
uintptr_t | GetLength (void) const |
Return the length of the string in bytes. | |
Private Attributes | |
const char * | m_pData |
Pointer to the actual string, never is NULL. | |
Simple "C" string container.
Most times, an application or class needs to store a copy of a string of unknown length. This class will take a string, allocate memory to hold it and make a copy so the application doesn't have to worry about managing the buffer.
The first and foremost goal of this class is to use the least amount of memory to store a string. This class only has a single member of a const char * to the string so it only occupies 4 or 8 bytes when it's a member of a higher class. If no string is contained, it will point to a global Burger::g_EmptyString so no memory is allocated if no string is assigned. Only when a string is assigned, will a string be allocated.
Because of the nature of the way the string is managed, it is not recommended to use this class for strings that are constantly modified or updated. You may wish to consider using a Burger::String instead.
|
inline |
Default constructor.
Assign the global Burger::g_EmptyString string ("") and exit. No memory allocation is performed.
Burger::SimpleString::SimpleString | ( | char | cInput | ) |
Default constructor for a single char.
If the input is zero, then the global Burger::g_EmptyString string ("") is used, otherwise a 2 byte buffer is allocated and a string containing the single character and a terminating zero is created and assigned.
cInput | Single char to turn into a 1 character length string. Zero will create an empty string. |
Burger::SimpleString::SimpleString | ( | const char * | pInput1 | ) |
Default constructor for a single "C" string.
If the input is NULL or an empty string, the global Burger::g_EmptyString string ("") is used, otherwise a buffer is allocated and the string will be copied and assigned.
pInput1 | Pointer to input string. NULL or an empty string is acceptable. |
Burger::SimpleString::SimpleString | ( | const char * | pInput1, |
const char * | pInput2 ) |
Default constructor for concatinated "C" strings.
Take the passed "C" strings and create a "C" string by concatinating all of them together into a single unified string. If any of the inputs are NULL or empty strings, they will be ignored. If the resulting string is empty, the global Burger::g_EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.
Burger::SimpleString::SimpleString | ( | const char * | pInput1, |
const char * | pInput2, | ||
const char * | pInput3 ) |
Default constructor for concatinated "C" strings.
Take the passed "C" strings and create a "C" string by concatinating all of them together into a single unified string. If any of the inputs are NULL or empty strings, they will be ignored. If the resulting string is empty, the global Burger::g_EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.
Burger::SimpleString::SimpleString | ( | const char * | pInput1, |
const char * | pInput2, | ||
const char * | pInput3, | ||
const char * | pInput4 ) |
Default constructor for concatinated "C" strings.
Take the passed "C" strings and create a "C" string by concatinating all of them together into a single unified string. If any of the inputs are NULL or empty strings, they will be ignored. If the resulting string is empty, the global Burger::g_EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.
pInput1 | Pointer to the first input string. NULL or an empty string is acceptable. |
pInput2 | Pointer to the second input string. NULL or an empty string is acceptable. |
pInput3 | Pointer to the third input string. NULL or an empty string is acceptable. |
pInput4 | Pointer to the fourth input string. NULL or an empty string is acceptable. |
Burger::SimpleString::SimpleString | ( | const char * | pInput1, |
const char * | pInput2, | ||
const char * | pInput3, | ||
const char * | pInput4, | ||
const char * | pInput5 ) |
Default constructor for concatinated "C" strings.
Take the passed "C" strings and create a "C" string by concatinating all of them together into a single unified string. If any of the inputs are NULL or empty strings, they will be ignored. If the resulting string is empty, the global Burger::g_EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.
pInput1 | Pointer to the first input string. NULL or an empty string is acceptable. |
pInput2 | Pointer to the second input string. NULL or an empty string is acceptable. |
pInput3 | Pointer to the third input string. NULL or an empty string is acceptable. |
pInput4 | Pointer to the fourth input string. NULL or an empty string is acceptable. |
pInput5 | Pointer to the fifth input string. NULL or an empty string is acceptable. |
Burger::SimpleString::SimpleString | ( | const Burger::SimpleString & | rInput | ) |
Default copy constructor.
Makes a copy of an existing SimpleString. If the passed string is empty, no memory is allocated, otherwise the string is copied so the original SimpleString can be discarded.
rInput | Reference to a SimpleString to copy. |
Burger::SimpleString::~SimpleString | ( | ) |
void Burger::SimpleString::Clear | ( | void | ) |
Force the assignment of an empty string.
Dispose of the previous string and assign the global Burger::g_EmptyString ("") as the string. This has the effect of releasing all used memory and this instance having an empty string.
|
inline |
Return the length of the string in bytes.
Return the length (in bytes) of the "C" string contained inside of this class. The terminating zero will not count towards the total. The length is the same as if you called Burger::StringLength(const char *) on the "C" string.
\sa Burger::SimpleString::IsEmpty(void) const
|
inline |
Convert a Burger::SimpleString into a const char *.
Most functions passed a Burger::SimpleString will want a const char * instead. This inline accessor will allow access to the contained string.
|
inline |
|
inline |
Convert a Burger::SimpleString into a const char *.
Most functions passed a Burger::SimpleString will want a const char * instead. This inline accessor will allow access to the contained string.
Burger::SimpleString & Burger::SimpleString::operator= | ( | char | cInput | ) |
Assign a new string to an existing Burger::SimpleString.
Dispose of the previous string and assign a new one that's one character long. If cInput is zero, the resulting string will be empty.
cInput | Single character to make a string out of. If zero, the string will be empty. |
Burger::SimpleString & Burger::SimpleString::operator= | ( | const Burger::SimpleString & | rInput | ) |
Assign a new string to an existing Burger::SimpleString.
Dispose of the previous string and assign a new one. If rInput is an empty string, the resulting string will be empty.
rInput | Reference to a Burger::SimpleString to make a copy of. |
Burger::SimpleString & Burger::SimpleString::operator= | ( | const char * | pInput | ) |
Assign a new string to an existing SimpleString.
Dispose of the previous string and assign a new one. If pInput is NULL or an empty string, the resulting string will be empty.
pInput | Pointer to a "C" string to make a copy of. NULL is acceptable. |
|
inline |
Access a character reference inside of the string.
Returns a reference to a single character inside the string by using a supplied index.
uIndex | Index into the string, 0 to less than Burger::SimpleString::GetLength(void) const. |
|
inline |
Access a character inside of the string.
Returns a single character inside the string by using a supplied index.
uIndex | Index into the string, 0 to less than Burger::SimpleString::GetLength(void) const. |
|
private |
Pointer to the actual string, never is NULL.