xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
operating_system.h
Go to the documentation of this file.
1
4#pragma once
5#include <map>
6#include <vector>
7#include "object.h"
8#include "platform_id.h"
9#include "ustring.h"
10#include "version.h"
11
13namespace xtd {
23 class operating_system final : public object {
24 public:
31
39
48
56 operating_system(xtd::platform_id platform, const xtd::version& version, const xtd::ustring& service_pack, const xtd::ustring& desktop_environment, bool is_64_bit) : platform_(platform), version_(version), service_pack_(service_pack), desktop_environment_(desktop_environment), is_64_bit_(is_64_bit) {}
57
59 operating_system() = default;
60 operating_system(const operating_system&) = default;
61 operating_system& operator=(const operating_system&) = default;
62 friend std::ostream& operator <<(std::ostream& os, const operating_system& operating_system) noexcept {return os << operating_system.to_string();}
64
70 xtd::ustring desktop_environment() const {return desktop_environment_;}
71
74 bool is_64_bit() const noexcept {return is_64_bit_;}
75
78 bool is_macos_platform() const noexcept {return platform_ == xtd::platform_id::macos || platform_ == xtd::platform_id::ios;}
79
82 bool is_linux_platform() const noexcept {return platform_ == xtd::platform_id::unix || platform_ == xtd::platform_id::android;}
83
86 bool is_windows_platform() const noexcept {return platform_ == xtd::platform_id::win32_nt || platform_ == xtd::platform_id::win32s || platform_ == xtd::platform_id::win32_windows || platform_ == xtd::platform_id::win_ce || platform_ == xtd::platform_id::xbox;}
87
90 xtd::ustring name() const noexcept {
91 static std::map<xtd::platform_id, xtd::ustring> operating_system_names {{platform_id::win32s, "Microsoft Win32S"}, {platform_id::win32_windows, "Microsoft Windows 95"}, {platform_id::win32_nt, "Microsoft Windows NT"}, {platform_id::win_ce, "Microsoft Windows CE"}, {platform_id::unix, "Unix"}, {platform_id::xbox, "Xbox"}, {platform_id::macos, "macOS"}, {platform_id::ios, "iOS"}, {platform_id::android, "Android"}, {platform_id::unknown, "<Unknown>"}};
92 if (platform_ == xtd::platform_id::win32_windows && (version_.major() > 4 || (version_.major() == 4 && version_.minor() > 0))) return "Microsoft Windows 98";
93 return operating_system_names[platform_];
94 }
95
98 xtd::platform_id platform() const noexcept {return platform_;}
99
104 xtd::ustring service_pack() const noexcept {return service_pack_;}
105
109 const xtd::version& version() const noexcept {return version_;}
110
114 xtd::ustring version_string() const noexcept {
115 if (!version_string_.empty()) return version_string_;
116 version_string_ = ustring::format("{} {}", name(), version_.to_string(3));
117 if (!service_pack_.empty()) version_string_ += ustring::format(" {}", service_pack());
118 return version_string_;
119 }
120
123 xtd::ustring to_string() const noexcept {return version_string();}
124
125 private:
127 xtd::version version_;
128 xtd::ustring service_pack_;
129 xtd::ustring desktop_environment_;
130 bool is_64_bit_ = false;
131 mutable xtd::ustring version_string_;
132 };
133}
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents information about an operating system, such as the version and platform identifier....
Definition: operating_system.h:23
operating_system(xtd::platform_id platform, const xtd::version &version, const xtd::ustring &service_pack)
Initializes a new instance of the operating_system class, using the specified platform identifier val...
Definition: operating_system.h:38
xtd::ustring desktop_environment() const
Gets the desktop environment .
Definition: operating_system.h:70
bool is_linux_platform() const noexcept
Determines whether the current platform is Unix family.
Definition: operating_system.h:82
const xtd::version & version() const noexcept
Gets a xtd::version object that identifies the operating system.
Definition: operating_system.h:109
xtd::ustring to_string() const noexcept
Converts the value of this operating_system object to its equivalent string representation.
Definition: operating_system.h:123
operating_system(xtd::platform_id platform, const xtd::version &version, const xtd::ustring &service_pack, const xtd::ustring &desktop_environment, bool is_64_bit)
Initializes a new instance of the operating_system class, using the specified platform identifier val...
Definition: operating_system.h:56
operating_system(xtd::platform_id platform, const xtd::version &version)
Initializes a new instance of the operating_system class, using the specified platform identifier val...
Definition: operating_system.h:30
operating_system(xtd::platform_id platform, const xtd::version &version, const xtd::ustring &service_pack, const xtd::ustring &desktop_environment)
Initializes a new instance of the operating_system class, using the specified platform identifier val...
Definition: operating_system.h:47
xtd::ustring version_string() const noexcept
Gets the concatenated string representation of the platform identifier, version, and service pack tha...
Definition: operating_system.h:114
bool is_macos_platform() const noexcept
Determines whether the current platform is macOS family.
Definition: operating_system.h:78
bool is_windows_platform() const noexcept
Determines whether the current platform is Windows family.
Definition: operating_system.h:86
bool is_64_bit() const noexcept
Determines whether the current operating system is a 64-bit operating system.
Definition: operating_system.h:74
xtd::platform_id platform() const noexcept
Gets a xtd::platform_id enumeration value that identifies the operating system platform.
Definition: operating_system.h:98
xtd::ustring name() const noexcept
Gets the concatenated string representation of the platform identifier.
Definition: operating_system.h:90
xtd::ustring service_pack() const noexcept
Gets the service pack version represented by this operating_system object.
Definition: operating_system.h:104
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition: version.h:93
int32_t minor() const noexcept
Gets the value of the minor component of the version number for the current xtd::version object.
int32_t major() const noexcept
Gets the value of the major component of the version number for the current xtd::version object.
xtd::ustring to_string() const noexcept override
Converts the value of the current xtd::version object to its equivalent xtd::ustring representation.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
platform_id
Identifies the operating system, or platform, supported by an assembly.
Definition: platform_id.h:17
@ win_ce
The operating system is Windows CE.
@ win32s
The operating system is Win32s. Win32s is a layer that runs on 16-bit versions of Windows to provide ...
@ xbox
The development platform is Xbox 360.
@ win32_nt
The operating system is Windows NT or later.
@ macos
The operating system is Macintosh.
@ unix
The operating system is Unix.
@ ios
The operating system is IOs Apple.
@ unknown
The operating system is unknown.
@ android
The operating system is Android.
@ win32_windows
The operating system is Windows 95 or Windows 98.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.
Contains xtd::platform_id enum class.
Contains xtd::ustring class.
Contains xtd::version class.