ObjFW
Loading...
Searching...
No Matches
Macros | Functions
macros.h File Reference
#include "objfw-defs.h"
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "platform.h"

Go to the source code of this file.

Macros

#define OFByteSwap16(i)    (__builtin_constant_p(i) ? _OFByteSwap16Const(i) : _OFByteSwap16NonConst(i))
 Byte swaps the specified 16 bit integer.
 
#define OFByteSwap32(i)    (__builtin_constant_p(i) ? _OFByteSwap32Const(i) : _OFByteSwap32NonConst(i))
 Byte swaps the specified 32 bit integer.
 
#define OFByteSwap64(i)    (__builtin_constant_p(i) ? _OFByteSwap64Const(i) : _OFByteSwap64NonConst(i))
 Byte swaps the specified 64 bit integer.
 
#define OFFromBigEndian16(i)   (i)
 Converts the specified 16 bit integer from big endian to native endian.
 
#define OFFromBigEndian32(i)   (i)
 Converts the specified 32 bit integer from big endian to native endian.
 
#define OFFromBigEndian64(i)   (i)
 Converts the specified 64 bit integer from big endian to native endian.
 
#define OFFromLittleEndian16(i)   OFByteSwap16(i)
 Converts the specified 16 bit integer from little endian to native endian.
 
#define OFFromLittleEndian32(i)   OFByteSwap32(i)
 Converts the specified 32 bit integer from little endian to native endian.
 
#define OFFromLittleEndian64(i)   OFByteSwap64(i)
 Converts the specified 64 bit integer from little endian to native endian.
 
#define OFToBigEndian16(i)   (i)
 Converts the specified 16 bit integer from native endian to big endian.
 
#define OFToBigEndian32(i)   (i)
 Converts the specified 32 bit integer from native endian to big endian.
 
#define OFToBigEndian64(i)   (i)
 Converts the specified 64 bit integer from native endian to big endian.
 
#define OFToLittleEndian16(i)   OFByteSwap16(i)
 Converts the specified 16 bit integer from native endian to little endian.
 
#define OFToLittleEndian32(i)   OFByteSwap32(i)
 Converts the specified 32 bit integer from native endian to little endian.
 
#define OFToLittleEndian64(i)   OFByteSwap64(i)
 Converts the specified 64 bit integer from native endian to little endian.
 
#define OFFromBigEndianFloat(f)   (f)
 Converts the specified float from big endian to native endian.
 
#define OFFromBigEndianDouble(d)   (d)
 Converts the specified double from big endian to native endian.
 
#define OFFromLittleEndianFloat(f)   OFByteSwapFloat(f)
 Converts the specified float from little endian to native endian.
 
#define OFFromLittleEndianDouble(d)   OFByteSwapDouble(d)
 Converts the specified double from little endian to native endian.
 
#define OFToBigEndianFloat(f)   (f)
 Converts the specified float from native endian to big endian.
 
#define OFToBigEndianDouble(d)   (d)
 Converts the specified double from native endian to big endian.
 
#define OFToLittleEndianFloat(f)   OFByteSwapFloat(f)
 Converts the specified float from native endian to little endian.
 
#define OFToLittleEndianDouble(d)   OFByteSwapDouble(d)
 Converts the specified double from native endian to little endian.
 
#define OFRotateLeft(value, bits)
 Rotates the specified value left by the specified amount of bits.
 
#define OFRotateRight(value, bits)
 Rotates the specified value right by the specified amount of bits.
 
#define OFRoundUpToPowerOf2(pow2, value)    (((value) + (pow2) - 1) & ~((pow2) - 1))
 Rounds up the specified value to the specified power of two.
 

Functions

static OF_INLINE uint32_t OF_CONST_FUNC OFBitConvertFloatToUInt32 (float f)
 Bit-converts the specified float to a uint32_t.
 
static OF_INLINE float OF_CONST_FUNC OFBitConvertUInt32ToFloat (uint32_t uInt32)
 Bit-converts the specified uint32_t to a float.
 
static OF_INLINE uint64_t OF_CONST_FUNC OFBitConvertDoubleToUInt64 (double d)
 Bit-converts the specified double to a uint64_t.
 
static OF_INLINE double OF_CONST_FUNC OFBitConvertUInt64ToDouble (uint64_t uInt64)
 Bit-converts the specified uint64_t to a double.
 
static OF_INLINE float OF_CONST_FUNC OFByteSwapFloat (float f)
 Byte swaps the specified float.
 
