Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::NumberStringHex Class Reference

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

Public Member Functions

 NumberStringHex () noexcept
 Default constructor.
 
template<class T >
 NumberStringHex (T input) noexcept
 Default constructor for an integral.
 
template<class T >
 NumberStringHex (T uInput, uint_t uFormat) noexcept
 Default constructor for an integral with formatting.
 
template<class T >
NumberStringHexoperator= (T input) noexcept
 Copy operator for an integral.
 
 operator const char * () const noexcept
 Get a pointer to the string.
 
const char * data (void) const noexcept
 Get a pointer to the string.
 
const char * c_str (void) const noexcept
 Get a pointer to the string.
 
char operator[] (uintptr_t uIndex) const noexcept
 Get a character from the string.
 
const char & operator[] (uintptr_t uIndex) noexcept
 Get a character reference from the string.
 
void clear (void) noexcept
 Erase the string.
 
uint_t empty (void) const noexcept
 Return TRUE if the string is blank.
 
uintptr_t length (void) const noexcept
 Get the length of the string in bytes.
 
uintptr_t capacity (void) const noexcept
 Get the size of the internal buffer in bytes.
 

Private Attributes

char m_Data [24]
 String buffer.
 

Detailed Description

Simple "C" string hexadecimal conversion class.


To convert a hexadecimal 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 NumberStringHex::c_str() 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. After which, the program can access the string and use it as needed.

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

// Cross platform way of printing a 64 bit hex value
uint64_t uValue = 0x123456789ABCDULL;
printf("uValue = 0x%s\n",Text.c_str());
// Output is "uValue = 0x000123456789ABCD"
Simple "C" string hexadecimal conversion class.
Definition burger.h:17204

Constructor & Destructor Documentation

◆ NumberStringHex() [1/3]

Burger::NumberStringHex::NumberStringHex ( )
inlinenoexcept

Default constructor.


Initialize to an empty string

See also
NumberStringHex(T) or NumberStringHex(T, uint_t)

◆ NumberStringHex() [2/3]

template<class T >
Burger::NumberStringHex::NumberStringHex ( T input)
inlinenoexcept

Default constructor for an integral.


Convert the integral into an ASCII hex string and store that string inside the class. The resulting string is from 1 to 8 digits in length depending on the number of bytes the integral occupies.

Template Parameters
Tinput data type, tested with is_integral.
Parameters
inputIntegral value to print in HEX to a string.
See also
NumberToAsciiHex(char *, T) or NumberStringHex::NumberStringHex(T, uint_t)

◆ NumberStringHex() [3/3]

template<class T >
Burger::NumberStringHex::NumberStringHex ( T input,
uint_t uFormat )
inlinenoexcept

Default constructor for an integral with formatting.


Convert the integral into an ASCII hex string and store that string inside the class. The resulting string is from 1 to 8 digits in length in length depending on the number of bytes the integral occupies. Formatting will have some influence on the string's length.

The format parameter is passed directly to NumberToAsciiHex(char*,T,uint_t), please see that function's documentation for what values you can pass.

Template Parameters
Tinput data type, tested with is_integral.
Parameters
inputIntegral value to print in HEX to a string.
uFormatFormatting parameter.
See also
NumberToAsciiHex(char *, T, uint_t) or NumberStringHex(T, uint_t)

Member Function Documentation

◆ c_str()

const char * Burger::NumberStringHex::c_str ( void ) const
inlinenodiscardnoexcept

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
operator const char*() const or data() const

◆ capacity()

uintptr_t Burger::NumberStringHex::capacity ( void ) const
inlinenodiscardnoexcept

Get the size of the internal buffer in bytes.


Return the immutable buffer length.

Returns
Length of the total buffer in bytes.
See also
length() const

◆ clear()

void Burger::NumberStringHex::clear ( void )
inlinenoexcept

Erase the string.


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

See also
empty() const

◆ data()

const char * Burger::NumberStringHex::data ( void ) const
inlinenodiscardnoexcept

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
operator const char*() const or c_str() const

◆ empty()

uint_t Burger::NumberStringHex::empty ( void ) const
inlinenodiscardnoexcept

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
length() const or clear()

◆ length()

uintptr_t Burger::NumberStringHex::length ( void ) const
inlinenodiscardnoexcept

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
empty() const

◆ operator const char *()

Burger::NumberStringHex::operator const char * ( ) const
inlinenoexcept

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
c_str(void) const

◆ operator=()

template<class T >
NumberStringHex & Burger::NumberStringHex::operator= ( T input)
inlinenoexcept

Copy operator for an integral.


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

Template Parameters
Tinput data type, tested with is_integral.
Parameters
inputIntegral value to print in HEX to a string.
See also
NumberStringHex::NumberStringHex(T)

◆ operator[]() [1/2]

char Burger::NumberStringHex::operator[] ( uintptr_t uIndex) const
inlinenoexcept

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::NumberStringHex::operator [](uintptr_t)

◆ operator[]() [2/2]

const char & Burger::NumberStringHex::operator[] ( uintptr_t uIndex)
inlinenoexcept

Get a character reference from the string.


Retrieve a const char reference 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::NumberStringHex::operator [](uintptr_t) const

Member Data Documentation

◆ m_Data

char Burger::NumberStringHex::m_Data[24]
private

String buffer.