Cbeam
Loading...
Searching...
No Matches
info.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2025 acrion innovations GmbH
3Authors: Stefan Zipproth, s.zipproth@acrion.ch
4
5This file is part of Cbeam, see https://github.com/acrion/cbeam and https://cbeam.org
6
7Cbeam is offered under a commercial and under the AGPL license.
8For commercial licensing, contact us at https://acrion.ch/sales. For AGPL licensing, see below.
9
10AGPL licensing:
11
12Cbeam is free software: you can redistribute it and/or modify
13it under the terms of the GNU Affero General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17Cbeam is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU Affero General Public License for more details.
21
22You should have received a copy of the GNU Affero General Public License
23along with Cbeam. If not, see <https://www.gnu.org/licenses/>.
24*/
25
26#pragma once
27
28#include <cctype> // for isdigit, std::isdigit
29#include <cstddef> // for std::size_t
30
31#include <string> // for std::allocator, std::operator+, std::string, std::char_traits, std::operator""s, std::to_string, std::string_literals
32
33namespace cbeam::platform
34{
40 inline std::string get_bit_architecture()
41 {
42 return std::to_string(sizeof(std::size_t) * 8);
43 }
44
52 inline std::string get_platform_architecture()
53 {
54 using namespace std::string_literals;
55
56#if defined(__arm__) || defined(__aarch64__)
57 return "ARM"s;
58#elif defined(__powerpc64__) || defined(__powerpc__)
59 return "PowerPC"s;
60#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
61 return "x86"s;
62#elif defined(__mips__) || defined(__mips64)
63 return "MIPS"s;
64#elif defined(__riscv)
65 return "RISC-V"s;
66#elif defined(__sparc__) || defined(__sparc)
67 return "SPARC"s;
68#elif defined(__AVR__)
69 return "AVR"s;
70#elif defined(__pic__) || defined(__PIC__)
71 return "PIC"s;
72#elif defined(ESP32) || defined(ESP8266)
73 return "ESP"s;
74#elif defined(__MSP430__)
75 return "MSP430"s;
76#elif defined(__SH1__) || defined(__SH2__) || defined(__SH3__) || defined(__SH4__)
77 return "SuperH"s;
78#else
79 return "Unknown"s;
80#endif
81 }
82
88 inline std::string get_architecture()
89 {
90 const std::string platform = get_platform_architecture();
91 const std::string bit = get_bit_architecture();
92
93 if (!platform.empty() && std::isdigit(platform.back()))
94 {
95 return platform + "_" + bit;
96 }
97 else
98 {
99 return platform + bit;
100 }
101 }
102
110 inline std::string get_kernel_name()
111 {
112 using namespace std::string_literals;
113
114#ifdef _WIN32
115 return "Windows"s;
116#elif defined(__linux__)
117 return "Linux"s; // includes Android
118#elif defined(__APPLE__)
119 return "Darwin"s; // both macOS and iOS
120#elif defined(__MACH__)
121 return "Mach"s; // macOS before Darwin
122#elif defined(__FreeBSD__)
123 return "FreeBSD"s;
124#elif defined(__sun) && defined(__SVR4)
125 return "Solaris"s;
126#elif defined(__NetBSD__)
127 return "NetBSD"s;
128#elif defined(__OpenBSD__)
129 return "OpenBSD"s;
130#elif defined(__vxworks)
131 return "VxWorks"s;
132#elif defined(__QNX__)
133 return "QNX"s;
134#else
135 return "Unknown"s;
136#endif
137 }
138}
Groups platform-specific helpers for Windows, Linux, and macOS. These utilities detect CPU architectu...
Definition clock_precision.hpp:42
std::string get_bit_architecture()
Returns the bitness (e.g. "64") of the current platform based on sizeof(std::size_t).
Definition info.hpp:40
std::string get_architecture()
Returns a string describing both the architecture and bitness (e.g. "x86_64", "ARM32").
Definition info.hpp:88
std::string get_platform_architecture()
Returns a string identifying the platform architecture (e.g., "x86", "ARM", "MIPS",...
Definition info.hpp:52
std::string get_kernel_name()
Returns the kernel or operating system name (e.g., "Windows", "Linux", "Darwin").
Definition info.hpp:110