API Reference
The following section outlines the API of LibOS.
Macros
There are 2 ways to write OS-specific code:
-
OS_UNIX
Defined if OS is Unix-like.
-
OS_LINUX
Defined if OS is Linux.
-
OS_WINDOWS
Defined if OS is Windows.
Example:
#if defined(OS_WINDOWS)
/* Some Windows-only code */
#endif
Warning
The following is incorrect usage:
#if OS_WINDOWS
/* Some Windows-only code */
#endif
This will cause compilation error on non-Windows OS,
because this macro won’t be defined. Use IS_OS_WINDOWS
instead.
-
IS_OS_UNIX
Set to 1 if OS is Unix-like, 0 otherwise.
-
IS_OS_LINUX
Set to 1 if OS is Linux, 0 otherwise.
-
IS_OS_WINDOWS
Set to 1 if OS is Windows, 0 otherwise.
Tip
If your code is valid for any platform,
you may want to use os::type()
with if constexpr
.
Example:
#if IS_OS_WINDOWS
/* Some Windows-only code */
#endif
Warning
The following is incorrect usage:
#if defined(IS_OS_WINDOWS)
/* Some Windows-only code */
#endif
This will be always true, as this macro always defined. Use OS_WINDOWS
instead.
Semantic Version
-
struct version
Struct to represent semantic versioning.
Public Functions
-
inline constexpr version(unsigned major = 0, unsigned minor = 0, unsigned patch = 0) noexcept
Construct version from major, minor and patch numbers.
-
inline explicit constexpr version(std::string_view str) noexcept
Construct version from string.
Note
If string format is wrong, no exception is thrown. All successfully read values will be saved.
- Parameters
str – String with format “major.minor.patch”
-
inline constexpr bool operator<=(const version &rhs) const noexcept
Check if version is less or equal.
-
inline constexpr bool operator>=(const version &rhs) const noexcept
Check if version is greater or equal.
-
inline std::string str() const
Get version string in format “major.minor.patch”.
-
inline constexpr version(unsigned major = 0, unsigned minor = 0, unsigned patch = 0) noexcept
OS Info
-
enum os::type_t
Possible OS types.
Values:
-
enumerator undefined
-
enumerator linux
-
enumerator windows
-
enumerator macos
-
enumerator undefined
Usage:
if constexpr (os::type() == os::linux)
{
/* Code for linux (but must compile on every OS) */
}
-
std::string os::name()
Get OS name.
- Returns
Linux:
Distributive’s name (e.g.
"Ubuntu"
)"Linux"
, if/etc/os-release
not found
MacOS:
"macOS"
Windows:
"Windows"
-
std::string os::pretty_name()
Get OS name with version.
-
std::string os::codename()
Get OS codename.
- Returns
Linux: codename, if present
MacOS: codename
Windows:
""
-
std::string os::version_string()
Get OS version as string.
-
struct os::info_t
Full OS info.
Kernel Info
-
std::string os::kernel::name()
Get OS Kernel name.
- Returns
Linux:
"Linux"
MacOS:
"Darwin"
Windows:
"Windows NT"
-
std::string os::kernel::version_string()
Get OS Kernel version as string.
-
struct os::kernel::info_t
Full OS Kernel info.
Keyboard Input
-
enum os::keyboard::vk
Virtual keys.
Virtual-key code is a device-independent value defined by the system that identifies the purpose of a key. The output of sending a virtual key is affected by current keyboard layout and mapping.
Note
Some enum values are different on different OS.
Values:
-
enumerator Key_0
-
enumerator Key_1
-
enumerator Key_2
-
enumerator Key_3
-
enumerator Key_4
-
enumerator Key_5
-
enumerator Key_6
-
enumerator Key_7
-
enumerator Key_8
-
enumerator Key_9
-
enumerator A
-
enumerator B
-
enumerator C
-
enumerator D
-
enumerator E
-
enumerator F
-
enumerator G
-
enumerator H
-
enumerator I
-
enumerator J
-
enumerator K
-
enumerator L
-
enumerator M
-
enumerator N
-
enumerator O
-
enumerator P
-
enumerator Q
-
enumerator R
-
enumerator S
-
enumerator T
-
enumerator U
-
enumerator V
-
enumerator W
-
enumerator X
-
enumerator Y
-
enumerator Z
-
enumerator Shift
-
enumerator Control
-
enumerator Ctrl
-
enumerator Caps
-
enumerator Enter
-
enumerator Esc
-
enumerator Del
-
enumerator Key_0
Tip
You can shorten enum name with using os::keyboard::vk
.
Tip
You can make combination
of virtual keys
with vk::Shift + vk::A
.
-
struct os::keyboard::combination
Combination of keys.
Public Functions
-
inline combination(std::initializer_list<vk> keys = {})
Make combination from list of virtual keys.
-
inline combination &operator+=(const combination &combo)
Append a combination.
-
inline combination operator+(const combination &combo) const
Concatinate 2 combinations.
-
inline combination(std::initializer_list<vk> keys = {})
-
bool os::keyboard::is_pressed(const combination &combo)
Check if every key in combination is pressed.
-
combination os::keyboard::pressed_keys()
Get combination of all pressed keys on a keyboard.
-
void os::keyboard::press(const combination &combo)
Press combination of keys (until release())
-
void os::keyboard::release(const combination &combo)
Release combination of keys.
-
inline void os::keyboard::click(const combination &combo)