ImFusion C++ SDK 4.4.0
Platform-specific functions

Selection of platform-specific functions. More...

Collaboration diagram for Platform-specific functions:

Detailed Description

Selection of platform-specific functions.

Classes

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

Functions

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

Handling of Environment Variables

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

Handling of crashes

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

Changing the byte order (endianness)

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

Type names

std::optional< std::stringImFusion::Platform::demangleTypeName (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::stringImFusion::Platform::demangleTypeName ()
 Returns the demangled name of the type T.

Function Documentation

◆ getEnvironmentVariable()

std::string ImFusion::Platform::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 ImFusion::Platform::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 ImFusion::Platform::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 ImFusion::Platform::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.

◆ libraryPathOfSymbol()

Filesystem::Path ImFusion::Platform::libraryPathOfSymbol ( const void * symbolPtr)

#include <ImFusion/Core/Platform.h>

Returns the absolute path to the library in which symbolPtr is located.

An empty string is returned on error.

Parameters
symbolPtrAddress of a symbol (free function, global variable) for which the corresponding shared library shall be located.
Note
On Linux this function uses dladdr() which may erroneously return the object from which you called the function. This is a known limitation in case the library was compiled without the position-independent code flag (-fPIC), cf. https://man7.org/linux/man-pages/man3/dladdr.3.html#BUGS

◆ installCrashHandler()

void ImFusion::Platform::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 ImFusion::Platform::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 > ImFusion::Platform::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 > ImFusion::Platform::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