mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-09-26 19:28:36 +00:00
Add std::bit_cast fallback for Helpers::bit_cast and run clang-format
This commit is contained in:
parent
e9b3b7c2a2
commit
88e3eb1558
1 changed files with 119 additions and 121 deletions
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include <cstdarg>
|
||||
#include <climits>
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
@ -8,8 +8,16 @@
|
|||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "termcolor.hpp"
|
||||
|
||||
// We have to detect and special-case AppleClang at the moment since its C++20 support is finicky and doesn't quite support std::bit_cast
|
||||
#if defined(__clang__) && defined(__apple_build_version__)
|
||||
#define HELPERS_APPLE_CLANG
|
||||
#else
|
||||
#include <bit>
|
||||
#endif
|
||||
|
||||
using u8 = std::uint8_t;
|
||||
using u16 = std::uint16_t;
|
||||
using u32 = std::uint32_t;
|
||||
|
@ -45,15 +53,12 @@ namespace Helpers {
|
|||
|
||||
static std::vector<u8> loadROM(std::string directory) {
|
||||
std::ifstream file(directory, std::ios::binary);
|
||||
if (file.fail())
|
||||
panic("Couldn't read %s", directory.c_str());
|
||||
if (file.fail()) panic("Couldn't read %s", directory.c_str());
|
||||
|
||||
std::vector<u8> ROM;
|
||||
|
||||
file.unsetf(std::ios::skipws);
|
||||
ROM.insert(ROM.begin(),
|
||||
std::istream_iterator<uint8_t>(file),
|
||||
std::istream_iterator<uint8_t>());
|
||||
ROM.insert(ROM.begin(), std::istream_iterator<uint8_t>(file), std::istream_iterator<uint8_t>());
|
||||
|
||||
file.close();
|
||||
|
||||
|
@ -65,7 +70,6 @@ namespace Helpers {
|
|||
#ifdef NDEBUG
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -117,9 +121,7 @@ namespace Helpers {
|
|||
}
|
||||
|
||||
/// Check if a bit "bit" of value is set
|
||||
static constexpr bool isBitSet (u32 value, int bit) {
|
||||
return (value >> bit) & 1;
|
||||
}
|
||||
static constexpr bool isBitSet(u32 value, int bit) { return (value >> bit) & 1; }
|
||||
|
||||
/// rotate number right
|
||||
template <typename T>
|
||||
|
@ -149,29 +151,25 @@ namespace Helpers {
|
|||
}
|
||||
|
||||
// For values < 0x99
|
||||
static constexpr inline u8 incBCDByte(u8 value) {
|
||||
return ((value & 0xf) == 0x9) ? value + 7 : value + 1;
|
||||
}
|
||||
// Use this helper for platforms that lack a working std::bit_cast implementation
|
||||
// TODO: Replace this with C++20 version if available
|
||||
static constexpr inline u8 incBCDByte(u8 value) { return ((value & 0xf) == 0x9) ? value + 7 : value + 1; }
|
||||
|
||||
#ifdef HELPERS_APPLE_CLANG
|
||||
template <class To, class From>
|
||||
constexpr To bit_cast(const From& from) noexcept {
|
||||
return *reinterpret_cast<const To*>(&from);
|
||||
}
|
||||
};
|
||||
#else
|
||||
template <class To, class From>
|
||||
constexpr To bit_cast(const From& from) noexcept {
|
||||
return std::bit_cast<To, From>(from);
|
||||
}
|
||||
#endif
|
||||
}; // namespace Helpers
|
||||
|
||||
// UDLs for memory size values
|
||||
constexpr size_t operator""_KB(unsigned long long int x) {
|
||||
return 1024ULL * x;
|
||||
}
|
||||
|
||||
constexpr size_t operator""_MB(unsigned long long int x) {
|
||||
return 1024_KB * x;
|
||||
}
|
||||
|
||||
constexpr size_t operator""_GB(unsigned long long int x) {
|
||||
return 1024_MB * x;
|
||||
}
|
||||
constexpr size_t operator""_KB(unsigned long long int x) { return 1024ULL * x; }
|
||||
constexpr size_t operator""_MB(unsigned long long int x) { return 1024_KB * x; }
|
||||
constexpr size_t operator""_GB(unsigned long long int x) { return 1024_MB * x; }
|
||||
|
||||
// useful macros
|
||||
// likely/unlikely
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue