xoreos  0.0.5
Macros | Functions
endianness.h File Reference

Low-level macros and functions to handle different endianness portably. More...

#include "src/common/system.h"
#include "src/common/types.h"
Include dependency graph for endianness.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SWAP_CONSTANT_64(a)
 
#define SWAP_CONSTANT_32(a)
 
#define SWAP_CONSTANT_16(a)
 
#define MKTAG(a0, a1, a2, a3)   ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
 A wrapper macro used around four character constants, like 'DATA', to ensure portability. More...
 
#define MKTAG_16(a0, a1)   ((uint16)((a1) | ((a0) << 8)))
 A wrapper macro used around two character constants, like 'MZ'. More...
 

Functions

static uint64 SWAP_BYTES_64 (uint64 a)
 
static uint32 SWAP_BYTES_32 (uint32 a)
 
static uint16 SWAP_BYTES_16 (const uint16 a)
 
FORCEINLINE uint16 READ_UINT16 (const void *ptr)
 
FORCEINLINE uint32 READ_UINT32 (const void *ptr)
 
FORCEINLINE uint64 READ_UINT64 (const void *ptr)
 
FORCEINLINE void WRITE_UINT16 (void *ptr, uint16 value)
 
FORCEINLINE void WRITE_UINT32 (void *ptr, uint32 value)
 
FORCEINLINE void WRITE_UINT64 (void *ptr, uint64 value)
 

Detailed Description

Low-level macros and functions to handle different endianness portably.

Definition in file endianness.h.

Macro Definition Documentation

◆ MKTAG

#define MKTAG (   a0,
  a1,
  a2,
  a3 
)    ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))

A wrapper macro used around four character constants, like 'DATA', to ensure portability.

Typical usage: MKTAG('D','A','T','A').

Why is this necessary? The C/C++ standard does not define the endianness to be used for character constants. Hence if one uses multi-byte character constants, a potential portability problem opens up.

Definition at line 140 of file endianness.h.

Referenced by Engines::KotOR::Walkmesh::appendFromStream(), Engines::Witcher::Area::Area(), Engines::NWN2::Area::Area(), Video::QuickTimeDecoder::AudioSampleDesc::createAudioStream(), Engines::NWN2::Campaign::getDescription(), Engines::Witcher::Campaign::getDescription(), Engines::NWN2::Module::getDescription(), Engines::Witcher::Module::getDescription(), Engines::NWN2::Campaign::getName(), Engines::Witcher::Campaign::getName(), Engines::NWN2::Module::getName(), Engines::Witcher::Module::getName(), Engines::Witcher::Area::getName(), Engines::NWN2::Area::getName(), Engines::KotOR2::Module::getName(), Engines::NWN::Area::getName(), Engines::KotOR::Module::getName(), Engines::KotOR::PartySelectionGUI::getPortrait(), Sound::WwRIFFVorbisStream::init(), Video::QuickTimeDecoder::VideoSampleDesc::initCodec(), Video::QuickTimeDecoder::initParseTable(), Video::QuickTimeDecoder::AudioSampleDesc::isAudioCodecSupported(), Engines::KotOR::Trigger::load(), Engines::KotOR2::Trigger::load(), Video::ActimagineDecoder::load(), Engines::Witcher::Creature::load(), Engines::KotOR::Waypoint::load(), Engines::KotOR2::Waypoint::load(), Engines::NWN::Waypoint::load(), Engines::NWN2::Waypoint::load(), Engines::Witcher::Waypoint::load(), Engines::NWN::GUI::load(), Engines::DragonAge2::Placeable::load(), Engines::DragonAge::Placeable::load(), Aurora::IFOFile::load(), Engines::Jade::Placeable::load(), Engines::Jade::Trigger::load(), Engines::Jade::Creature::load(), Engines::Witcher::Door::load(), Engines::NWN2::TRXFile::load(), Engines::Witcher::Placeable::load(), Engines::KotOR2::Placeable::load(), Engines::NWN2::Placeable::load(), Engines::KotOR::GUI::load(), Engines::Jade::GUI::load(), Sound::FMODSampleBank::load(), Engines::KotOR::Placeable::load(), Engines::Jade::Area::load(), Engines::NWN::Placeable::load(), Engines::NWN::Item::load(), Engines::KotOR::Door::load(), Sound::XACTWaveBank_Binary::load(), Engines::KotOR2::Door::load(), Engines::NWN2::Door::load(), Engines::NWN::Door::load(), Engines::KotOR2::Creature::load(), Video::XboxMediaVideo::load(), Engines::KotOR::Creature::load(), Engines::NWN2::Creature::load(), Engines::KotOR2::Area::load(), Engines::NWN::Area::load(), Engines::KotOR::Area::load(), Engines::NWN::Creature::load(), Engines::Witcher::Campaign::loadCampaignFile(), Engines::NWN2::Campaign::loadCampaignResource(), Common::PEResources::loadFromEXE(), Engines::Jade::Placeable::loadInstance(), Engines::NWN2::TRXFile::loadPacket(), Sound::SoundManager::makeAudioStream(), Sound::makeWAVStream(), Video::QuickTimeDecoder::QuickTimeAudioTrack::QuickTimeAudioTrack(), Video::QuickTimeDecoder::readDefault(), Video::QuickTimeDecoder::readHDLR(), Video::QuickTimeDecoder::readSampleDesc(), Aurora::SACFile::SACFile(), and Engines::KotOR::SoundObject::SoundObject().

