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

Simple "C" string numeric conversion class. More...

#include <brnumberstring.h>

List of all members.

Public Member Functions

 NumberString (Word32 uInput)
 Default constructor for an unsigned 32 bit integer.
 NumberString (Word32 uInput, Word uFormat)
 Default constructor for an unsigned 32 bit integer with formatting.
 NumberString (Int32 iInput)
 Default constructor for a signed 32 bit integer.
 NumberString (Int32 iInput, Word uFormat)
 Default constructor for a signed 32 bit integer with formatting.
 NumberString (float fInput)
 Default constructor for a 32 bit float.
 NumberString (double dInput)
 Default constructor for a 64 bit float.
Burger::NumberStringoperator= (Word32 uInput)
 Copy operator for an unsigned 32 bit integer.
Burger::NumberStringoperator= (Int32 iInput)
 Copy operator for a signed 32 bit integer.
Burger::NumberStringoperator= (float fInput)
 Copy operator for a 32 bit float.
Burger::NumberStringoperator= (double dInput)
 Copy operator for a 64 bit float.
BURGER_INLINE operator const char * () const
 Get a pointer to the string.
BURGER_INLINE const char * GetPtr (void) const
 Get a pointer to the string.
BURGER_INLINE char operator[] (WordPtr uIndex) const
 Get a character from the string.
BURGER_INLINE const char & operator[] (WordPtr uIndex)
 Get a character reference from the string.
BURGER_INLINE void Clear (void)
 Erase the string.
BURGER_INLINE Word IsEmpty (void) const
 Return TRUE if the string is blank.
BURGER_INLINE WordPtr GetLength (void) const
 Get the length of the string in bytes.

Private Attributes

char m_Data [32]
 String buffer.

Detailed Description

Simple "C" string numeric conversion class.

To convert a number into a string quickly and without the worry of creating a text buffer to contain the ASCII string, use this class. Once the string is created, you can access via Burger::NumberString::GetPtr() const or const char * accessors.

The main benefit of this class is that the string buffer is part of the class instance, so no behind the scenes memory allocation is performed. It's best used with creating a local on the stack instance with the number to be converted as input to the constructor. You then access the string and use it as you wish.

Most constructors can take an optional format parameter so you can have some control as to how the string is created.


Constructor & Destructor Documentation

Default constructor for an unsigned 32 bit integer.

Convert the 32 bit unsigned integer into an ASCII string and store that string inside the class. The resulting string is from 1 to 10 digits in length.

Parameters:
uInputUnsigned 32 bit integer to convert to ASCII.
See also:
Burger::NumberString::NumberString(Int32) or Burger::NumberString::NumberString(Word32,Word)
Burger::NumberString::NumberString ( Word32  uInput,
Word  uFormat 
)

Default constructor for an unsigned 32 bit integer with formatting.

Convert the 32 bit unsigned integer into an ASCII string and store that string inside the class. The resulting string is from 1 to 10 digits in length. Formatting will have some influence on the string's length.

The format parameter is passed directly to Burger::NumberToAscii(char *,Word32,Word), please see that function's documentation for what values you can pass.

Parameters:
uInputUnsigned 32 bit integer to convert to ASCII.
uFormatFormatting parameter.
See also:
Burger::NumberString::NumberString(Word32) or Burger::NumberString::NumberString(Word32,Word) Burger::NumberToAscii(char *,Word32,Word)

Default constructor for a signed 32 bit integer.

Convert the 32 bit signed integer into an ASCII string and store that string inside the class. The resulting string is from 1 to 11 digits in length.

Parameters:
iInputSigned 32 bit integer to convert to ASCII.
See also:
Burger::NumberString::NumberString(Word32) or Burger::NumberString::NumberString(Int32,Word)
Burger::NumberString::NumberString ( Int32  iInput,
Word  uFormat 
)

Default constructor for a signed 32 bit integer with formatting.

Convert the 32 bit signed integer into an ASCII string and store that string inside the class. The resulting string is from 1 to 11 digits in length. Formatting will have some influence on the string's length.

The format parameter is passed directly to Burger::NumberToAscii(char *,Int32,Word), please see that function's documentation for what values you can pass.

Parameters:
iInputSigned 32 bit integer to convert to ASCII.
uFormatFormatting parameter.
See also:
Burger::NumberString::NumberString(Int32) or Burger::NumberString::NumberString(Word32,Word) Burger::NumberToAscii(char *,Word32,Word)

Default constructor for a 32 bit float.

