ObjFW
Loading...
Searching...
No Matches
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)
 Byte swaps the specified 16 bit integer.
 
#define OFByteSwap32(i)
 Byte swaps the specified 32 bit integer.
 
#define OFByteSwap64(i)
 Byte swaps the specified 64 bit integer.
 
#define OFFromBigEndian16(i)
 Converts the specified 16 bit integer from big endian to native endian.
 
#define OFFromBigEndian32(i)
 Converts the specified 32 bit integer from big endian to native endian.
 
#define OFFromBigEndian64(i)
 Converts the specified 64 bit integer from big endian to native endian.
 
#define OFFromLittleEndian16(i)
 Converts the specified 16 bit integer from little endian to native endian.
 
#define OFFromLittleEndian32(i)
 Converts the specified 32 bit integer from little endian to native endian.
 
#define OFFromLittleEndian64(i)
 Converts the specified 64 bit integer from little endian to native endian.
 
#define OFToBigEndian16(i)
 Converts the specified 16 bit integer from native endian to big endian.
 
#define OFToBigEndian32(i)
 Converts the specified 32 bit integer from native endian to big endian.
 
#define OFToBigEndian64(i)
 Converts the specified 64 bit integer from native endian to big endian.
 
#define OFToLittleEndian16(i)
 Converts the specified 16 bit integer from native endian to little endian.
 
#define OFToLittleEndian32(i)
 Converts the specified 32 bit integer from native endian to little endian.
 
#define OFToLittleEndian64(i)
 Converts the specified 64 bit integer from native endian to little endian.
 
#define OFFromBigEndianFloat(f)
 Converts the specified float from big endian to native endian.
 
#define OFFromBigEndianDouble(d)
 Converts the specified double from big endian to native endian.
 
#define OFFromLittleEndianFloat(f)
 Converts the specified float from little endian to native endian.
 
#define OFFromLittleEndianDouble(d)
 Converts the specified double from little endian to native endian.
 
#define OFToBigEndianFloat(f)
 Converts the specified float from native endian to big endian.
 
#define OFToBigEndianDouble(d)
 Converts the specified double from native endian to big endian.
 
#define OFToLittleEndianFloat(f)
 Converts the specified float from native endian to little endian.
 
#define OFToLittleEndianDouble(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)
 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)
Value:
(__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)
Value:
(__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)
Value:
(__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)
Value:
(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)
Value:
(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)
Value:
(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)
Value:
(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)
Value:
(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)
Value:
#define OFByteSwap16(i)
Byte swaps the specified 16 bit integer.
Definition macros.h:608

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)
Value:
#define OFByteSwap32(i)
Byte swaps the specified 32 bit integer.
Definition macros.h:617

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)
Value:
#define OFByteSwap64(i)
Byte swaps the specified 64 bit integer.
Definition macros.h:626

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)
Value:
static OF_INLINE double OF_CONST_FUNC OFByteSwapDouble(double d)
Byte swaps the specified double.
Definition macros.h:710

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)
Value:
static OF_INLINE float OF_CONST_FUNC OFByteSwapFloat(float f)
Byte swaps the specified float.
Definition macros.h:697

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:
(((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)
Value:
(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)
Value:
(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)
Value:
(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)
Value:
(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)
Value:
(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)
Value:

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)
Value:

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)
Value:

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)
Value:

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)
Value:

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