◆ MKTAG_16

#define MKTAG_16 (   a0,
  a1 
)    ((uint16)((a1) | ((a0) << 8)))

A wrapper macro used around two character constants, like 'MZ'.

Definition at line 143 of file endianness.h.

Referenced by Common::PEResources::loadFromEXE().

◆ SWAP_CONSTANT_16

#define SWAP_CONSTANT_16 (   a)
Value:
((uint16)((((a) >> 8) & 0x00FF) | \
(((a) << 8) & 0xFF00) ))
uint16_t uint16
Definition: types.h:202

Definition at line 77 of file endianness.h.

◆ SWAP_CONSTANT_32

#define SWAP_CONSTANT_32 (   a)
Value:
((uint32)((((a) >> 24) & 0x00FF) | \
(((a) >> 8) & 0xFF00) | \
(((a) & 0xFF00) << 8) | \
(((a) & 0x00FF) << 24) ))
uint32_t uint32
Definition: types.h:204

Definition at line 71 of file endianness.h.

◆ SWAP_CONSTANT_64

#define SWAP_CONSTANT_64 (   a)
Value:
((uint64)((((a) >> 56) & 0x000000FF) | \
(((a) >> 40) & 0x0000FF00) | \
(((a) >> 24) & 0x00FF0000) | \
(((a) >> 8) & 0xFF000000) | \
(((a) & 0xFF000000) << 8) | \
(((a) & 0x00FF0000) << 24) | \
(((a) & 0x0000FF00) << 40) | \
(((a) & 0x000000FF) << 56) ))
uint64_t uint64
Definition: types.h:206

Definition at line 61 of file endianness.h.

Function Documentation

◆ READ_UINT16()

FORCEINLINE uint16 READ_UINT16 ( const void *  ptr)

Definition at line 150 of file endianness.h.

◆ READ_UINT32()

FORCEINLINE uint32 READ_UINT32 ( const void *  ptr)

Definition at line 154 of file endianness.h.

◆ READ_UINT64()

FORCEINLINE uint64 READ_UINT64 ( const void *  ptr)

Definition at line 158 of file endianness.h.

◆ SWAP_BYTES_16()

static uint16 SWAP_BYTES_16 ( const uint16  a)
inlinestatic

Definition at line 128 of file endianness.h.

◆ SWAP_BYTES_32()

static uint32 SWAP_BYTES_32 ( uint32  a)
inlinestatic

Definition at line 120 of file endianness.h.

◆ SWAP_BYTES_64()

static uint64 SWAP_BYTES_64 ( uint64  a)
inlinestatic

Definition at line 108 of file endianness.h.

◆ WRITE_UINT16()

FORCEINLINE void WRITE_UINT16 ( void *  ptr,
uint16  value 
)

Definition at line 162 of file endianness.h.

◆ WRITE_UINT32()

FORCEINLINE void WRITE_UINT32 ( void *  ptr,
uint32  value 
)

Definition at line 166 of file endianness.h.

◆ WRITE_UINT64()

FORCEINLINE void WRITE_UINT64 ( void *  ptr,
uint64  value 
)

Definition at line 170 of file endianness.h.