GlobalObjects
|
A UnsignedMagicNumber is an artificial number consisting of numbers and letters (similar to hex numbers). More...
#include <EuUnsignedMagicNumber.h>
Public Member Functions | |
UnsignedMagicNumber () | |
UnsignedMagicNumber (const UnsignedMagicNumber &rT) | |
UnsignedMagicNumber (unsigned int uiMaxSize) | |
UnsignedMagicNumber (unsigned int uiMaxSize, char chFirstRangeDigit, char chLastRangeDigit) | |
UnsignedMagicNumber (unsigned int uiMaxSize, char chFirstRangeDigit, char chLastRangeDigit, const char *pchValue) | |
UnsignedMagicNumber (unsigned int uiMaxSize, char chFirstRangeDigit, char chLastRangeDigit, const std::string &rsValue) | |
UnsignedMagicNumber (unsigned int uiMaxSize, char chLastRangeDigit) | |
UnsignedMagicNumber (unsigned int uiMaxSize, char chLastRangeDigit, const char *pchValue) | |
UnsignedMagicNumber (unsigned int uiMaxSize, char chLastRangeDigit, const std::string &rsValue) | |
UnsignedMagicNumber (unsigned int uiMaxSize, const char *pchValue) | |
UnsignedMagicNumber (unsigned int uiMaxSize, const std::string &rsValue) | |
virtual | ~UnsignedMagicNumber () |
char | getFirstRangeDigit () const |
int | getLastError () |
char | getLastRangeDigit () const |
unsigned int | getMaxSize () const |
bool | isAsciiInRange (const char chCharacter) const |
bool | isNULL () const |
UnsignedMagicNumber & | operator= (const UnsignedMagicNumber &rT) |
void | setNULL () |
int | setValue (const char *pchValue) |
std::string | toString () const |
bool | operator== (const UnsignedMagicNumber &rT) const |
Comparison operator. | |
bool | operator!= (const UnsignedMagicNumber &rT) const |
Comparison operator. | |
bool | operator> (const UnsignedMagicNumber &rT) const |
Comparison operator for size comparison. | |
bool | operator>= (const UnsignedMagicNumber &rT) const |
Comparison operator for size comparison. | |
bool | operator< (const UnsignedMagicNumber &rT) const |
Comparison operator for size comparison. | |
bool | operator<= (const UnsignedMagicNumber &rT) const |
Comparison operator for size comparison. | |
UnsignedMagicNumber & | operator++ () |
Computational operators. | |
UnsignedMagicNumber | operator++ (int) |
Computational operators. | |
UnsignedMagicNumber & | operator+= (const UnsignedMagicNumber &rrT) |
Computational operators. | |
UnsignedMagicNumber & | operator-- () |
Computational operators. | |
UnsignedMagicNumber | operator-- (int) |
Computational operators. | |
UnsignedMagicNumber & | operator-= (const UnsignedMagicNumber &rrT) |
Computational operators. | |
Private Types | |
enum | EnCalcType { eADD , eSUBTRACT } |
Private Member Functions | |
bool | addChar (char &rchTarget, const char chSource, char chLastRangeDigit) |
int | addValue (char *pchTarget, const char *pchSource, unsigned int uiMaxSize, char chFirstRangeDigit, char chLastRangeDigit) |
int | calculateValue (char *pchTarget, const char *pchSource, unsigned int uiMaxSize, char chFirstRangeDigit, char chLastRangeDigit, EnCalcType eCalcType) |
bool | checkFirstLast (char chFirstRangeDigit, char chLastRangeDigit) |
void | convertAsciiCharArrayInOwn (char *pchChar) const |
void | convertAsciiCharInOwn (char &rchChar) const |
void | convertOwnCharArrayInAscii (char *pchChar) const |
void | convertOwnCharInAscii (char &rchChar) const |
char | getAsciiCharInOwn (const char &rchChar) const |
char | getOwnCharInAscii (const char &rchChar) const |
void | init (char chFirstRangeDigit, char chLastRangeDigit) |
bool | isInRange (const char chCharacter) const |
bool | subtractChar (char &rchTarget, const char chSource, char chLastRangeDigit) |
int | subtractValue (char *pchTarget, const char *pchSource, unsigned int uiMaxSize, char chFirstRangeDigit, char chLastRangeDigit) |
Private Attributes | |
char | m_chFirstRangeDigit |
char | m_chLastRangeDigit |
int | m_iLastError |
char * | m_pchValue |
unsigned int | m_uiMaxSize |
Friends | |
UnsignedMagicNumber | operator+ (UnsignedMagicNumber lT, const UnsignedMagicNumber &rrT) |
UnsignedMagicNumber | operator- (UnsignedMagicNumber lT, const UnsignedMagicNumber &rrT) |
std::ostream & | operator<< (std::ostream &rOStream, const UnsignedMagicNumber &rMagicNumber) |
std::istream & | operator>> (std::istream &rIStream, UnsignedMagicNumber &rMagicNumber) |
A UnsignedMagicNumber is an artificial number consisting of numbers and letters (similar to hex numbers).
A maximum value of 0-9, A-Z and a-z can be assigned to this number per digit, which means a maximum of 10 + 26 + 26 states per digit. This makes 62^10 -> 839,299,365,868,340,000 for a 10-digit value. In the standard setting (0-Z), this would be 31^10 -> 3,656,158,440,062,980.
This number is used accordingly; it is counted from 0 to z (i.e. from 0 to 9 and after 9 comes A to z -> e.g. 12 + A = 1C ).
This was born from the idea that I used an unsigned long as index and the range seemed too small to me. The unsigned long reaches to 4,294,967,295, but I did not want to change the length of the index. The first idea was to extend the number range to 9,999,999,999, but there are still the letters similar to the hex numbers. An additional requirement is that all numbers are printable and can be used as letters for file names.
The length of the UnsignedMagicNumber and the value range can be determined. E.g. length 10 and value range from 0 to Z (inclusive).
But the most important thing is that this UnsignedMagicNumber can be added and subtracted, e.g. to get a unique index by decrementing.
A side effect is that with the m_chFirstRangeDigit == '0' and the m_chLastRangeDigit == 'F' a hexadecimal representation with simple calculation is possible.
|
private |
For UnsignedMagicNumber::calculateValue (...)
Enumerator | |
---|---|
eADD | It should be added. |
eSUBTRACT | It should be subtracted. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | ) |
The standard constructor is not available.
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize | ) |
Constructor with length of the value.
[in] | uiMaxSize | The maximum length of the value. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
const char * | pchValue ) |
Constructor with length of the value and the value itself.
[in] | uiMaxSize | The maximum length of the value. |
[in] | pchValue | The value as a 0-terminated char array. The length of the value must not be greater than passed with uiMaxSize and all characters must be in the range of the start and end value. |
eut::ErrorNException | An exception will be thrown if uiMaxSize == 0. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
const std::string & | rsValue ) |
Constructor with length of the value and the value itself.
[in] | uiMaxSize | The maximum length of the value. |
[in] | rsValue | The value as a std::string. The length of the value must not be greater than passed with uiMaxSize and all characters must be in the range of the start and end value. |
eut::ErrorNException | An exception will be thrown if uiMaxSize == 0. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
char | chLastRangeDigit ) |
Constructor with length of the value and the last range value.
[in] | uiMaxSize | The maximum length of the value. |
[in] | chLastRangeDigit | The largest allowed value, i.e. the final value. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0 or chLastRangeDigit is not in the ranges '0' - '9', 'A' - 'Z' and 'a' - 'z'. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
char | chLastRangeDigit, | ||
const char * | pchValue ) |
Constructor with length of the value, the last range value and the value itself.
[in] | uiMaxSize | The maximum length of the value. |
[in] | chLastRangeDigit | The largest allowed value, i.e. the final value. |
[in] | pchValue | The value as a 0-terminated char array. The length of the value must not be greater than specified in uiMaxSize and all characters must be in the range of '0' and chLastRangeDigit. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0 or chLastRangeDigit is not in the ranges '0' - '9', 'A' - 'Z' and 'a' - 'z'. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
char | chLastRangeDigit, | ||
const std::string & | rsValue ) |
Constructor with length of the value, the last range value and the value itself.
[in] | uiMaxSize | The maximum length of the value. |
[in] | chLastRangeDigit | The largest allowed value, i.e. the final value. |
[in] | rsValue | The value as a std::string. The length of the value must not be greater than specified in uiMaxSize and all characters must be in the range of '0' and chLastRangeDigit. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0 or chLastRangeDigit is not in the ranges '0' - '9', 'A' - 'Z' and 'a' - 'z'. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
char | chFirstRangeDigit, | ||
char | chLastRangeDigit ) |
Constructor with length of the value and the range values.
[in] | uiMaxSize | The maximum length of the value. |
[in] | chFirstRangeDigit | The smallest allowed value, i.e. the start value. |
[in] | chLastRangeDigit | The largest permitted value, i.e. the end value. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0 or chLastRangeDigit is not in the ranges '0' - '9', 'A' - 'Z' and 'a' - 'z'. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
char | chFirstRangeDigit, | ||
char | chLastRangeDigit, | ||
const char * | pchValue ) |
Constructor with the length of the value, the range values and the value itself.
[in] | uiMaxSize | The maximum length of the value. |
[in] | chFirstRangeDigit | The smallest allowed value, i.e. the start value. |
[in] | chLastRangeDigit | The largest permitted value, i.e. the end value. |
[in] | pchValue | The value as a 0-terminated char array. The length of the value must not be greater than specified in uiMaxSize and all characters must be within the range of chFirstRangeDigit and chLastRangeDigit. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0 or chLastRangeDigit is not in the ranges '0' - '9', 'A' - 'Z' and 'a' - 'z'. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | unsigned int | uiMaxSize, |
char | chFirstRangeDigit, | ||
char | chLastRangeDigit, | ||
const std::string & | rsValue ) |
Constructor with the length of the value, the range values and the value itself.
[in] | uiMaxSize | The maximum length of the value. |
[in] | chFirstRangeDigit | The smallest allowed value, i.e. the start value. |
[in] | chLastRangeDigit | The largest permitted value, i.e. the end value. |
[in] | rsValue | The value as a std::string. The length of the value must not be greater than specified in uiMaxSize and all characters must be within the range of chFirstRangeDigit and chLastRangeDigit. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0 or chLastRangeDigit is not in the ranges '0' - '9', 'A' - 'Z' and 'a' - 'z'. |
eut::UnsignedMagicNumber::UnsignedMagicNumber | ( | const UnsignedMagicNumber & | rT | ) |
Copy constructor.
[in] | rT | The data is copied from this object. |
|
virtual |
Destrctor.
|
private |
Adds second to the first transferred char.
[in,out] | rchTarget | The char to which to add up. |
[in] | chSource | The char to be summed up to chTarget. |
[in] | chLastRangeDigit | The largest allowed value. |
|
private |
Adds a second char array to the first char array passed. This method is only called by operators, so there is no need to check here.
[in,out] | pchTarget | The value to be added to (0-terminated char array of own characters). The length of the value is defined in uiMaxSize and all characters must be in the range of chFirstRangeDigit and chLastRangeDigit. |
[in] | pchSource | The value to be summed up on pchTarget (0-terminated char array of own characters). The length of the value is defined in uiMaxSize and all characters must be in the range of chFirstRangeDigit and chLastRangeDigit. |
[in] | uiMaxSize | The maximum length of the passed char arrays. |
[in] | chFirstRangeDigit | The first allowed value of each char in the char arrays. |
[in] | chLastRangeDigit | The last allowed value of each char in the char-arrays. |
|
private |
Adds the second passed Char-Array to the first passed Char-Array or subtracts the second passed Char-Array from the first passed Char-Array. Is used by addValue (...) and subtractValue (...).
[in,out] | pchTarget | The value to be processed (0-terminated Char-Array of own characters). The length of the value is defined in uiMaxSize and all characters must be in the range of chFirstRangeDigit and chLastRangeDigit. |
[in] | pchSource | The value to be calculated with rchTarget (0-terminated char array of own characters). The length of the value is defined in uiMaxSize and all characters must be in the range of chFirstRangeDigit and chLastRangeDigit. |
[in] | uiMaxSize | The maximum length of the passed char arrays. |
[in] | chFirstRangeDigit | The first allowed value of each char in the char arrays. |
[in] | chLastRangeDigit | The last allowed value of each char in the char-arrays. |
[in] | eCalcType | Should be added or subtracted. |
|
private |
Checks if the passed Range is within the allowed range.
[in] | chFirstRangeDigit | The smallest value. |
[in] | chLastRangeDigit | The largest value. |
|
private |
Changes the ASCII characters in the passed ASCII char array to the corresponding custom chars.
[in] | pchChar | The ASCII char array whose contents are to be converted into custom chars. |
eut::ErrorNException | An exception is thrown if the characters in pchChar are not in the ranges '0' - '9', 'A' - 'Z' or 'a' - 'z'. |
|
private |
Converts the transferred char into its own char.
[in] | rchChar | The ASCII char to be converted into your own char. |
eut::ErrorNException | An exception is thrown if rchChar is not in the ranges '0' - '9', 'A' - 'Z' or 'a' - 'z'. |
|
private |
Changes the own characters in the passed char array to the corresponding ASCII char.
[in] | pchChar | The char array with its own characters, whose content is to be converted to ASCII char. |
eut::ErrorNException | An exception is thrown if the characters in pchChar are not in the ranges '0' - '9', 'A' - 'Z' or 'a' - 'z'. |
|
private |
Changes the transferred custom char to the corresponding ASCII char.
[in] | rchChar | The own char to be converted into an ASCII char. |
eut::ErrorNExceptioneut::ErrorNException | An exception is thrown if rchChar is not in the ranges '0' - '9', 'A' - 'Z' or 'a' - 'z'. |
|
private |
Returns the own char, which corresponds to the ASCII char.
[in] | rchChar | The ASCII char to be converted into a custom char. |
eut::ErrorNException | An exception is thrown if rchChar is not in the ranges '0' - '9', 'A' - 'Z' or 'a' - 'z'. |
char eut::UnsignedMagicNumber::getFirstRangeDigit | ( | ) | const |
Returns the smallest valid ASCII character.
int eut::UnsignedMagicNumber::getLastError | ( | ) |
Returns the last error that occurred.
char eut::UnsignedMagicNumber::getLastRangeDigit | ( | ) | const |
Returns the largest valid ASCII character.
unsigned int eut::UnsignedMagicNumber::getMaxSize | ( | ) | const |
Returns the maximum length of the value.
|
private |
Returns the ASCII char which corresponds to the own char.
[in] | rchChar | The own char which should be converted into an ASCII char. |
eut::ErrorNExceptioneut::ErrorNException | An exception is thrown if rchChar is not in the ranges '0' - '9', 'A' - 'Z' or 'a' - 'z'. |
|
private |
Initializes and checks its values.
[in] | chFirstRangeDigit | The smallest allowed value, i.e. the start value. |
[in] | chLastRangeDigit | The largest permitted value, i.e. the end value. |
eut::ErrorNException | An exception is thrown if uiMaxSize == 0 or chFirstRangeDigit and chLastRangeDigit are not in the ranges '0' - '9', 'A' - 'Z' and 'a' - 'z'. |
bool eut::UnsignedMagicNumber::isAsciiInRange | ( | const char | chCharacter | ) | const |
Checks if the passed ASCII character is in the range of m_chFirstRangeDigit and m_chLastRangeDigit
[in] | chCharacter | The ASCII character to check. |
|
private |
Checks if the passed character is in the specified range of m_chFirstRangeDigit and m_chLastRangeDigit
[in] | chCharacter | The character to check. |
bool eut::UnsignedMagicNumber::isNULL | ( | ) | const |
Checks if the smallest value (the value from m_chFirstRangeDigit) is seted.
bool eut::UnsignedMagicNumber::operator!= | ( | const UnsignedMagicNumber & | rT | ) | const |
Comparison operator.
UnsignedMagicNumber & eut::UnsignedMagicNumber::operator++ | ( | ) |
Computational operators.
If another UnsignedMagicNumber is involved, it is checked if both EuUnsignedMagicNumbers have the same settings.
UnsignedMagicNumber eut::UnsignedMagicNumber::operator++ | ( | int | ) |
Computational operators.
If another UnsignedMagicNumber is involved, it is checked if both EuUnsignedMagicNumbers have the same settings.
UnsignedMagicNumber & eut::UnsignedMagicNumber::operator+= | ( | const UnsignedMagicNumber & | rrT | ) |
Computational operators.
If another UnsignedMagicNumber is involved, it is checked if both EuUnsignedMagicNumbers have the same settings.
UnsignedMagicNumber & eut::UnsignedMagicNumber::operator-- | ( | ) |
Computational operators.
If another UnsignedMagicNumber is involved, it is checked if both EuUnsignedMagicNumbers have the same settings.
UnsignedMagicNumber eut::UnsignedMagicNumber::operator-- | ( | int | ) |
Computational operators.
If another UnsignedMagicNumber is involved, it is checked if both EuUnsignedMagicNumbers have the same settings.
UnsignedMagicNumber & eut::UnsignedMagicNumber::operator-= | ( | const UnsignedMagicNumber & | rrT | ) |
Computational operators.
If another UnsignedMagicNumber is involved, it is checked if both EuUnsignedMagicNumbers have the same settings.
bool eut::UnsignedMagicNumber::operator< | ( | const UnsignedMagicNumber & | rT | ) | const |
Comparison operator for size comparison.
bool eut::UnsignedMagicNumber::operator<= | ( | const UnsignedMagicNumber & | rT | ) | const |
Comparison operator for size comparison.
UnsignedMagicNumber & eut::UnsignedMagicNumber::operator= | ( | const UnsignedMagicNumber & | rT | ) |
Assignment operator, all attributes are considered.
bool eut::UnsignedMagicNumber::operator== | ( | const UnsignedMagicNumber & | rT | ) | const |
Comparison operator.
bool eut::UnsignedMagicNumber::operator> | ( | const UnsignedMagicNumber & | rT | ) | const |
Comparison operator for size comparison.
bool eut::UnsignedMagicNumber::operator>= | ( | const UnsignedMagicNumber & | rT | ) | const |
Comparison operator for size comparison.
void eut::UnsignedMagicNumber::setNULL | ( | ) |
Sets m_pchValue to the smallest value (m_chFirstRangeDigit)
int eut::UnsignedMagicNumber::setValue | ( | const char * | pchValue | ) |
Sets its own value.
[in] | pchValue | The value as 0-terminated ASCII char array. The length of the value must not be greater than specified in m_uiMaxSize and all characters must be within the range of m_chFirstRangeDigit and m_chLastRangeDigit. |
|
private |
Subtracts the second char from the first one transferred.
[in,out] | rchTarget | The char from which to subtract |
[in] | chSource | The char to be subtracted from chTarget. |
[in] | chLastRangeDigit | The last allowed value. |
|
private |
Subtracts the second passed Char-Array from the first passed Char-Array. This method is only called by operators, so there is no need to perform checks here.
[in,out] | pchTarget | The value to subtract from (0-terminated char array of own characters). The length of the value is defined in uiMaxSize and all characters must be in the range of chFirstRangeDigit and chLastRangeDigit. |
[in] | pchSource | The value to be subtracted from pchTarget (0-terminated char array of own characters). The length of the value is defined in uiMaxSize and all characters must be in the range of chFirstRangeDigit and chLastRangeDigit. |
[in] | uiMaxSize | The maximum length of the passed char arrays. |
[in] | chFirstRangeDigit | The first allowed value of each char in the char arrays. |
[in] | chLastRangeDigit | The last allowed value of each char in the char-arrays. |
std::string eut::UnsignedMagicNumber::toString | ( | ) | const |
Returns its value as std::string.
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
The start value, default is '0'.
|
private |
The final value, default setting is 'Z'.
|
private |
Last error.
|
private |
The value of MagicNumber.
|
private |
The maximum length (number of characters) of m_pchValue (default is 10).