RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RST::System Namespace Reference

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 path, or 0 on failure.

std::uint64_t getTotalDiskSpace (const std::string &path="/")
 
std::uint64_t getAvailableDiskSpace (const std::string &path="/")
 

Detailed Description

Portable access to system information, environment variables, files and paths.

Nothing throws: failures return std::nullopt, false, 0 or an empty value.

Function Documentation

◆ getEnv()

std::optional< std::string > RST::System::getEnv ( std::string_view  name)

Value of the variable name, or std::nullopt if it is not set.

◆ setEnv()

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.

◆ unsetEnv()

bool RST::System::unsetEnv ( std::string_view  name)

Removes name from the environment; returns false on failure.

◆ readFile()

std::optional< std::string > RST::System::readFile ( const std::filesystem::path &  path)

Content of the file, or std::nullopt if it cannot be read.

◆ writeFile()

bool RST::System::writeFile ( const std::filesystem::path &  path,
std::string_view  content 
)

Creates or replaces the file with content; returns false on failure.

◆ appendFile()

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.

◆ getExecutablePath()

std::filesystem::path RST::System::getExecutablePath ( )

Absolute path of the running executable.

◆ getExecutableDirectory()

std::filesystem::path RST::System::getExecutableDirectory ( )

Directory of the running executable.

◆ getHomeDirectory()

std::filesystem::path RST::System::getHomeDirectory ( )

Home directory of the current user.

◆ getCpuCores()

std::size_t RST::System::getCpuCores ( )
noexcept

Number of logical cores, at least 1.

Examples
quickstart.cpp.

◆ getCpuName()

std::string RST::System::getCpuName ( )

CPU model name, or an empty string if unknown.

◆ getArchitecture()

constexpr std::string_view RST::System::getArchitecture ( )
constexprnoexcept

Architecture the program was built for: x86_64, x86, arm64, arm, riscv, wasm or unknown.

◆ getTotalRAM()

std::uint64_t RST::System::getTotalRAM ( )
noexcept

◆ getAvailableRAM()

std::uint64_t RST::System::getAvailableRAM ( )
noexcept

◆ getProcessMemoryUsage()

std::uint64_t RST::System::getProcessMemoryUsage ( )
noexcept

Physical memory used by this process.

◆ getPeakProcessMemoryUsage()

std::uint64_t RST::System::getPeakProcessMemoryUsage ( )
noexcept

Highest physical memory used by this process so far.

◆ getOSName()

std::string RST::System::getOSName ( )

Operating system family, such as Linux or Windows 64-bit.

Examples
quickstart.cpp.

◆ getHostName()

std::string RST::System::getHostName ( )

Network name of this computer, or an empty string on failure.

◆ getTotalDiskSpace()

std::uint64_t RST::System::getTotalDiskSpace ( const std::string &  path = "/")

◆ getAvailableDiskSpace()

std::uint64_t RST::System::getAvailableDiskSpace ( const std::string &  path = "/")