Loading...
Searching...
No Matches
by::platformAPI Namespace Reference

Platform-independent API wrapper for OS-specific operations. More...

Functions

const string & foreColor (consoleColor fore)
 Returns platform-specific string for console foreground color.
 
const string & backColor (consoleColor back)
 Returns platform-specific string for console background color.
 
string createNowTime (const std::string &strftime_format)
 Creates formatted timestamp using strftime format.
 
nuint64 getNowMs ()
 
string toAddrId (const void *inst)
 Converts pointer to 4-character hexadecimal identifier.
 
void log (const std::string &msg)
 
void log (const std::string *it) BY_SIDE_FUNC(log)
 
string getExecPath ()
 Retrieves absolute path of currently running executable.
 
string exec (const std::string &cmd)
 Executes shell command and captures output.
 
vector< string > callstack ()
 Captures current call stack for debugging.
 
string demangle (const nchar *org)
 Demangles C++ symbol name to human-readable form.
 
string filterDemangle (const nchar *org)
 Demangles C++ symbol and extracts only the function name portion.
 
std::string format (const nchar *fmt,...)
 Formats string using printf-style specifiers.
 
std::string format (const std::string &fmt, va_list args)
 
std::string format (const std::string *fmt, va_list args) BY_SIDE_FUNC(fmt
 
std::string format (const nchar *fmt, va_list args)
 
void crash (const nchar *msg,...)
 Terminates program with error message and call stack dump.
 
void crash (const std::string &msg, va_list args)
 
void crash (const std::string *msg, va_list args) BY_SIDE_FUNC(msg
 
void crash void ())
 
void crash (const std::string &msg)
 
void crash (const std::string *it) BY_SIDE_FUNC(crash)
 
nbool unlimitCoreDump ()
 Enables unlimited core dump size for debugging.
 

Variables

constexpr nint PATH_MAX_LEN = 256
 
constexpr nint MAX_BUF = 512
 
std::string format fmt
 
void crash msg
 

Detailed Description

Platform-independent API wrapper for OS-specific operations.

Provides a unified interface for platform-dependent operations, acting as a buffer layer between platform-specific APIs and the rest of the codebase.

For example, colored text output requires different approaches on different platforms: POSIX systems use ANSI escape sequences, while Windows uses WINAPI. Using platformAPI::foreColor() allows writing platform-independent code.

Usage

Example of platform-independent colored console output:

cout << foreColor(LIGHTGRAY) << "("
<< foreColor(LIGHTGRAY) << ")";
const string & foreColor(consoleColor fore)
Returns platform-specific string for console foreground color.
Definition platformAPI.cpp:51
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34

Other common operations include:

Function Documentation

◆ backColor()

const _nout std::string & by::platformAPI::backColor ( consoleColor back)

Returns platform-specific string for console background color.

Returns
On POSIX returns ANSI escape sequence, on Windows modifies console and returns empty string. Returns empty if terminal doesn't support colors.

◆ callstack()

_nout std::vector< std::string > by::platformAPI::callstack ( )

Captures current call stack for debugging.

Returns
Vector of demangled function names, excluding invalid entries. Returns empty if execinfo unavailable.
Note
Requires execinfo.h support (BY_HAS_EXECINFO == 1)

◆ crash()

_nout void by::platformAPI::crash ( const nchar * msg,
... )

Terminates program with error message and call stack dump.

Note
Outputs crash banner, reason, callstack, then calls abort()

◆ createNowTime()

_nout std::string by::platformAPI::createNowTime ( const std::string & strftime_format)

Creates formatted timestamp using strftime format.

Returns
Formatted time string representing current local time

◆ demangle()

_nout std::string by::platformAPI::demangle ( const nchar * org)

Demangles C++ symbol name to human-readable form.

Returns
Demangled name on POSIX, original string on Windows/WASM or if demangling fails

◆ exec()

_nout std::string by::platformAPI::exec ( const std::string & cmd)

Executes shell command and captures output.

Returns
Complete stdout output. Returns empty on Windows or execution failure.
Note
POSIX only. Uses popen/pclose internally.

◆ filterDemangle()

_nout std::string by::platformAPI::filterDemangle ( const nchar * org)

Demangles C++ symbol and extracts only the function name portion.

Returns
Function name after "::" on POSIX, after last space on Windows

◆ foreColor()

const _nout std::string & by::platformAPI::foreColor ( consoleColor fore)

Returns platform-specific string for console foreground color.

Returns
On POSIX returns ANSI escape sequence, on Windows modifies console and returns empty string. Returns empty if terminal doesn't support colors.

◆ format()

_nout std::string by::platformAPI::format ( const nchar * fmt,
... )

Formats string using printf-style specifiers.

Returns
Formatted string (max 512 characters)

◆ getExecPath()

_nout std::string by::platformAPI::getExecPath ( )

Retrieves absolute path of currently running executable.

Returns
Absolute path on Linux/macOS, empty string on Windows or error
Note
Uses /proc/self/exe on Linux, _NSGetExecutablePath on macOS

◆ toAddrId()

_nout std::string by::platformAPI::toAddrId ( const void * inst)

Converts pointer to 4-character hexadecimal identifier.

Returns
Last 4 hex digits of address
Note
Commonly used in logging with "@" prefix (e.g., "obj@a4f2")

◆ unlimitCoreDump()

_nout nbool by::platformAPI::unlimitCoreDump ( )

Enables unlimited core dump size for debugging.

Returns
true if successfully set, false otherwise
Note
On POSIX sets RLIMIT_CORE to infinity, on Windows registers minidump filter. Should be called early in debug builds.