static OF_INLINE double OF_CONST_FUNC OFByteSwapDouble (double d)
 Byte swaps the specified double.
 

Macro Definition Documentation

◆ OFByteSwap16

#define OFByteSwap16 ( i)     (__builtin_constant_p(i) ? _OFByteSwap16Const(i) : _OFByteSwap16NonConst(i))

Byte swaps the specified 16 bit integer.

Parameters
iThe integer to byte swap
Returns
The byte swapped integer

◆ OFByteSwap32

#define OFByteSwap32 ( i)     (__builtin_constant_p(i) ? _OFByteSwap32Const(i) : _OFByteSwap32NonConst(i))

Byte swaps the specified 32 bit integer.

Parameters
iThe integer to byte swap
Returns
The byte swapped integer

◆ OFByteSwap64

#define OFByteSwap64 ( i)     (__builtin_constant_p(i) ? _OFByteSwap64Const(i) : _OFByteSwap64NonConst(i))

Byte swaps the specified 64 bit integer.

Parameters
iThe integer to byte swap
Returns
The byte swapped integer

◆ OFFromBigEndian16

#define OFFromBigEndian16 ( i)    (i)

Converts the specified 16 bit integer from big endian to native endian.

Parameters
iThe 16 bit integer to convert
Returns
The 16 bit integer converted to native endian

◆ OFFromBigEndian32

#define OFFromBigEndian32 ( i)    (i)

Converts the specified 32 bit integer from big endian to native endian.

Parameters
iThe 32 bit integer to convert
Returns
The 32 bit integer converted to native endian

◆ OFFromBigEndian64

#define OFFromBigEndian64 ( i)    (i)

Converts the specified 64 bit integer from big endian to native endian.

Parameters
iThe 64 bit integer to convert
Returns
The 64 bit integer converted to native endian

◆ OFFromBigEndianDouble

#define OFFromBigEndianDouble ( d)    (d)

Converts the specified double from big endian to native endian.

Parameters
dThe double to convert
Returns
The double converted to native endian

◆ OFFromBigEndianFloat

#define OFFromBigEndianFloat ( f)    (f)

Converts the specified float from big endian to native endian.

Parameters
fThe float to convert
Returns
The float converted to native endian

◆ OFFromLittleEndian16

#define OFFromLittleEndian16 ( i)    OFByteSwap16(i)

Converts the specified 16 bit integer from little endian to native endian.

Parameters
iThe 16 bit integer to convert
Returns
The 16 bit integer converted to native endian

◆ OFFromLittleEndian32

#define OFFromLittleEndian32 ( i)    OFByteSwap32(i)

Converts the specified 32 bit integer from little endian to native endian.

Parameters
iThe 32 bit integer to convert
Returns
The 32 bit integer converted to native endian

◆ OFFromLittleEndian64

#define OFFromLittleEndian64 ( i)    OFByteSwap64(i)

Converts the specified 64 bit integer from little endian to native endian.

Parameters
iThe 64 bit integer to convert
Returns
The 64 bit integer converted to native endian

◆ OFFromLittleEndianDouble

#define OFFromLittleEndianDouble ( d)    OFByteSwapDouble(d)

Converts the specified double from little endian to native endian.

Parameters
dThe double to convert
Returns
The double converted to native endian

◆ OFFromLittleEndianFloat

#define OFFromLittleEndianFloat ( f)    OFByteSwapFloat(f)

Converts the specified float from little endian to native endian.

Parameters
fThe float to convert
Returns
The float converted to native endian

◆ OFRotateLeft

#define OFRotateLeft ( value,
bits )
Value:
(((bits) % (sizeof(value) * 8)) > 0 \
? ((value) << ((bits) % (sizeof(value) * 8))) | \
((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
: (value))

Rotates the specified value left by the specified amount of bits.

Parameters
valueThe value to rotate
bitsThe number of bits to rotate left the value by
Returns
The value rotated left by the specified amount of bits

◆ OFRotateRight

#define OFRotateRight ( value,
bits )
Value:
(((bits) % (sizeof(value) * 8)) > 0 \
? ((value) >> ((bits) % (sizeof(value) * 8))) | \
((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
: (value))

Rotates the specified value right by the specified amount of bits.

Parameters
valueThe value to rotate
bitsThe number of bits to rotate right the value by
Returns
The value rotated right by the specified amount of bits

◆ OFRoundUpToPowerOf2

#define OFRoundUpToPowerOf2 ( pow2,
value )    (((value) + (pow2) - 1) & ~((pow2) - 1))

Rounds up the specified value to the specified power of two.

Parameters
pow2The power of 2 to round up to
valueThe value to round up to the specified power of two
Returns
The specified value rounded up to the specified power of two

◆ OFToBigEndian16

#define OFToBigEndian16 ( i)    (i)

Converts the specified 16 bit integer from native endian to big endian.

Parameters
iThe 16 bit integer to convert
Returns
The 16 bit integer converted to big endian

◆ OFToBigEndian32

#define OFToBigEndian32 ( i)    (i)

Converts the specified 32 bit integer from native endian to big endian.

Parameters
iThe 32 bit integer to convert
Returns
The 32 bit integer converted to big endian

◆ OFToBigEndian64

#define OFToBigEndian64 ( i)    (i)

Converts the specified 64 bit integer from native endian to big endian.

Parameters
iThe 64 bit integer to convert
Returns
The 64 bit integer converted to big endian

◆ OFToBigEndianDouble

#define OFToBigEndianDouble ( d)    (d)

Converts the specified double from native endian to big endian.

Parameters
dThe double to convert
Returns
The double converted to big endian

◆ OFToBigEndianFloat

#define OFToBigEndianFloat ( f)    (f)

Converts the specified float from native endian to big endian.

Parameters
fThe float to convert
Returns
The float converted to big endian

◆ OFToLittleEndian16

#define OFToLittleEndian16 ( i)    OFByteSwap16(i)

Converts the specified 16 bit integer from native endian to little endian.

Parameters
iThe 16 bit integer to convert
Returns
The 16 bit integer converted to little endian

◆ OFToLittleEndian32

#define OFToLittleEndian32 ( i)    OFByteSwap32(i)

Converts the specified 32 bit integer from native endian to little endian.

Parameters
iThe 32 bit integer to convert
Returns
The 32 bit integer converted to little endian

◆ OFToLittleEndian64

#define OFToLittleEndian64 ( i)    OFByteSwap64(i)

Converts the specified 64 bit integer from native endian to little endian.

Parameters
iThe 64 bit integer to convert
Returns
The 64 bit integer converted to little endian

◆ OFToLittleEndianDouble

#define OFToLittleEndianDouble ( d)    OFByteSwapDouble(d)

Converts the specified double from native endian to little endian.

Parameters
dThe double to convert
Returns
The double converted to little endian

◆ OFToLittleEndianFloat

#define OFToLittleEndianFloat ( f)    OFByteSwapFloat(f)

Converts the specified float from native endian to little endian.

Parameters
fThe float to convert
Returns
The float converted to little endian

Function Documentation

◆ OFBitConvertDoubleToUInt64()

static OF_INLINE uint64_t OF_CONST_FUNC OFBitConvertDoubleToUInt64 ( double d)
static

Bit-converts the specified double to a uint64_t.

Parameters
dThe double to bit-convert
Returns
The double bit-converted to a uint64_t

◆ OFBitConvertFloatToUInt32()

static OF_INLINE uint32_t OF_CONST_FUNC OFBitConvertFloatToUInt32 ( float f)
static

Bit-converts the specified float to a uint32_t.

Parameters
fThe float to bit-convert
Returns
The float bit-converted to a uint32_t

◆ OFBitConvertUInt32ToFloat()

static OF_INLINE float OF_CONST_FUNC OFBitConvertUInt32ToFloat ( uint32_t uInt32)
static

Bit-converts the specified uint32_t to a float.

Parameters
uInt32The uint32_t to bit-convert
Returns
The uint32_t bit-converted to a float

◆ OFBitConvertUInt64ToDouble()

static OF_INLINE double OF_CONST_FUNC OFBitConvertUInt64ToDouble ( uint64_t uInt64)
static

Bit-converts the specified uint64_t to a double.

Parameters
uInt64The uint64_t to bit-convert
Returns
The uint64_t bit-converted to a double

◆ OFByteSwapDouble()

static OF_INLINE double OF_CONST_FUNC OFByteSwapDouble ( double d)
static

Byte swaps the specified double.

Parameters
dThe double to byte swap
Returns
The byte swapped double

◆ OFByteSwapFloat()

static OF_INLINE float OF_CONST_FUNC OFByteSwapFloat ( float f)
static

Byte swaps the specified float.

Parameters
fThe float to byte swap
Returns
The byte swapped float