OSCR
Open Source Cartridge Reader
Loading...
Searching...
No Matches
OSCR::Util Namespace Reference

Utility methods. More...

Classes

class  bitset
class  clamped_value
 Wrapper for clamping variable values. More...
struct  is_printable< OSCR::CRC32::crc32_t >
struct  is_printable< OSCR::Storage::Path >

Typedefs

typedef uint8_t BitsetType

Functions

template<uint8_t base, typename T, if_is_integer_t< T > Enable = true, enable_if_t< 2==base, bool > IsEnabled = true>
power (T n)
template<uint8_t base, typename T, if_is_integer_t< T > Enable = true, enable_if_t< 8==base, bool > IsEnabled = true>
power (T n)
template<uint8_t base, typename T, if_is_integer_t< T > Enable = true, enable_if_t< 10==base, bool > IsEnabled = true>
power (T n)
template<uint8_t base, typename T, if_is_integer_t< T > Enable = true, enable_if_t< 16==base, bool > IsEnabled = true>
power (T n)
template<typename T, if_is_integer_t< T > Enable = true>
power (T b, T n)
bool strToInt (char const buffer[], int32_t &dest)
bool strToInt (char const buffer[], uint32_t &dest)
bool copyStr (char buffer[], size_t bufferSize, char const *str)
bool copyStrUpr (char buffer[], size_t bufferSize, char const *str)
bool copyStrLwr (char buffer[], size_t bufferSize, char const *str)
template<bool prfx = true, typename T, if_is_any_unsigned_t< T > Enable = true>
int toHex (char *buff, size_t len, T number)
bool copyStr_P (char buffer[], size_t bufferSize, char const *str)
bool copyStr_P (char buffer[], size_t bufferSize, __FlashStringHelper const *str)
bool copyStrUpr_P (char buffer[], size_t bufferSize, char const *str)
bool copyStrUpr_P (char buffer[], size_t bufferSize, __FlashStringHelper const *str)
bool copyStrLwr_P (char buffer[], size_t bufferSize, char const *str)
bool copyStrLwr_P (char buffer[], size_t bufferSize, __FlashStringHelper const *str)
bool applyTemplate_P (char buffer[], size_t bufferSize, char const *templateStr, int32_t num)
bool applyTemplate_P (char buffer[], size_t bufferSize, __FlashStringHelper const *templateStr, int32_t num)
bool applyTemplate_P (char buffer[], size_t bufferSize, char const *templateStr, uint32_t num)
bool applyTemplate_P (char buffer[], size_t bufferSize, __FlashStringHelper const *templateStr, uint32_t num)
bool applyTemplate_P (char buffer[], size_t bufferSize, char const *templateStr, char const *flashStr)
bool applyTemplate_P (char buffer[], size_t bufferSize, __FlashStringHelper const *templateStr, char const *flashStr)
bool applyTemplate_P (char buffer[], size_t bufferSize, char const *templateStr, __FlashStringHelper const *flashStr)
bool applyTemplate_P (char buffer[], size_t bufferSize, __FlashStringHelper const *templateStr, __FlashStringHelper const *flashStr)
bool applyTemplate (char buffer[], size_t bufferSize, char const *templateStr, char const *str)
bool applyTemplate (char buffer[], size_t bufferSize, __FlashStringHelper const *templateStr, char const *str)
bool isAlphaNumeric (uint8_t src)
template<typename T>
void swap (T &a, T &b)
template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout minOf (Tin a, Tin b)
template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout maxOf (Tin a, Tin b)
template<typename Tout, typename Tin1, typename Tin2, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin1 > in1Enable = true, if_is_any_number_t< Tin2 > in2Enable = true>
Tout minOf (Tin1 a, Tin2 b)
template<typename Tout, typename Tin1, typename Tin2, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin1 > in1Enable = true, if_is_any_number_t< Tin2 > in2Enable = true>
Tout maxOf (Tin1 a, Tin2 b)
template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
constexpr Tout minOf_CX (Tin a, Tin b)
template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
constexpr Tout maxOf_CX (Tin a, Tin b)
template<typename Tin, typename Tmin, typename Tmax, typename Tout = Tin, if_is_any_number_t< Tin > inEnable = true, if_is_any_number_t< Tmin > minEnable = true, if_is_any_number_t< Tmax > maxEnable = true, if_is_any_number_t< Tout > outEnable = true>
Tout clamp (Tin input, Tmin minimum, Tmax maximum)
template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout clamp (Tin input, Tout minimum, Tout maximum)
template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
constexpr Tout clamp_CX (Tin input, Tout minimum, Tout maximum)
uint8_t __getBase (char const buffer[], uint8_t &offset)
uint8_t __chrToInt (char chr)
template<bool prfx = true>
int _toHex (char *buff, size_t len, uint8_t number)

Variables

constexpr size_t const flashBufferStrSize = 100

Detailed Description

Utility methods.

Function Documentation

◆ applyTemplate()

bool OSCR::Util::applyTemplate ( char buffer[],
size_t bufferSize,
char const * templateStr,
char const * str )

Apply a template of templateStr stored in PROGMEM using parameter str to buffer with a maximum size of n.

Parameters
bufferPointer to the destination in SRAM.
bufferSizeMaximum number of characters to be copied from source (usually sizeof(buffer), must be >0).
templateStrPointer to the template in PROGMEM. Should contain s (or equivilent).
strPointer to the string parameter in SRAM.
Returns
true if buffer fit the templated string, false if it was truncated.

◆ applyTemplate_P() [1/2]

bool OSCR::Util::applyTemplate_P ( char buffer[],
size_t bufferSize,
char const * templateStr,
char const * flashStr )

Apply a template of templateStr stored in PROGMEM using parameter flashStr to buffer with a maximum size of n.

Parameters
bufferPointer to the destination in SRAM.
bufferSizeMaximum number of characters to be copied from source (usually sizeof(buffer), must be >0).
templateStrPointer to the template in PROGMEM. Should contain s (or equivilent).
flashStrPointer to the string parameter in PROGMEM. Maximum size (including the NUL terminator) is configured by flashBufferStrSize.
Returns
true if buffer fit the templated string, false if it was truncated.
See also
flashBufferStrSize

◆ applyTemplate_P() [2/2]

bool OSCR::Util::applyTemplate_P ( char buffer[],
size_t bufferSize,
char const * templateStr,
int32_t num )

Apply a template of templateStr stored in PROGMEM using parameter num to buffer with a maximum size of n.

Parameters
bufferPointer to the destination in SRAM.
bufferSizeMaximum number of characters to be copied from source (usually sizeof(buffer), must be >0).
templateStrPointer to the template in PROGMEM. Should contain d (or equivilent).
numThe integer to use.
Returns
true if buffer fit the templated string, false if it was truncated.

◆ clamp() [1/2]

template<typename Tin, typename Tmin, typename Tmax, typename Tout = Tin, if_is_any_number_t< Tin > inEnable = true, if_is_any_number_t< Tmin > minEnable = true, if_is_any_number_t< Tmax > maxEnable = true, if_is_any_number_t< Tout > outEnable = true>
Tout OSCR::Util::clamp ( Tin input,
Tmin minimum,
Tmax maximum )
inline

Clamp the input to a minimum and maximum value.

Note
For the sake of program size, cast parameter values to consistent types where possible.
Parameters
inputThe number to clamp.
minimumThe minimum value.
maximumThe maximum value.
Returns
The clamped value (Tout or same type as input type if unspecified).
Template Parameters
TinThe type of the input value.
TminThe type of the minimum value.
TmaxThe type of the maximum value.
ToutThe type of the output value (default: Tin).

◆ clamp() [2/2]

template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout OSCR::Util::clamp ( Tin input,
Tout minimum,
Tout maximum )
inline

Clamp the input to a minimum and maximum value.

Parameters
inputThe number to clamp.
minimumThe minimum value.
maximumThe maximum value.
Returns
The clamped value
Template Parameters
ToutThe type of the output, min, and max values.
TinThe type of the input value.

◆ clamp_CX()

template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout OSCR::Util::clamp_CX ( Tin input,
Tout minimum,
Tout maximum )
inlineconstexpr

constexpr implementation of clamp()

Parameters
inputThe number to clamp.
minimumThe minimum value.
maximumThe maximum value.
Returns
The clamped value
Template Parameters
ToutThe type of the output, min, and max values.
TinThe type of the input value.