Convert the 32 bit float into an ASCII string and store that string inside the class. The resulting string is from 1 to 32 digits in length.

Parameters:
fInput32 bit float to convert to ASCII.
See also:
Burger::NumberString::NumberString(double) or Burger::NumberToAscii(char *,float)

Default constructor for a 64 bit float.

Convert the 64 bit float into an ASCII string and store that string inside the class. The resulting string is from 1 to 32 digits in length.

Parameters:
dInput64 bit float to convert to ASCII.
See also:
Burger::NumberString::NumberString(float) or Burger::NumberToAscii(char *,double)

Member Function Documentation

Erase the string.

Set the string to a blank string, I.E. "".

See also:
Burger::NumberString::IsEmpty() const
Burger::NumberString::GetLength ( void  ) const [inline]

Get the length of the string in bytes.

By calling Burger::StringLength(), return the length of the string contained within.

Note:
This function performs no caching. If the length of the string is not expected to change in a performance critical loop, cache the returned value and use it in the loop instead of calling this function repeatedly.
Returns:
Length of the string in bytes. The terminating zero doesn't count.
See also:
Burger::NumberString::IsEmpty() const
Burger::NumberString::GetPtr ( void  ) const [inline]

Get a pointer to the string.

Retrieve a char * to the string contained in this class. The pointer is const because this class was not meant to have anything modify the string without the class knowing about the operation.

Returns:
const char * to the string within. The string is always valid.
See also:
Burger::NumberString::operator const char *() const
Burger::NumberString::IsEmpty ( void  ) const [inline]

Return TRUE if the string is blank.

If the string inside is blank, return TRUE, otherwise return FALSE.

Returns:
TRUE if the string is blank, FALSE if not.
See also:
Burger::NumberString::GetLength() const or Burger::NumberString::Clear()
Burger::NumberString::operator const char * ( ) const [inline]

Get a pointer to the string.

Retrieve a char * to the string contained in this class. The pointer is const because this class was not meant to have anything modify the string without the class knowing about the operation.

Returns:
const char * to the string within. The string is always valid.
See also:
Burger::NumberString::GetPtr(void) const
Burger::NumberString & Burger::NumberString::operator= ( Word32  uInput)

Copy operator for an unsigned 32 bit integer.

Convert the 32 bit unsigned integer into an ASCII string and store that string inside the class. The resulting string is from 1 to 10 digits in length.

Parameters:
uInputUnsigned 32 bit integer to convert to ASCII.
See also:
Burger::NumberString::NumberString(Word32) or Burger::NumberString::NumberString(Word32,Word)
Burger::NumberString & Burger::NumberString::operator= ( Int32  iInput)

Copy operator for a signed 32 bit integer.

Convert the 32 bit signed integer into an ASCII string and store that string inside the class. The resulting string is from 1 to 11 digits in length.

Parameters:
iInputSigned 32 bit integer to convert to ASCII.
See also:
Burger::NumberString::NumberString(Int32) or Burger::NumberString::NumberString(Int32,Word)
Burger::NumberString & Burger::NumberString::operator= ( float  fInput)

Copy operator for a 32 bit float.

Convert the 32 bit float into an ASCII string and store that string inside the class. The resulting string is from 1 to 32 digits in length.

Parameters:
fInput32 bit float to convert to ASCII.
See also:
Burger::NumberString::NumberString(float) or Burger::NumberToAscii(char *,float)
Burger::NumberString & Burger::NumberString::operator= ( double  dInput)

Copy operator for a 64 bit float.

Convert the 64 bit float into an ASCII string and store that string inside the class. The resulting string is from 1 to 32 digits in length.

Parameters:
dInput64 bit float to convert to ASCII.
See also:
Burger::NumberString::NumberString(double) or Burger::NumberToAscii(char *,float)
Burger::NumberString::operator[] ( WordPtr  uIndex) const [inline]

Get a character from the string.

Retrieve a char from inside the string contained in this class. There is no bounds checking performed on the index passed just like if this were a literal char array.

Returns:
One character from the string.
See also:
Burger::NumberString::operator [](WordPtr)
Burger::NumberString::operator[] ( WordPtr  uIndex) [inline]

Get a character reference from the string.

Retrieve a const char refernce from inside the string contained in this class. There is no bounds checking performed on the index passed just like if this were a literal char array.

Returns:
A const character reference from the string.
See also:
Burger::NumberString::operator [](WordPtr) const

Member Data Documentation

char Burger::NumberString::m_Data[32] [private]

String buffer.