Uniot Core
0.8.1
Loading...
Searching...
No Matches
Common

Common utilities and macros for the Uniot Core. More...

Collaboration diagram for Common:

Classes

struct  FourCC< a, b, c, d >
 Creates a four-character code (FourCC) value from template parameters. More...
 

Macros

#define COUNT_OF(arr)
 Calculates the number of elements in a statically allocated array.
 
#define ARRAY_ELEMENT_SAFE(arr, index)
 Provides safe array access with bounds checking.
 
#define FOURCC(name)
 Creates a FourCC constant from a string literal.
 
#define ALIAS_IMPLICIT_FUNCTION(high, low)
 Creates an alias for a function that forwards all arguments implicitly.
 
#define ALIAS_EXPLICIT_FUNCTION(high, low)
 Creates an alias for a template function that forwards all arguments explicitly.
 

Functions

template<typename... Args>
void UNUSED (Args &&...args)
 Utility function to mark function parameters as intentionally unused.
 
uint32_t CRC32 (const void *data, size_t length, uint32_t crc=0)
 Calculates CRC32-C (Castagnoli) checksum for data integrity verification.
 
template<typename T>
using uniot::UniquePointer = std::unique_ptr<T>
 Type alias for std::unique_ptr with cleaner syntax.
 
template<typename T>
using uniot::SharedPointer = std::shared_ptr<T>
 Type alias for std::shared_ptr with cleaner syntax.
 
template<typename T_First, typename T_Second>
using uniot::Pair = std::pair<T_First, T_Second>
 Type alias for std::pair with cleaner syntax.
 
template<typename T, typename... Args>
auto uniot::MakeShared (Args &&...args) -> decltype(std::make_shared< T >(std::forward< Args >(args)...))
 Creates a shared pointer instance, alias for std::make_shared.
 
template<typename T, typename... Args>
auto uniot::MakeUnique (Args &&...args) -> decltype(std::make_unique< T >(std::forward< Args >(args)...))
 Creates a unique pointer instance, alias for std::make_unique.
 
template<typename... Args>
auto uniot::MakePair (Args &&...args) -> decltype(std::make_pair(std::forward< Args >(args)...))
 Creates a pair instance, alias for std::make_pair.
 

Detailed Description

Common utilities and macros for the Uniot Core.

Macro Definition Documentation

◆ ALIAS_EXPLICIT_FUNCTION

#define ALIAS_EXPLICIT_FUNCTION ( high,
low )
Value:
template <typename T, typename... Args> \
inline auto high(Args &&...args) -> decltype(low<T>(std::forward<Args>(args)...)) { \
return low<T>(std::forward<Args>(args)...); \
}

Creates an alias for a template function that forwards all arguments explicitly.

Similar to ALIAS_IMPLICIT_FUNCTION but maintains the explicit template parameter.

Parameters
highNew function name
lowOriginal function being aliased

◆ ALIAS_IMPLICIT_FUNCTION

#define ALIAS_IMPLICIT_FUNCTION ( high,
low )
Value:
template <typename... Args> \
inline auto high(Args &&...args) -> decltype(low(std::forward<Args>(args)...)) { \
return low(std::forward<Args>(args)...); \
}

Creates an alias for a function that forwards all arguments implicitly.

Used to expose standard library functions through a custom namespace with the same parameter forwarding behavior.

Parameters
highNew function name
lowOriginal function being aliased

◆ ARRAY_ELEMENT_SAFE

#define ARRAY_ELEMENT_SAFE ( arr,
index )
Value:
((arr)[(((index) < COUNT_OF(arr)) ? (index) : (COUNT_OF(arr) - 1))])
#define COUNT_OF(arr)
Calculates the number of elements in a statically allocated array.
Definition Common.h:88

Provides safe array access with bounds checking.

Returns the element at the specified index if within bounds, otherwise returns the last element.

◆ COUNT_OF

#define COUNT_OF ( arr)
Value:
(sizeof(arr) / sizeof(arr[0]))

Calculates the number of elements in a statically allocated array.

◆ FOURCC

#define FOURCC ( name)
Value:
FourCC<ARRAY_ELEMENT_SAFE(#name, 0), ARRAY_ELEMENT_SAFE(#name, 1), ARRAY_ELEMENT_SAFE(#name, 2), ARRAY_ELEMENT_SAFE(#name, 3)>::Value
#define ARRAY_ELEMENT_SAFE(arr, index)
Provides safe array access with bounds checking.
Definition Common.h:97
Creates a four-character code (FourCC) value from template parameters.
Definition Common.h:43

Creates a FourCC constant from a string literal.

Uses up to the first four characters of the string to create a unique identifier. If the string has fewer than 4 characters, the remaining positions will be filled with the last character.

Typedef Documentation

◆ Pair

template<typename T_First, typename T_Second>
using uniot::Pair = std::pair<T_First, T_Second>

Type alias for std::pair with cleaner syntax.

Template Parameters
T_FirstType of the first element
T_SecondType of the second element

◆ SharedPointer

template<typename T>
using uniot::SharedPointer = std::shared_ptr<T>

Type alias for std::shared_ptr with cleaner syntax.

Template Parameters
TType of the managed object

◆ UniquePointer

template<typename T>
using uniot::UniquePointer = std::unique_ptr<T>

Type alias for std::unique_ptr with cleaner syntax.

Template Parameters
TType of the managed object

Function Documentation

◆ CRC32()

uint32_t CRC32 ( const void * data,
size_t length,
uint32_t crc = 0 )
inline

Calculates CRC32-C (Castagnoli) checksum for data integrity verification.

This function implements the CRC-32C polynomial used in iSCSI standard.

Parameters
dataPointer to data buffer
lengthSize of data buffer in bytes
crcInitial CRC value (defaults to 0)
Return values
uint32_tCRC32 checksum value

◆ MakePair()

template<typename... Args>
auto uniot::MakePair ( Args &&... args) -> decltype(std::make_pair(std::forward<Args>(args)...))
inline

Creates a pair instance, alias for std::make_pair.

◆ MakeShared()

template<typename T, typename... Args>
auto uniot::MakeShared ( Args &&... args) -> decltype(std::make_shared<T>(std::forward<Args>(args)...))
inline

Creates a shared pointer instance, alias for std::make_shared.

◆ MakeUnique()

template<typename T, typename... Args>
auto uniot::MakeUnique ( Args &&... args) -> decltype(std::make_unique<T>(std::forward<Args>(args)...))
inline

Creates a unique pointer instance, alias for std::make_unique.

◆ UNUSED()

template<typename... Args>
void UNUSED ( Args &&... args)
inline

Utility function to mark function parameters as intentionally unused.

Prevents compiler warnings about unused parameters by explicitly consuming them.

Template Parameters
ArgsVariadic template parameter types
Parameters
argsParameters to mark as used