◆ copyStr_P()

bool OSCR::Util::copyStr_P ( char buffer[],
size_t bufferSize,
char const * str )

Copy a string of a specific length from PROGMEM to SRAM.

Parameters
bufferPointer to the destination in SRAM.
strPointer to the source in PROGMEM.
strSizeMaximum number of characters to be copied from source (usually sizeof(buffer), must be >0).
Returns
true if str was copied in its entirety, false if it was truncated.

◆ maxOf() [1/2]

template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout OSCR::Util::maxOf ( Tin a,
Tin b )
inline

Return the larger of two values.

Parameters
aThe first value.
bThe second value.
Note
If the output is unsigned and the inputs are signed, negative numbers will be set to zero before being compared
Template Parameters
ToutThe type of the output value.
TinThe type of the input values.
See also
maxOf_CX

◆ maxOf() [2/2]

template<typename Tout, typename Tin1, typename Tin2, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin1 > in1Enable = true, if_is_any_number_t< Tin2 > in2Enable = true>
Tout OSCR::Util::maxOf ( Tin1 a,
Tin2 b )
inline

Return the larger of two values of different signedness.

Parameters
aThe first value.
bThe second value.
Template Parameters
ToutThe type of the output value.
Tin1The type of the first value.
Tin2The type of the second value.

◆ maxOf_CX()

template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout OSCR::Util::maxOf_CX ( Tin a,
Tin b )
inlineconstexpr

constexpr implementation of maxOf().

Parameters
aThe first value.
bThe second value.
Template Parameters
ToutThe type of the output value.
TinThe type of the input values.
See also
maxOf()

◆ minOf() [1/2]

template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout OSCR::Util::minOf ( Tin a,
Tin b )
inline

Return the smaller of two values.

Parameters
aThe first value.
bThe second value.
Note
If the output is unsigned and the inputs are signed, negative numbers will be set to zero before being compared
Template Parameters
ToutThe type of the output value.
TinThe type of the input values.
See also
minOf_CX()

◆ minOf() [2/2]

template<typename Tout, typename Tin1, typename Tin2, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin1 > in1Enable = true, if_is_any_number_t< Tin2 > in2Enable = true>
Tout OSCR::Util::minOf ( Tin1 a,
Tin2 b )
inline

Return the smaller of two values of different signedness.

Parameters
aThe first value.
bThe second value.
Template Parameters
ToutThe type of the output value.
Tin1The type of the first value.
Tin2The type of the second value.

◆ minOf_CX()

template<typename Tout, typename Tin, if_is_any_number_t< Tout > outEnable = true, if_is_any_number_t< Tin > inEnable = true>
Tout OSCR::Util::minOf_CX ( Tin a,
Tin b )
inlineconstexpr

constexpr implementation of minOf().

Parameters
aThe first value.
bThe second value.
Template Parameters
ToutThe type of the output value.
TinThe type of the input values.
See also
minOf()

◆ strToInt() [1/2]

bool OSCR::Util::strToInt ( char const buffer[],
int32_t & dest )

Convert a string representation to an integer.

Parameters
bufferThe array of characters (string).
destThe destination.
Returns
true on success, false on failure.
Note
Supports decimal, hexidecimal (0x...), and octal (0...), as well as ignores whitespace and commas, even in the middle of the number. When the number is negative, the first character must be a minus (-) symbol.

◆ strToInt() [2/2]

bool OSCR::Util::strToInt ( char const buffer[],
uint32_t & dest )

Convert a string representation to an unsigned integer.

Parameters
bufferThe array of characters (string).
destThe destination.
Returns
true on success, false on failure.
Note
Supports decimal, hexidecimal (0x...), and octal (0...), as well as ignores whitespace and commas, even in the middle of the number.

◆ swap()

template<typename T>
void OSCR::Util::swap ( T & a,
T & b )
extern

Perform an in-place swap of two variables of the same type.

Parameters
aThe first variable.
bThe second variable.
Template Parameters
TThe type of two variables.

Variable Documentation

◆ flashBufferStrSize

size_t const OSCR::Util::flashBufferStrSize = 100
constexpr

Maximum size of the internal buffer used by functions which copy strings from flash.