libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <bit>
11#include <limits>
12#include <algorithm>
13#include <type_traits>
14#include <cstdint>
16#include <promeki/core/string.h>
17
19
20class String;
21
29class System {
30 public:
35 static String hostname();
36
41 static constexpr bool isLittleEndian() {
42 return std::endian::native == std::endian::little;
43 }
44
49 static constexpr bool isBigEndian() {
50 return std::endian::native == std::endian::big;
51 }
52
58 template<typename T> static void swapEndian(T &value) {
59 static_assert(std::is_arithmetic<T>::value, "swab() requires an arithmetic type");
60 constexpr size_t size = sizeof(T);
61 if constexpr (size == 1) return;
62 unsigned char *data = reinterpret_cast<unsigned char*>(&value);
63 #pragma unroll
64 for (size_t i = 0; i < size / 2; ++i) {
65 std::swap(data[i], data[size - i - 1]);
66 }
67 return;
68 }
69
76 template<typename T, bool ValueIsBigEndian> static void makeNativeEndian(T &value) {
77 if constexpr (ValueIsBigEndian && isBigEndian()) return;
78 swab(value);
79 return;
80 }
81
88 static String demangleSymbol(const char *symbol, bool useCache = true);
89};
90
92
Dynamic array container wrapping std::vector.
Definition list.h:40
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
Provides system-level utility functions.
Definition system.h:29
static constexpr bool isBigEndian()
Returns true if the host byte order is big-endian.
Definition system.h:49
static void swapEndian(T &value)
Reverses the byte order of an arithmetic value in place.
Definition system.h:58
static String hostname()
Returns the hostname of the machine.
static void makeNativeEndian(T &value)
Converts a value to native endian if its byte order differs.
Definition system.h:76
static String demangleSymbol(const char *symbol, bool useCache=true)
Demangles a C++ symbol name into a human-readable form.
static constexpr bool isLittleEndian()
Returns true if the host byte order is little-endian.
Definition system.h:41
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56