|
RSTools 3.1.0
Versatile C++20 utility library
|
Portable access to system information, environment variables, files and paths. More...
Functions | |
Environment variables | |
| std::optional< std::string > | getEnv (std::string_view name) |
Value of the variable name, or std::nullopt if it is not set. | |
| bool | setEnv (std::string_view name, std::string_view value, bool overwrite=true) |
Sets name to value, unless it is already set and overwrite is false; returns false on failure. | |
| bool | unsetEnv (std::string_view name) |
Removes name from the environment; returns false on failure. | |
Files | |
Files are read and written in binary mode, so the content is kept unchanged. | |
| std::optional< std::string > | readFile (const std::filesystem::path &path) |
Content of the file, or std::nullopt if it cannot be read. | |
| bool | writeFile (const std::filesystem::path &path, std::string_view content) |
Creates or replaces the file with content; returns false on failure. | |
| bool | appendFile (const std::filesystem::path &path, std::string_view content) |
Appends content to the file, creating it if needed; returns false on failure. | |
Paths | |
Empty when the path cannot be found. | |
| std::filesystem::path | getExecutablePath () |
| Absolute path of the running executable. | |
| std::filesystem::path | getExecutableDirectory () |
| Directory of the running executable. | |
| std::filesystem::path | getHomeDirectory () |
| Home directory of the current user. | |
CPU | |
| std::size_t | getCpuCores () noexcept |
| Number of logical cores, at least 1. | |
| std::string | getCpuName () |
| CPU model name, or an empty string if unknown. | |
| constexpr std::string_view | getArchitecture () noexcept |
Architecture the program was built for: x86_64, x86, arm64, arm, riscv, wasm or unknown. | |
Memory | |
Sizes in bytes, or 0 if unavailable. | |
| std::uint64_t | getTotalRAM () noexcept |
| std::uint64_t | getAvailableRAM () noexcept |
| std::uint64_t | getProcessMemoryUsage () noexcept |
| Physical memory used by this process. | |
| std::uint64_t | getPeakProcessMemoryUsage () noexcept |
| Highest physical memory used by this process so far. | |
Operating system | |
| std::string | getOSName () |
Operating system family, such as Linux or Windows 64-bit. | |
| std::string | getHostName () |
| Network name of this computer, or an empty string on failure. | |
Disk | |
Sizes in bytes of the file system holding | |
| std::uint64_t | getTotalDiskSpace (const std::string &path="/") |
| std::uint64_t | getAvailableDiskSpace (const std::string &path="/") |
Portable access to system information, environment variables, files and paths.
Nothing throws: failures return std::nullopt, false, 0 or an empty value.
| std::optional< std::string > RST::System::getEnv | ( | std::string_view | name | ) |
Value of the variable name, or std::nullopt if it is not set.
| bool RST::System::setEnv | ( | std::string_view | name, |
| std::string_view | value, | ||
| bool | overwrite = true |
||
| ) |
Sets name to value, unless it is already set and overwrite is false; returns false on failure.
| bool RST::System::unsetEnv | ( | std::string_view | name | ) |
Removes name from the environment; returns false on failure.
| std::optional< std::string > RST::System::readFile | ( | const std::filesystem::path & | path | ) |
Content of the file, or std::nullopt if it cannot be read.
| bool RST::System::writeFile | ( | const std::filesystem::path & | path, |
| std::string_view | content | ||
| ) |
Creates or replaces the file with content; returns false on failure.
| bool RST::System::appendFile | ( | const std::filesystem::path & | path, |
| std::string_view | content | ||
| ) |
Appends content to the file, creating it if needed; returns false on failure.
| std::filesystem::path RST::System::getExecutablePath | ( | ) |
Absolute path of the running executable.
| std::filesystem::path RST::System::getExecutableDirectory | ( | ) |
Directory of the running executable.
| std::filesystem::path RST::System::getHomeDirectory | ( | ) |
Home directory of the current user.
|
noexcept |
Number of logical cores, at least 1.
| std::string RST::System::getCpuName | ( | ) |
CPU model name, or an empty string if unknown.
|
constexprnoexcept |
Architecture the program was built for: x86_64, x86, arm64, arm, riscv, wasm or unknown.
|
noexcept |
|
noexcept |
|
noexcept |
Physical memory used by this process.
|
noexcept |
Highest physical memory used by this process so far.
| std::string RST::System::getOSName | ( | ) |
Operating system family, such as Linux or Windows 64-bit.
| std::string RST::System::getHostName | ( | ) |
Network name of this computer, or an empty string on failure.
| std::uint64_t RST::System::getTotalDiskSpace | ( | const std::string & | path = "/" | ) |
| std::uint64_t RST::System::getAvailableDiskSpace | ( | const std::string & | path = "/" | ) |