Various utility functions.
|
template<class T > |
using | Common::remove_cv_t = typename remove_cv< T >::type |
|
template<class T > |
using | Common::remove_const_t = typename remove_const< T >::type |
|
template<class T > |
using | Common::remove_volatile_t = typename remove_volatile< T >::type |
|
template<class T > |
using | Common::remove_reference_t = typename remove_reference< T >::type |
|
|
template<typename T > |
T | ABS (T x) |
|
template<typename T > |
T | MIN (T a, T b) |
|
template<typename T > |
T | MAX (T a, T b) |
|
template<typename T > |
T | CLIP (T v, T amin, T amax) |
|
template<typename T > |
void | SWAP (T &a, T &b) |
|
template<typename T , size_t N> |
void | ARRAYCLEAR (T(&array) [N], const T &value=T()) |
|
template<class T > |
constexpr remove_reference_t< T > && | Common::move (T &&t) noexcept |
|
template<class T > |
constexpr T && | Common::forward (remove_reference_t< T > &&t) noexcept |
|
template<class T > |
constexpr T && | Common::forward (remove_reference_t< T > &t) noexcept |
|
void | Common::hexdump (const byte *data, int len, int bytesPerLine=16, int startOffset=0) |
|
bool | Common::parseBool (const String &val, bool &valAsBool) |
|
bool | Common::isAscii (int c) |
|
bool | Common::isAlnum (int c) |
|
bool | Common::isAlpha (int c) |
|
bool | Common::isDigit (int c) |
|
bool | Common::isXDigit (int c) |
|
bool | Common::isLower (int c) |
|
bool | Common::isSpace (int c) |
|
bool | Common::isUpper (int c) |
|
bool | Common::isPrint (int c) |
|
bool | Common::isPunct (int c) |
|
bool | Common::isCntrl (int c) |
|
bool | Common::isGraph (int c) |
|
bool | Common::isBlank (int c) |
|
Common::String | Common::getHumanReadableBytes (uint64 bytes, const char *&unitsOut) |
|
◆ IS_ALIGNED
#define IS_ALIGNED |
( |
|
value, |
|
|
|
alignment |
|
) |
| ((((size_t)value) & ((alignment) - 1)) == 0) |
Check whether a given pointer is aligned correctly. Note that 'alignment' must be a power of two!
◆ ARRAYSIZE
#define ARRAYSIZE |
( |
|
x | ) |
((int)(sizeof(x) / sizeof(x[0]))) |
Determine the number of entries in a fixed size array.
◆ ARRAYEND
Compute a pointer to one past the last element of an array.
◆ SCUMMVM_CURRENT_FUNCTION
#define SCUMMVM_CURRENT_FUNCTION "<unknown>" |
Evaluate the name of the current function on compilers supporting this.
◆ ABS()
Template method to return the absolute value of x
.
◆ MIN()
Template method to return the smallest of its parameters.
◆ MAX()
Template method to return the largest of its parameters.
◆ CLIP()
template<typename T >
T CLIP |
( |
T |
v, |
|
|
T |
amin, |
|
|
T |
amax |
|
) |
| |
|
inline |
Template method to clip the value v
so that it remains between amin
and amax
.
◆ SWAP()
template<typename T >
void SWAP |
( |
T & |
a, |
|
|
T & |
b |
|
) |
| |
|
inline |
Template method to swap the values of its two parameters.
◆ ARRAYCLEAR()
template<typename T , size_t N>
void ARRAYCLEAR |
( |
T(&) |
array[N], |
|
|
const T & |
value = T() |
|
) |
| |
|
inline |
Clear an array using the default or provided value.
◆ move()
template<class T >
constexpr remove_reference_t<T>&& Common::move |
( |
T && |
t | ) |
|
|
noexcept |
A reimplementation of std::move.
◆ hexdump()
void Common::hexdump |
( |
const byte * |
data, |
|
|
int |
len, |
|
|
int |
bytesPerLine = 16 , |
|
|
int |
startOffset = 0 |
|
) |
| |
Print a hexdump of the data passed in. The number of bytes per line is customizable.
- Parameters
-
data | The data to be dumped. |
len | Length of that data. |
bytesPerLine | Number of bytes to print per line (default: 16). |
startOffset | Shift the shown offsets by the starting offset (default: 0). |
◆ parseBool()
bool Common::parseBool |
( |
const String & |
val, |
|
|
bool & |
valAsBool |
|
) |
| |
Parse a string for a boolean value.
The strings "true", "yes", and "1" are interpreted as true. The strings "false", "no", and "0" are interpreted as false. This function ignores case.
- Parameters
-
[in] | val | The string to parse. |
[out] | valAsBool | Parsing result. |
- Returns
- True if the string has been parsed correctly, false if an error occurred.
◆ isAscii()
bool Common::isAscii |
( |
int |
c | ) |
|
Test whether the given character is in ASCII range (between 0 and 127 included).
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is ASCII, false otherwise.
◆ isAlnum()
bool Common::isAlnum |
( |
int |
c | ) |
|
Test whether the given character is alphanumeric (a-z, A-Z, 0-9).
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is alphanumeric, false otherwise.
◆ isAlpha()
bool Common::isAlpha |
( |
int |
c | ) |
|
Test whether the given character is an alphabetic letter (a-z, A-Z).
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is alphabetic, false otherwise.
◆ isDigit()
bool Common::isDigit |
( |
int |
c | ) |
|
Test whether the given character is a decimal digit (0-9).
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is a decimal digit, false otherwise.
◆ isXDigit()
bool Common::isXDigit |
( |
int |
c | ) |
|
Test whether the given character is a hexadecimal digit (0-9 or A-F).
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is a hexadecimal digit, false otherwise.
◆ isLower()
bool Common::isLower |
( |
int |
c | ) |
|
Test whether the given character is a lowercase letter (a-z).
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is a lowercase letter, false otherwise.
◆ isSpace()
bool Common::isSpace |
( |
int |
c | ) |
|
Test whether the given character is a whitespace.
The following characters are considered a whitespace:
' ', '\t', '\r', '\n', '\v', '\f'
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is a whitespace, false otherwise.
◆ isUpper()
bool Common::isUpper |
( |
int |
c | ) |
|
Test whether the given character is an uppercase letter (A-Z).
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is an uppercase letter, false otherwise.
◆ isPrint()
bool Common::isPrint |
( |
int |
c | ) |
|
Test whether the given character is printable. This includes the space character (' ').
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is printable, false otherwise.
◆ isPunct()
bool Common::isPunct |
( |
int |
c | ) |
|
Test whether the given character is a punctuation character, (i.e. not alphanumeric).
- Parameters
-
- Returns
- True if the character is punctuation, false otherwise.
◆ isCntrl()
bool Common::isCntrl |
( |
int |
c | ) |
|
Test whether the given character is a control character.
- Parameters
-
- Returns
- True if the character is a control character, false otherwise.
◆ isGraph()
bool Common::isGraph |
( |
int |
c | ) |
|
Test whether the given character has a graphical representation.
- Parameters
-
- Returns
- True if the character is a graphic, false otherwise.
◆ isBlank()
bool Common::isBlank |
( |
int |
c | ) |
|
Test whether the given character is blank.
The following characters are considered blank:
If the parameter is outside the range of a signed or unsigned char, then false is returned.
- Parameters
-
- Returns
- True if the character is blank, false otherwise.
◆ getHumanReadableBytes()
Common::String Common::getHumanReadableBytes |
( |
uint64 |
bytes, |
|
|
const char *& |
unitsOut |
|
) |
| |
Represent the size of a file in bytes as a number with floating point and largest suitable units. For example, 1474560 bytes as 1.4 MB.
- Parameters
-
[in] | bytes | Size in bytes to be represented. |
[out] | unitsOut | String with units. |
- Note
- Use
_()
to translate units correctly.
- Returns
- String with a floating point number representing the given size.