xoreos  0.0.5
Macros | Functions | Variables
util.h File Reference

Utility templates and functions. More...

#include "src/common/endianness.h"
#include <cmath>
Include dependency graph for util.h:

Go to the source code of this file.

Macros

#define ARRAYSIZE(x)   (sizeof(x) / sizeof(x[0]))
 Macro which determines the number of entries in a fixed size array. More...
 

Functions

template<typename T >
ABS (T x)
 
template<typename T >
MIN (T a, T b)
 
template<typename T >
MAX (T a, T b)
 
template<typename T >
CLIP (T v, T amin, T amax)
 
template<typename T >
void SWAP (T &a, T &b)
 Template method which swaps the values of its two parameters. More...
 
template<typename T >
bool ISPOWER2 (T x)
 Is this integer value a power of 2? More...
 
static uint32 NEXTPOWER2 (uint32 x)
 Round up to the next power of 2. More...
 
static uint64 NEXTPOWER2 (uint64 x)
 Round up to the next power of 2. More...
 
void warning (const char *s,...) GCC_PRINTF(1
 Print a warning message to both stderr and the global log file (if a global log file has been opened). More...
 
void void status (const char *s,...) GCC_PRINTF(1
 Print a status message to both stderr and the global log file (if a global log file has been opened). More...
 
void void void info (const char *s,...) GCC_PRINTF(1
 Print an info message to both stdout and the global log file (if a global log file has been opened). More...
 
void void void void NORETURN_PRE error (const char *s,...) GCC_PRINTF(1
 Print an error message to both stderr and the global log file (if a global log file has been opened). More...
 
float convertIEEEFloat (uint32 data)
 Convert a uint32 holding the bit pattern of a 32-bit IEEE 754 single precision floating point value into a real, native float. More...
 
double convertIEEEDouble (uint64 data)
 Convert a uint64 holding the bit pattern of a 64-bit IEEE 754 double precision floating point value into a real, native double. More...
 
uint32 convertIEEEFloat (float value)
 Convert a native float into a uint32 holding the bit pattern a 32-bit IEEE 754 single precision floating point value. More...
 
uint64 convertIEEEDouble (double value)
 Convert a native double into a uint64 holding the bit pattern a 64-bit IEEE 754 double precision floating point value. More...
 
double readNintendoFixedPoint (uint32 value, bool sign, uint8 iBits, uint8 fBits)
 Read a fixed-point value, in a format used by the Nintendo DS. More...
 
float readIEEEFloat16 (uint16 value)
 Read a half-precision 16-bit IEEE float, converting it into a 32-bit iEEE float. More...
 

Variables

void void void void NORETURN_PRE NORETURN_POST
 

Detailed Description

Utility templates and functions.

Definition in file util.h.

Macro Definition Documentation

◆ ARRAYSIZE

#define ARRAYSIZE (   x)    (sizeof(x) / sizeof(x[0]))

Macro which determines the number of entries in a fixed size array.

Definition at line 131 of file util.h.

Referenced by Graphics::Aurora::TextureManager::activeTexture(), Aurora::FileTypeManager::buildExtensionLookup(), Aurora::FileTypeManager::buildHashLookup(), Aurora::FileTypeManager::buildTypeLookup(), Engines::KotOR::CharacterGenerationMenu::CharacterGenerationMenu(), convertShortToLongOption(), Graphics::Aurora::Texture::create(), Engines::DragonAge::Creature::createModelPrefix(), Graphics::CubeMapCombiner::CubeMapCombiner(), Engines::NWN::NWNEngine::declareBogusTextures(), Engines::Jade::JadeEngine::declareLanguages(), Engines::KotOR2::KotOR2Engine::declareLanguages(), Engines::Sonic::SonicEngine::declareLanguages(), Engines::NWN2::NWN2Engine::declareLanguages(), Engines::DragonAge::DragonAgeEngine::declareLanguages(), Engines::DragonAge2::DragonAge2Engine::declareLanguages(), Engines::Witcher::WitcherEngine::declareLanguages(), Engines::KotOR::KotOREngine::declareLanguages(), Engines::NWN::NWNEngine::declareLanguages(), Engines::Sonic::SonicEngine::declareResources(), Sound::WMACodec::decodeExpHuffman(), Sound::Ima_ADPCMStream::decodeIMA(), Aurora::findGDAHeader(), Aurora::ERFFile::findNWNPremiumKey(), Engines::NWN::getCreatureAnimationName(), Engines::NWN::getCreatureTalkAnimationName(), Engines::NWN::getDoorAnimationName(), Common::FilePath::getHumanReadableSize(), Engines::NWN::getPlaceableAnimationName(), Sound::WMACodec::initExponents(), Sound::WMACodec::initNoise(), Engines::NWN::OptionsResolutionMenu::initResolutionsBox(), Engines::NWN::Game::isPremiumModule(), Engines::Sonic::Placeable::load(), Graphics::Aurora::Texture::loadImage(), Graphics::outputGLDebug(), Graphics::TXI::parseBlending(), Aurora::LanguageManager::parseLanguage(), Graphics::Aurora::Model_NWN::populateDefaultAnimations(), Engines::DragonAge2::ScriptContainer::readScript(), Engines::DragonAge::ScriptContainer::readScript(), Engines::Jade::ScriptContainer::readScripts(), Engines::KotOR::ScriptContainer::readScripts(), Engines::KotOR2::ScriptContainer::readScripts(), Engines::NWN::ScriptContainer::readScripts(), Engines::Witcher::ScriptContainer::readScripts(), Engines::NWN2::ScriptContainer::readScripts(), Engines::DragonAge2::Functions::registerFunctions(), Engines::DragonAge::Functions::registerFunctions(), Engines::NWN::Functions::registerFunctions(), Engines::Witcher::Functions::registerFunctions(), Engines::NWN2::Functions::registerFunctions(), Engines::KotOR2::Functions::registerFunctions(), Engines::Jade::Functions::registerFunctions(), Engines::KotOR::Functions::registerFunctions(), Engines::NWN::Module::removePCTokens(), Engines::NWN::Module::setPCTokens(), Aurora::NWScript::NCSFile::setupOpcodes(), Engines::KotOR::HUD::update(), Engines::KotOR::GUIBackground::update(), Engines::Jade::GUIBackground::update(), and Engines::NWN::Console::updateCampaigns().

Function Documentation

◆ ABS()

template<typename T >
T ABS ( x)
inline

Definition at line 69 of file util.h.

Referenced by Engines::DragonAge::Functions::abs(), Engines::DragonAge2::Functions::abs(), Engines::KotOR2::Functions::abs(), Engines::NWN::Functions::abs(), Engines::NWN2::Functions::abs(), Engines::Witcher::Functions::abs(), Engines::KotOR::Functions::abs(), Engines::Jade::Functions::abs(), Graphics::Aurora::CubeSide::calculateDistance(), Graphics::Aurora::Model::calculateDistance(), Common::composeString(), Engines::DragonAge::Functions::fabs(), Engines::DragonAge2::Functions::fabs(), Engines::NWN2::Functions::fabs(), Engines::KotOR2::Functions::fabs(), Engines::NWN::Functions::fabs(), Engines::Witcher::Functions::fabs(), Engines::KotOR::Functions::fabs(), Engines::Jade::Functions::fabs(), Common::BoundingBox::getDepth(), Engines::Sonic::ObjectDistanceSort::getDistance(), Engines::Jade::ObjectDistanceSort::getDistance(), Engines::KotOR2::ObjectDistanceSort::getDistance(), Engines::NWN2::ObjectDistanceSort::getDistance(), Engines::Witcher::ObjectDistanceSort::getDistance(), Engines::KotOR::ObjectDistanceSort::getDistance(), Engines::NWN::ObjectDistanceSort::getDistance(), Engines::DragonAge::ObjectDistanceSort::getDistance(), Engines::DragonAge2::ObjectDistanceSort::getDistance(), Common::BoundingBox::getHeight(), Graphics::Aurora::GUIQuad::getHeight(), Common::BoundingBox::getWidth(), Graphics::Aurora::GUIQuad::getWidth(), Engines::DragonAge2::Functions::isVectorEmpty(), Engines::DragonAge::Functions::isVectorEmpty(), Graphics::Aurora::TextureFont::load(), Common::MDCT::MDCT(), Engines::NWN::QuadWidget::QuadWidget(), and Engines::ConsoleWindow::updateHighlight().

Here is the caller graph for this function:

◆ CLIP()

template<typename T >
T CLIP ( v,
amin,
amax 
)
inline

◆ convertIEEEDouble() [1/2]

double convertIEEEDouble ( uint64  data)

Convert a uint64 holding the bit pattern of a 64-bit IEEE 754 double precision floating point value into a real, native double.

NOTE: Currently, this function assumes native doubles are 64-bit IEEE 754 double precision floating point values!

Definition at line 143 of file util.cpp.

References doubleConvert::dDouble, and doubleConvert::dInt.

Referenced by Common::FoxPro::getDouble(), Common::ReadStream::readIEEEDoubleBE(), Common::ReadStream::readIEEEDoubleLE(), Common::FoxPro::setDouble(), Common::WriteStream::writeIEEEDoubleBE(), and Common::WriteStream::writeIEEEDoubleLE().

Here is the caller graph for this function:

◆ convertIEEEDouble() [2/2]

uint64 convertIEEEDouble ( double  value)

Convert a native double into a uint64 holding the bit pattern a 64-bit IEEE 754 double precision floating point value.

NOTE: Currently, this function assumes native doubles are 64-bit IEEE 754 double precision floating point values!

Definition at line 151 of file util.cpp.

References doubleConvert::dDouble, and doubleConvert::dInt.

◆ convertIEEEFloat() [1/2]

float convertIEEEFloat ( uint32  data)

Convert a uint32 holding the bit pattern of a 32-bit IEEE 754 single precision floating point value into a real, native float.

NOTE: Currently, this function assumes native floats are 32-bit IEEE 754 single precision floating point values!

Definition at line 116 of file util.cpp.

References floatConvert::dFloat, and floatConvert::dInt.

Referenced by Common::FoxPro::getDouble(), Aurora::GFF3Struct::getDouble(), readIEEEFloat16(), Common::ReadStream::readIEEEFloatBE(), Common::ReadStream::readIEEEFloatLE(), Common::FoxPro::setDouble(), Common::WriteStream::writeIEEEFloatBE(), and Common::WriteStream::writeIEEEFloatLE().

Here is the caller graph for this function:

◆ convertIEEEFloat() [2/2]

uint32 convertIEEEFloat ( float  value)

Convert a native float into a uint32 holding the bit pattern a 32-bit IEEE 754 single precision floating point value.

NOTE: Currently, this function assumes native floats are 32-bit IEEE 754 single precision floating point values!

Definition at line 125 of file util.cpp.

References floatConvert::dFloat, and floatConvert::dInt.

◆ error()

void void void void NORETURN_PRE error ( const char *  s,
  ... 
)

Print an error message to both stderr and the global log file (if a global log file has been opened).

See Common::DebugManager for details.

Automatically prepends the text "ERROR: " and appends an exclamation mark and a newline.

Additionally, the program will immediately quit with return code 1.

◆ info()

void void void info ( const char *  s,
  ... 
)

Print an info message to both stdout and the global log file (if a global log file has been opened).

See Common::DebugManager for details.

Automatically appends a newline.

◆ ISPOWER2()

template<typename T >
bool ISPOWER2 ( x)
inline

Is this integer value a power of 2?

Definition at line 81 of file util.h.

◆ MAX()

template<typename T >
T MAX ( a,
b 
)
inline

◆ MIN()

template<typename T >
T MIN ( a,
b 
)
inline

◆ NEXTPOWER2() [1/2]

static uint32 NEXTPOWER2 ( uint32  x)
inlinestatic

Round up to the next power of 2.

Definition at line 84 of file util.h.

Referenced by Graphics::Aurora::NFTRFont::drawGlyphs(), Video::VideoDecoder::initVideo(), and Graphics::SBM::readData().

Here is the caller graph for this function:

◆ NEXTPOWER2() [2/2]

static uint64 NEXTPOWER2 ( uint64  x)
inlinestatic

Round up to the next power of 2.

Definition at line 96 of file util.h.

◆ readIEEEFloat16()

float readIEEEFloat16 ( uint16  value)

Read a half-precision 16-bit IEEE float, converting it into a 32-bit iEEE float.

Definition at line 198 of file util.cpp.

References convertIEEEFloat().

Referenced by Graphics::Aurora::ModelNode_DragonAge::read2Float32(), Graphics::Aurora::ModelNode_DragonAge::read3Float32(), and Graphics::Aurora::ModelNode_DragonAge::read4Float32().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readNintendoFixedPoint()

double readNintendoFixedPoint ( uint32  value,
bool  sign,
uint8  iBits,
uint8  fBits 
)

Read a fixed-point value, in a format used by the Nintendo DS.

Parameters
valueThe integer representing the fixed-point value.
signIs this a signed fixed-point value?
iBitsNumber of bits in the integer part.
fBitsNumber of bits in the fractional part.
Returns
A floating-point representation of the fixed-point value.

Definition at line 159 of file util.cpp.

References UINT64_C.

Referenced by Graphics::Aurora::Model_Sonic::createPrimitives(), Aurora::GFF4Struct::getDouble(), Aurora::GFF4Struct::getFloat(), Graphics::Aurora::Model_Sonic::readBone(), Aurora::GFXFile::readMatrix(), and Graphics::Aurora::Model_Sonic::readModel().

Here is the caller graph for this function:

◆ status()

void void status ( const char *  s,
  ... 
)

Print a status message to both stderr and the global log file (if a global log file has been opened).

See Common::DebugManager for details.

Automatically appends a newline.

◆ SWAP()

template<typename T >
void SWAP ( T &  a,
T &  b 
)
inline

◆ warning()

void warning ( const char *  s,
  ... 
)

Print a warning message to both stderr and the global log file (if a global log file has been opened).

See Common::DebugManager for details.

Automatically prepends the text "WARNING: " and appends an exclamation mark and a newline.

Variable Documentation

◆ NORETURN_POST

void void void void NORETURN_PRE NORETURN_POST

Definition at line 166 of file util.h.