OpenBarnyard
 
Loading...
Searching...
No Matches
Helpers.h File Reference
#include "Math/TMathInline.h"
#include <limits>

Go to the source code of this file.

Functions

template<typename T>
TFORCEINLINE void TSwapValues (T &a, T &b)
 
TFORCEINLINE constexpr TUINT32 TFourCC (const TCHAR str[4])
 
TFORCEINLINE TUINT32 TFourCCLE (const TCHAR str[4])
 
TFORCEINLINE TUINT32 TFourCCBE (const TCHAR str[4])
 
TFORCEINLINE TBOOL TIsPointerAligned (const void *a_pPointer, TSIZE a_uiAlignment=sizeof(void *))
 
template<class T>
TFORCEINLINE constexpr T * TAlignPointerUp (T *a_pMem, TSIZE a_uiAlignment=sizeof(T *))
 
template<class T>
TFORCEINLINE constexpr T * TAlignPointerDown (T *a_pMem, TSIZE a_uiAlignment=sizeof(T *))
 
template<class T>
TFORCEINLINE constexpr T TAlignNumDown (T a_iValue, TSIZE a_uiAlignment=4)
 
template<class T>
TFORCEINLINE constexpr T TAlignNumUp (T a_iValue, TSIZE a_uiAlignment=4)
 

Function Documentation

◆ TAlignNumDown()

template<class T>
TFORCEINLINE constexpr T TAlignNumDown ( T a_iValue,
TSIZE a_uiAlignment = 4 )
constexpr

Definition at line 59 of file Helpers.h.

60{
61 TSTATICASSERT( std::is_arithmetic<T>::value );
62 return a_iValue & (T)( ~( a_uiAlignment - 1U ) );
63}
#define TSTATICASSERT(...)
Definition Defines.h:67

◆ TAlignNumUp()

template<class T>
TFORCEINLINE constexpr T TAlignNumUp ( T a_iValue,
TSIZE a_uiAlignment = 4 )
constexpr

Definition at line 66 of file Helpers.h.

67{
68 TSTATICASSERT( std::is_arithmetic<T>::value );
69 return ( a_iValue + ( a_uiAlignment - 1U ) ) & (T)( ~( a_uiAlignment - 1U ) );
70}

◆ TAlignPointerDown()

template<class T>
TFORCEINLINE constexpr T * TAlignPointerDown ( T * a_pMem,
TSIZE a_uiAlignment = sizeof( T* ) )
constexpr

Definition at line 50 of file Helpers.h.

51{
52 return TREINTERPRETCAST(
53 T*,
54 ( TUINTPTR( a_pMem ) ) & ( ~( a_uiAlignment - 1U ) )
55 );
56}
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68
uintptr_t TUINTPTR
Definition Typedefs.h:18

◆ TAlignPointerUp()

template<class T>
TFORCEINLINE constexpr T * TAlignPointerUp ( T * a_pMem,
TSIZE a_uiAlignment = sizeof( T* ) )
constexpr

Definition at line 41 of file Helpers.h.

42{
43 return TREINTERPRETCAST(
44 T*,
45 ( TUINTPTR( a_pMem ) + ( a_uiAlignment - 1 ) ) & ( ~( a_uiAlignment - 1U ) )
46 );
47}

◆ TFourCC()

TFORCEINLINE constexpr TUINT32 TFourCC ( const TCHAR str[4])
constexpr

Definition at line 15 of file Helpers.h.

16{
17 return ( ( str[ 3 ] << 24 ) | ( str[ 2 ] << 16 ) | ( str[ 1 ] << 8 ) | str[ 0 ] );
18}

◆ TFourCCBE()

TFORCEINLINE TUINT32 TFourCCBE ( const TCHAR str[4])

Definition at line 27 of file Helpers.h.

28{
29 return PARSEDWORD_BIG( TFourCC( str ) );
30}
TFORCEINLINE constexpr TUINT32 TFourCC(const TCHAR str[4])
Definition Helpers.h:15

◆ TFourCCLE()

TFORCEINLINE TUINT32 TFourCCLE ( const TCHAR str[4])

Definition at line 21 of file Helpers.h.

22{
23 return PARSEDWORD( TFourCC( str ) );
24}

◆ TIsPointerAligned()

TFORCEINLINE TBOOL TIsPointerAligned ( const void * a_pPointer,
TSIZE a_uiAlignment = sizeof( void* ) )

Definition at line 35 of file Helpers.h.

36{
37 return 0 == ( TUINTPTR( a_pPointer ) % a_uiAlignment );
38}

◆ TSwapValues()

template<typename T>
TFORCEINLINE void TSwapValues ( T & a,
T & b )

Definition at line 7 of file Helpers.h.

8{
9 T temp = std::move( a );
10 a = std::move( b );
11 b = std::move( temp );
12}