Groups platform-specific helpers for Windows, Linux, and macOS. These utilities detect CPU architecture, manage COM initialization on Windows, resolve runtime paths, handle system directories, and unify OS-level functionality behind well-defined C++ APIs.
More...
|
std::string | get_bit_architecture () |
| Returns the bitness (e.g. "64") of the current platform based on sizeof(std::size_t) .
|
|
std::string | get_platform_architecture () |
| Returns a string identifying the platform architecture (e.g., "x86", "ARM", "MIPS", etc.).
|
|
std::string | get_architecture () |
| Returns a string describing both the architecture and bitness (e.g. "x86_64", "ARM32").
|
|
std::string | get_kernel_name () |
| Returns the kernel or operating system name (e.g., "Windows", "Linux", "Darwin").
|
|
std::filesystem::path | get_path_to_runtime_binary (const void *symbol_inside_runtime_binary=nullptr) |
| Retrieves the absolute path to the runtime binary (either an executable or a shared library) that contains a specified symbol.
|
|
std::string | get_last_windows_error_message () |
| Retrieves a descriptive error message for the last Windows API error.
|
|
Groups platform-specific helpers for Windows, Linux, and macOS. These utilities detect CPU architecture, manage COM initialization on Windows, resolve runtime paths, handle system directories, and unify OS-level functionality behind well-defined C++ APIs.
◆ get_architecture()
std::string cbeam::platform::get_architecture |
( |
| ) |
|
|
inline |
Returns a string describing both the architecture and bitness (e.g. "x86_64", "ARM32").
- Returns
- A string combining the platform architecture and the number of bits.
◆ get_bit_architecture()
std::string cbeam::platform::get_bit_architecture |
( |
| ) |
|
|
inline |
Returns the bitness (e.g. "64") of the current platform based on sizeof(std::size_t)
.
- Returns
- A string representing the number of bits, typically "32" or "64".
◆ get_kernel_name()
std::string cbeam::platform::get_kernel_name |
( |
| ) |
|
|
inline |
Returns the kernel or operating system name (e.g., "Windows", "Linux", "Darwin").
The detection is based on predefined macros.
- Returns
- A string containing the kernel/OS name, or "Unknown" if not recognized.
◆ get_last_windows_error_message()
std::string cbeam::platform::get_last_windows_error_message |
( |
| ) |
|
|
inline |
Retrieves a descriptive error message for the last Windows API error.
This function attempts to retrieve a human-readable error message corresponding to the last error code set by the Windows API. The function assumes that an error has occurred and does not perform error detection; it should be called only when an error is known to have occurred. It returns a generic message if it fails to retrieve a specific error message.
- Returns
- A std::string containing the error message. If unable to retrieve a specific message, it returns "unknown error".
◆ get_path_to_runtime_binary()
std::filesystem::path cbeam::platform::get_path_to_runtime_binary |
( |
const void * | symbol_inside_runtime_binary = nullptr | ) |
|
|
inline |
Retrieves the absolute path to the runtime binary (either an executable or a shared library) that contains a specified symbol.
This function attempts to locate the runtime binary containing the specified symbol. By default, if no symbol is provided (symbol_inside_runtime_binary
is nullptr), the function employs a local static symbol defined within itself. This approach is useful for identifying the path of the binary that includes this function.
- Note
- Under Linux and macOS, this function may not yield the intended results if the executable was invoked through a symbolic link not present in the application's current directory but rather in the executing shell's PATH. This is due to the fact that the function relies on resolving the runtime context of the symbol, which may not correctly reflect symbolic links used during invocation.
- Warning
- When relying on the default parameter, linker optimizations might cause the local static symbol to reside in a binary different from the intended target, especially when multiple shared libraries including this header are linked to the same executable. This can result in unexpected path resolutions. To ensure accurate results, it is recommended to explicitly pass a pointer to a static symbol known to reside within the desired binary.
- Parameters
-
symbol_inside_runtime_binary | A pointer to a symbol within the runtime binary. If nullptr, a local static symbol is used. |
- Returns
- std::filesystem::path The absolute path to the runtime binary containing the specified symbol.
- Exceptions
-
std::runtime_error | if the path cannot be determined or if the symbol is not associated with any binary. |
◆ get_platform_architecture()
std::string cbeam::platform::get_platform_architecture |
( |
| ) |
|
|
inline |
Returns a string identifying the platform architecture (e.g., "x86", "ARM", "MIPS", etc.).
The detection is based on predefined compiler macros.
- Returns
- A string describing the CPU architecture, or "Unknown" if not recognized.