libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <bit>
14#include <limits>
15#include <algorithm>
16#include <type_traits>
17#include <cstdint>
18#include <promeki/namespace.h>
19#include <promeki/platform.h>
20#include <promeki/string.h>
21
22PROMEKI_NAMESPACE_BEGIN
23
24class String;
25
36class System {
37 public:
42 static String hostname();
43
48 static constexpr bool isLittleEndian() { return std::endian::native == std::endian::little; }
49
54 static constexpr bool isBigEndian() { return std::endian::native == std::endian::big; }
55
61 template <typename T> static void swapEndian(T &value) {
62 static_assert(std::is_arithmetic<T>::value, "swab() requires an arithmetic type");
63 constexpr size_t size = sizeof(T);
64 if constexpr (size == 1) return;
65 unsigned char *data = reinterpret_cast<unsigned char *>(&value);
66 PROMEKI_UNROLL
67 for (size_t i = 0; i < size / 2; ++i) {
68 std::swap(data[i], data[size - i - 1]);
69 }
70 return;
71 }
72
79 template <typename T, bool ValueIsBigEndian> static void makeNativeEndian(T &value) {
80 if constexpr (ValueIsBigEndian && isBigEndian()) return;
81 swab(value);
82 return;
83 }
84
91 static String demangleSymbol(const char *symbol, bool useCache = true);
92};
93
94PROMEKI_NAMESPACE_END
95
96#endif // PROMEKI_ENABLE_CORE