| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //================================================================================================== | ||
| 2 | /* | ||
| 3 | SPY - C++ Informations Broker | ||
| 4 | Copyright : SPY Project Contributors | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | #if defined(__APPLE__) || defined(__APPLE_CC__) || defined(macintosh) | ||
| 11 | #include <AvailabilityMacros.h> | ||
| 12 | #endif | ||
| 13 | |||
| 14 | namespace spy::_ | ||
| 15 | { | ||
| 16 | enum class systems | ||
| 17 | { | ||
| 18 | undefined_ = -1, | ||
| 19 | android_, | ||
| 20 | bsd_, | ||
| 21 | cygwin_, | ||
| 22 | ios_, | ||
| 23 | linux_, | ||
| 24 | macos_, | ||
| 25 | unix_, | ||
| 26 | windows_ | ||
| 27 | }; | ||
| 28 | |||
| 29 | template<systems OpSys> struct os_info | ||
| 30 | { | ||
| 31 | static constexpr systems vendor = OpSys; | ||
| 32 | |||
| 33 | inline constexpr explicit operator bool() const noexcept; | ||
| 34 | |||
| 35 | template<systems C2> constexpr bool operator==(os_info<C2> const&) const noexcept | ||
| 36 | { | ||
| 37 | return C2 == vendor; | ||
| 38 | } | ||
| 39 | }; | ||
| 40 | |||
| 41 | 1 | template<_::stream OS, systems OpSys> auto& operator<<(OS& os, os_info<OpSys> const&) | |
| 42 | { | ||
| 43 | if(OpSys == systems::android_) return os << "Android"; | ||
| 44 | if(OpSys == systems::bsd_) return os << "BSD"; | ||
| 45 | if(OpSys == systems::cygwin_) return os << "Cygwin"; | ||
| 46 | if(OpSys == systems::ios_) return os << "iOs"; | ||
| 47 | 1 | if(OpSys == systems::linux_) return os << "Linux"; | |
| 48 | if(OpSys == systems::macos_) return os << "MacOs"; | ||
| 49 | if(OpSys == systems::unix_) return os << "UNIX"; | ||
| 50 | if(OpSys == systems::windows_) return os << "Windows"; | ||
| 51 | |||
| 52 | return os << "Undefined Operating System"; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | namespace spy | ||
| 57 | { | ||
| 58 | #if defined(__ANDROID__) | ||
| 59 | #define SPY_OS_IS_ANDROID | ||
| 60 | using os_type = _::os_info<_::systems::android_>; | ||
| 61 | #elif defined(BSD) || defined(_SYSTYPE_BSD) | ||
| 62 | #define SPY_OS_IS_BSD | ||
| 63 | using os_type = _::os_info<_::systems::bsd_>; | ||
| 64 | #elif defined(__CYGWIN__) | ||
| 65 | #define SPY_OS_IS_CYGWIN | ||
| 66 | using os_type = _::os_info<_::systems::cygwin_>; | ||
| 67 | #elif defined(__APPLE__) && defined(__MACH__) && \ | ||
| 68 | defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) | ||
| 69 | #define SPY_OS_IS_IOS | ||
| 70 | using os_type = _::os_info<_::systems::ios_>; | ||
| 71 | #elif defined(linux) || defined(__linux) | ||
| 72 | #define SPY_OS_IS_LINUX | ||
| 73 | using os_type = _::os_info<_::systems::linux_>; | ||
| 74 | #elif defined(macintosh) || defined(Macintosh) || (defined(__APPLE__) && defined(__MACH__)) | ||
| 75 | #define SPY_OS_IS_MACOS | ||
| 76 | using os_type = _::os_info<_::systems::macos_>; | ||
| 77 | #elif defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) | ||
| 78 | #define SPY_OS_IS_UNIX | ||
| 79 | using os_type = _::os_info<_::systems::unix_>; | ||
| 80 | #elif defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || \ | ||
| 81 | defined(__WINDOWS__) | ||
| 82 | #define SPY_OS_IS_WINDOWS | ||
| 83 | using os_type = _::os_info<_::systems::windows_>; | ||
| 84 | #else | ||
| 85 | #define SPY_OS_IS_UNKNOWN | ||
| 86 | using os_type = _::os_info<_::systems::undefined_>; | ||
| 87 | #endif | ||
| 88 | |||
| 89 | //================================================================================================ | ||
| 90 | //! @ingroup spy_platform | ||
| 91 | //! @brief OS reporting value | ||
| 92 | //! | ||
| 93 | //! The `spy::operating_system` object can be compared to any other OS related value to verify | ||
| 94 | //! if the code being compiled is compiled on a given Operating Systems. | ||
| 95 | //! | ||
| 96 | //! Additionally, any of the OS related value are convertible to `bool`. They evaluates to `true` | ||
| 97 | //! if they matches the correct OS currently used. | ||
| 98 | //! | ||
| 99 | //! @groupheader{Supported Value} | ||
| 100 | //! | ||
| 101 | //! Name | Operating System | ||
| 102 | //! --------------- | ------------- | ||
| 103 | //! `spy::android_` | Android | ||
| 104 | //! `spy::bsd` | BSD | ||
| 105 | //! `spy::cygwin_` | CYGWIN | ||
| 106 | //! `spy::ios_` | iOS | ||
| 107 | //! `spy::linux_` | Linux | ||
| 108 | //! `spy::macos_` | MacOS | ||
| 109 | //! `spy::unix_` | UNIX | ||
| 110 | //! `spy::windows_` | Windows | ||
| 111 | //! | ||
| 112 | //! @groupheader{Example} | ||
| 113 | //! @godbolt{samples/os.cpp} | ||
| 114 | //================================================================================================ | ||
| 115 | constexpr inline os_type operating_system; | ||
| 116 | } | ||
| 117 | |||
| 118 | namespace spy::_ | ||
| 119 | { | ||
| 120 | template<systems OS> inline constexpr os_info<OS>::operator bool() const noexcept | ||
| 121 | { | ||
| 122 | return spy::operating_system == *this; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | namespace spy | ||
| 127 | { | ||
| 128 | constexpr inline auto android_ = _::os_info<_::systems::android_> {}; | ||
| 129 | constexpr inline auto bsd_ = _::os_info<_::systems::bsd_> {}; | ||
| 130 | constexpr inline auto cygwin_ = _::os_info<_::systems::cygwin_> {}; | ||
| 131 | constexpr inline auto ios_ = _::os_info<_::systems::ios_> {}; | ||
| 132 | constexpr inline auto linux_ = _::os_info<_::systems::linux_> {}; | ||
| 133 | constexpr inline auto macos_ = _::os_info<_::systems::macos_> {}; | ||
| 134 | constexpr inline auto unix_ = _::os_info<_::systems::unix_> {}; | ||
| 135 | constexpr inline auto windows_ = _::os_info<_::systems::windows_> {}; | ||
| 136 | } | ||
| 137 | |||
| 138 | namespace spy::supports | ||
| 139 | { | ||
| 140 | #if defined(SPY_DOXYGEN_INVOKED) | ||
| 141 | //================================================================================================ | ||
| 142 | //! @ingroup spy_platform | ||
| 143 | //! @brief POSIX supports indicator. | ||
| 144 | //! | ||
| 145 | //! Evaluates to `true` if current OS supports POSIX system calls and functions. | ||
| 146 | //! | ||
| 147 | //! @groupheader{Example} | ||
| 148 | //! @godbolt{samples/posix.cpp} | ||
| 149 | //================================================================================================ | ||
| 150 | constexpr inline auto posix_ = _::implementation_defined {}; | ||
| 151 | #else | ||
| 152 | #if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (_POSIX_C_SOURCE >= 200112L) || \ | ||
| 153 | (_XOPEN_SOURCE >= 600) | ||
| 154 | #define SPY_SUPPORTS_POSIX | ||
| 155 | constexpr inline auto posix_ = true; | ||
| 156 | #else | ||
| 157 | constexpr inline auto posix_ = false; | ||
| 158 | #endif | ||
| 159 | #endif | ||
| 160 | } | ||
| 161 |