mirror of
https://github.com/RPCSX/rpcsx.git
synced 2025-12-06 07:12:14 +01:00
utilities: fix refl::calcFieldCount for enum
add unordered_vector utility modernize hexdump
This commit is contained in:
parent
7d0f277ad5
commit
b012964099
|
|
@ -139,11 +139,11 @@ constexpr auto calcFieldCount() {
|
||||||
} else {
|
} else {
|
||||||
constexpr auto c = getNameOf<EnumT(N)>()[0];
|
constexpr auto c = getNameOf<EnumT(N)>()[0];
|
||||||
if constexpr (requires { EnumT::Count; }) {
|
if constexpr (requires { EnumT::Count; }) {
|
||||||
return EnumT::Count;
|
return static_cast<std::size_t>(EnumT::Count);
|
||||||
} else if constexpr (requires { EnumT::_count; }) {
|
} else if constexpr (requires { EnumT::_count; }) {
|
||||||
return EnumT::_count;
|
return static_cast<std::size_t>(EnumT::_count);
|
||||||
} else if constexpr (requires { EnumT::count; }) {
|
} else if constexpr (requires { EnumT::count; }) {
|
||||||
return EnumT::count;
|
return static_cast<std::size_t>(EnumT::count);
|
||||||
} else if constexpr (!requires { getNameOf<EnumT(N)>()[0]; }) {
|
} else if constexpr (!requires { getNameOf<EnumT(N)>()[0]; }) {
|
||||||
return N;
|
return N;
|
||||||
} else if constexpr (c >= '0' && c <= '9') {
|
} else if constexpr (c >= '0' && c <= '9') {
|
||||||
|
|
|
||||||
29
rx/include/rx/unordered_vector.hpp
Normal file
29
rx/include/rx/unordered_vector.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace rx {
|
||||||
|
template <typename VectorT>
|
||||||
|
void unordered_vector_erase(VectorT &vector, std::size_t pos) {
|
||||||
|
if (pos + 1 == vector.size()) {
|
||||||
|
vector.pop_back();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::swap(vector[pos], vector.back());
|
||||||
|
vector.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename VectorT, typename Value>
|
||||||
|
void unordered_vector_insert(VectorT &vector, std::size_t pos, Value &&value) {
|
||||||
|
bool isLast = pos + 1 == vector.size();
|
||||||
|
vector.push_back(std::move(value));
|
||||||
|
|
||||||
|
if (isLast) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::swap(vector[pos], vector.back());
|
||||||
|
}
|
||||||
|
} // namespace rx
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "hexdump.hpp"
|
#include "hexdump.hpp"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <print>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
void rx::hexdump(std::span<std::byte> bytes) {
|
void rx::hexdump(std::span<std::byte> bytes) {
|
||||||
|
|
@ -16,13 +17,13 @@ void rx::hexdump(std::span<std::byte> bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
flockfile(stderr);
|
flockfile(stderr);
|
||||||
std::fprintf(stderr, "%s ", std::string(sizeWidth, ' ').c_str());
|
std::print(stderr, "{} ", std::string(sizeWidth, ' '));
|
||||||
for (unsigned i = 0; i < 16; ++i) {
|
for (unsigned i = 0; i < 16; ++i) {
|
||||||
std::fprintf(stderr, " %02x", i);
|
std::print(stderr, " {:02x}", i);
|
||||||
}
|
}
|
||||||
std::fprintf(stderr, "\n%s ", std::string(sizeWidth, ' ').c_str());
|
std::print(stderr, "\n{} ", std::string(sizeWidth, ' '));
|
||||||
for (unsigned i = 0; i < 16; ++i) {
|
for (unsigned i = 0; i < 16; ++i) {
|
||||||
std::fprintf(stderr, " --");
|
std::print(stderr, " --");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::byte zeros[16]{};
|
std::byte zeros[16]{};
|
||||||
|
|
@ -36,7 +37,7 @@ void rx::hexdump(std::span<std::byte> bytes) {
|
||||||
if (std::memcmp(bytes.data() + i, zeros, 16) == 0) {
|
if (std::memcmp(bytes.data() + i, zeros, 16) == 0) {
|
||||||
if (!dotsPrinted) {
|
if (!dotsPrinted) {
|
||||||
dotsPrinted = true;
|
dotsPrinted = true;
|
||||||
std::printf("\n...");
|
std::print(stderr, "\n...");
|
||||||
}
|
}
|
||||||
i += 15;
|
i += 15;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -44,22 +45,22 @@ void rx::hexdump(std::span<std::byte> bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dotsPrinted) {
|
if (!dotsPrinted) {
|
||||||
std::fprintf(stderr, " | ");
|
std::print(stderr, " | ");
|
||||||
|
|
||||||
for (std::size_t j = i - 16; j < i; ++j) {
|
for (std::size_t j = i - 16; j < i; ++j) {
|
||||||
auto c = unsigned(bytes[j]);
|
auto c = unsigned(bytes[j]);
|
||||||
std::fprintf(stderr, "%c",
|
std::print(stderr, "{:c}",
|
||||||
(std::isprint(c) && c != '\n') ? c : '.');
|
(std::isprint(c) && c != '\n') ? c : '.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::fprintf(stderr, "\n");
|
std::println(stderr, "");
|
||||||
std::fprintf(stderr, "%0*zx ", sizeWidth, i);
|
std::print(stderr, "{:0{}x} ", i, sizeWidth);
|
||||||
wasAllZeros = true;
|
wasAllZeros = true;
|
||||||
dotsPrinted = false;
|
dotsPrinted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fprintf(stderr, " %02x", unsigned(bytes[i]));
|
std::print(stderr, " {:02x}", unsigned(bytes[i]));
|
||||||
|
|
||||||
if (bytes[i] != std::byte{0}) {
|
if (bytes[i] != std::byte{0}) {
|
||||||
wasAllZeros = false;
|
wasAllZeros = false;
|
||||||
|
|
@ -68,18 +69,18 @@ void rx::hexdump(std::span<std::byte> bytes) {
|
||||||
|
|
||||||
if (!bytes.empty()) {
|
if (!bytes.empty()) {
|
||||||
for (std::size_t i = 0; i < (16 - (bytes.size() % 16)) % 16; ++i) {
|
for (std::size_t i = 0; i < (16 - (bytes.size() % 16)) % 16; ++i) {
|
||||||
std::fprintf(stderr, " ");
|
std::print(stderr, " ");
|
||||||
}
|
}
|
||||||
std::fprintf(stderr, " | ");
|
std::print(stderr, " | ");
|
||||||
|
|
||||||
for (std::size_t j = bytes.size() -
|
for (std::size_t j = bytes.size() -
|
||||||
std::min(bytes.size(),
|
std::min(bytes.size(),
|
||||||
(bytes.size() % 16 ? bytes.size() % 16 : 16));
|
(bytes.size() % 16 ? bytes.size() % 16 : 16));
|
||||||
j < bytes.size(); ++j) {
|
j < bytes.size(); ++j) {
|
||||||
auto c = unsigned(bytes[j]);
|
auto c = unsigned(bytes[j]);
|
||||||
std::fprintf(stderr, "%c", (std::isprint(c) && c != '\n') ? c : '.');
|
std::print(stderr, "{:c}", (std::isprint(c) && c != '\n') ? c : '.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::fprintf(stderr, "\n");
|
std::println(stderr, "");
|
||||||
funlockfile(stderr);
|
funlockfile(stderr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue