BurgerLib
Public Member Functions | Private Attributes
Burger::SimpleString Class Reference

Simple "C" string container. More...

#include <brsimplestring.h>

List of all members.

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::SimpleStringoperator= (char cInput)
 Assign a new string to an existing Burger::SimpleString.
Burger::SimpleStringoperator= (const char *pInput)
 Assign a new string to an existing SimpleString.
Burger::SimpleStringoperator= (const Burger::SimpleString &rInput)
 Assign a new string to an existing Burger::SimpleString.
BURGER_INLINE operator const char * () const
 Convert a Burger::SimpleString into a const char *.
BURGER_INLINE const char * GetPtr (void) const
 Convert a Burger::SimpleString into a const char *.
BURGER_INLINE char operator[] (WordPtr uIndex) const
 Access a character inside of the string.
BURGER_INLINE const char & operator[] (WordPtr uIndex)
 Access a character reference inside of the string.
void BURGER_API Clear (void)
 Force the assignment of an empty string.
BURGER_INLINE Word IsEmpty (void) const
 Determine if a string is empty.
BURGER_INLINE WordPtr 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.

Detailed Description

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 formost 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::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 WorkString instead.


Constructor & Destructor Documentation

Default constructor.

Assign the global Burger::EmptyString string ("") and exit. No memory allocation is performed.

See also:
Burger::SimpleString::SimpleString(const char *)

Default constructor for a single char.

If the input is zero, then the global Burger::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.

Parameters:
cInputSingle char to turn into a 1 character length string. Zero will create an empty string.
See also:
Burger::SimpleString::SimpleString(const char *)
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::EmptyString string ("") is used, otherwise a buffer is allocated and the string will be copied and assigned.

Parameters:
pInput1Pointer to input string. NULL or an empty string is acceptable.
See also:
Burger::SimpleString::SimpleString(const char *,const char *)
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::EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.

Parameters:
pInput1Pointer to the first input string. NULL or an empty string is acceptable.
pInput2Pointer to the second input string. NULL or an empty string is acceptable.
See also:
Burger::SimpleString::SimpleString(const char *)
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::EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.

Parameters:
pInput1Pointer to the first input string. NULL or an empty string is acceptable.
pInput2Pointer to the second input string. NULL or an empty string is acceptable.
pInput3Pointer to the third input string. NULL or an empty string is acceptable.
See also:
Burger::SimpleString::SimpleString(const char *)
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::EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.

Parameters:
pInput1Pointer to the first input string. NULL or an empty string is acceptable.
pInput2Pointer to the second input string. NULL or an empty string is acceptable.
pInput3Pointer to the third input string. NULL or an empty string is acceptable.
pInput4Pointer to the fourth input string. NULL or an empty string is acceptable.
See also:
Burger::SimpleString::SimpleString(const char *)
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::EmptyString string ("") is used internally, otherwise a buffer is allocated and the string(s) will be copied, concatinated and assigned to this class instance.

Note:
If you need more than 5 strings, you will have to chain string creation or possibly use a WorkString class instance instead.
Parameters:
pInput1Pointer to the first input string. NULL or an empty string is acceptable.
pInput2Pointer to the second input string. NULL or an empty string is acceptable.
pInput3Pointer to the third input string. NULL or an empty string is acceptable.
pInput4Pointer to the fourth input string. NULL or an empty string is acceptable.
pInput5Pointer to the fifth input string. NULL or an empty string is acceptable.
See also:
Burger::SimpleString::SimpleString(const char *)

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.

Parameters:
rInputReference to a SimpleString to copy.
See also:
Burger::SimpleString::SimpleString(const char *)

Default destructor.

Releases any allocated memory.

See also:
Burger::SimpleString::Clear(void)

Member Function Documentation

Force the assignment of an empty string.

Dispose of the previous string and assign the global Burger::EmptyString ("") as the string. This has the effect of releasing all used memory and this instance having an empty string.

See also:
Burger::SimpleString::IsEmpty(void) const

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.

Note:
It isn't recommended to use this member function in a bottleneck routine because the length is calculated and not cached.
Returns:
The length of the "C" string in bytes (Without counting the terminating zero).
See also:
Burger::SimpleString::IsEmpty(void) const
const char * Burger::SimpleString::GetPtr ( 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.

Note:
It is not advised to cast away the const and modify the string. You can do this on a non-empty string as long as you do not attempt to write past the terminating zero.
Returns:
A pointer to the contained "C" string. Modify with caution.
See also:
Burger::SimpleString::operator const char *() const.
Word Burger::SimpleString::IsEmpty ( void  ) const [inline]

Determine if a string is empty.

Return TRUE if the string is only a terminating zero and nothing else. FALSE is returned if the string has any data inside.

Returns:
TRUE if the string is an empty one, FALSE if it isn't.
See also:
Burger::SimpleString::GetLength(void) const or Burger::SimpleString::Clear(void)
Burger::SimpleString::operator const char * ( ) 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.

Note:
It is not advised to cast away the const and modify the string. You can do this on a non-empty string as long as you do not attempt to write past the terminating zero.
Returns:
A pointer to the contained "C" string. Modify with caution.
See also:
Burger::SimpleString::GetPtr(void) const.
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.

Parameters:
cInputSingle character to make a string out of. If zero, the string will be empty.
Returns:
A reference to the "this" record.
See also:
Burger::SimpleString::operator = (const char *)
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.

Parameters:
pInputPointer to a "C" string to make a copy of. NULL is acceptable.
Returns:
A reference to the "this" record.
See also:
Burger::SimpleString::operator = (const Burger::SimpleString &)
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.

Parameters:
rInputReference to a Burger::SimpleString to make a copy of.
Returns:
A reference to the "this" record.
See also:
Burger::SimpleString::operator = (const char *)
char Burger::SimpleString::operator[] ( WordPtr  uIndex) const [inline]

Access a character inside of the string.

Returns a single character inside the string by using a supplied index.

Note:
No bounds checking is done. It's possible for you to access invalid data. Make sure that your index is valid before accessing the string in this manner.
Parameters:
uIndexIndex into the string, 0 to less than Burger::SimpleString::GetLength(void) const.
Returns:
Character at the supplied index.
See also:
Burger::SimpleString::operator[](WordPtr)
const char & Burger::SimpleString::operator[] ( WordPtr  uIndex) [inline]

Access a character reference inside of the string.

Returns a reference to a single character inside the string by using a supplied index.

Note:
No bounds checking is done. It's possible for you to access invalid data. Make sure that your index is valid before accessing the string in this manner.
Parameters:
uIndexIndex into the string, 0 to less than Burger::SimpleString::GetLength(void) const.
Returns:
Character reference at the supplied index.
See also:
Burger::SimpleString::operator[](WordPtr) const

Member Data Documentation

const char* Burger::SimpleString::m_pData [private]

Pointer to the actual string, never is NULL.