ImFusion SDK 4.3
Platform-specific functions

Selection of platform-specific functions. More...

+ Collaboration diagram for Platform-specific functions:

Detailed Description

Selection of platform-specific functions.

Classes

struct  MemoryInfo
 Structure storing information about the available main memory as reported Platform::memoryInfo(). More...
 

Functions

std::string stacktrace ()
 Generates a platform-dependent call stack of the current execution environment.
 
void signalDebugTrap ()
 Generates a platform-dependent trap signal that can be caught by an attached debugger to interrupt the program.
 
MemoryInfo memoryInfo ()
 Returns the currently available system memory and the total amount of memory.
 
Filesystem::Path executablePath ()
 Returns the absolute path to the current executable (including the name of the executable)
 
Filesystem::Path libraryPath (const std::string &libName)
 Returns the absolute path to the given library (including the full name of the library).
 

Handling of Environment Variables

std::string getEnvironmentVariable (const std::string &variableName, const std::string &defaultValue, bool reset=false)
 Reads an environment variable passed to the program at launch.
 
void setEnvironmentVariable (const std::string &variableName, const std::string &newValue)
 Writes an environment variable.
 

Handling of crashes

void installCrashHandler ()
 Install OS-specific hooks to catch and handle critical signals/exceptions.
 
void resetCrashHandler ()
 Remove crash hooks again.
 

Changing the byte order (endianness)

void swapEndianness (uint16_t *buffer, int64_t numElements)
 Reverses the order of bytes in the given buffer of 16-bit integers.
 
void swapEndianness (uint32_t *buffer, int64_t numElements)
 Reverses the order of bytes in the given buffer of 32-bit integers.
 
void swapEndianness (uint64_t *buffer, int64_t numElements)
 Reverses the order of bytes in the given buffer of 64-bit integers.
 
template<typename T>
void swapEndianness (T *buffer, int64_t numElements)
 Reverses the order of bytes in the given buffer of integers.
 

Type names

std::optional< std::stringdemangleTypeName (const std::type_info &typeInfo)
 Returns the demangled name of the type represented by the given type_info object.
 
template<typename T>
std::optional< std::stringdemangleTypeName ()
 Returns the demangled name of the type T.
 

Function Documentation

◆ getEnvironmentVariable()

std::string getEnvironmentVariable ( const std::string & variableName,
const std::string & defaultValue,
bool reset = false )

#include <ImFusion/Core/Platform.h>

Reads an environment variable passed to the program at launch.

The environment variable is read only the first time that the function is called with a given variable name. The result is cached for subsequent calls. The cache can be reset with the respective parameter.

Setting the empty value for an environment variable equals to unsetting it. In this case, the default value will be returned.

The cache is automatically updated when a variable is modified through setEnvironmentVariable().

Parameters
variableNameThe name of the environment variable to be read
defaultValueThe default value to be returned if the variable value was not set
resetIf true, the cached value for the environment variable will be deleted
Returns
The value of the environment variable, or the given default if none was set

◆ setEnvironmentVariable()

void setEnvironmentVariable ( const std::string & variableName,
const std::string & newValue )

#include <ImFusion/Core/Platform.h>

Writes an environment variable.

Updates the environment value table for the current process, setting the provided value for the specified variable.

To unset the variable, the empty string should be specified as new value. readEnvironmentVariable() will then return the default when the variable is queried.

The cache used by getEnvironmentVariable() is also updated in the process, so no further action is required.

Parameters
variableNameThe name of the environment variable to be written
newValueThe new value that is to be assumed by the variable

◆ memoryInfo()

MemoryInfo memoryInfo ( )

#include <ImFusion/Core/Platform.h>

Returns the currently available system memory and the total amount of memory.

Note
Currently only implemented for Windows and Linux platforms.

◆ libraryPath()

Filesystem::Path libraryPath ( const std::string & libName)

#include <ImFusion/Core/Platform.h>

Returns the absolute path to the given library (including the full name of the library).

The library must be loaded by the current process. An empty string is returned if the library could not be found.

Parameters
libNameFilename of the library to resolve without extension, e.g. ImFusionCore or ImFusionLib. On Unix platforms this function will automatically prepend the lib prefix to libName during lookup. On Linux, this function will match library names of the form "*.so{.versioning}" with the constraint that the optional versioning is of the form "1.23.312", i.e. three digits. Comparison is performed in a case-sensitive fashion.

◆ installCrashHandler()

void installCrashHandler ( )

#include <ImFusion/Core/Platform.h>

Install OS-specific hooks to catch and handle critical signals/exceptions.

The handler will write the current stacktrace() to the log and flush it to ensure that all pending writes of the log are completed in case the application terminates.

Note
The signal/exception handlers may interfere with managed languages and lead to issues, for instance when embedding the library into .NET or Java applications.

◆ swapEndianness()

template<typename T>
void swapEndianness ( T * buffer,
int64_t numElements )

#include <ImFusion/Core/Platform.h>

Reverses the order of bytes in the given buffer of integers.

T must be an integral type of 16, 32, or 64 bit width.

◆ demangleTypeName() [1/2]

std::optional< std::string > demangleTypeName ( const std::type_info & typeInfo)

#include <ImFusion/Core/Platform.h>

Returns the demangled name of the type represented by the given type_info object.

Returns an empty optional if demangling fails.

◆ demangleTypeName() [2/2]

template<typename T>
std::optional< std::string > demangleTypeName ( )

#include <ImFusion/Core/Platform.h>

Returns the demangled name of the type T.

Returns an empty optional if demangling fails.

Search Tab / S to search, Esc to close