Convert PointerWrap::Mode to enum class

This commit is contained in:
Dentomologist 2022-05-21 21:18:27 -07:00
parent f6b9acccfc
commit c8e20c569b
4 changed files with 37 additions and 37 deletions

View File

@ -38,12 +38,12 @@
class PointerWrap class PointerWrap
{ {
public: public:
enum Mode enum class Mode
{ {
MODE_READ, Read,
MODE_WRITE, Write,
MODE_MEASURE, Measure,
MODE_VERIFY, Verify,
}; };
private: private:
@ -57,12 +57,12 @@ public:
{ {
} }
void SetMeasureMode() { m_mode = Mode::MODE_MEASURE; } void SetMeasureMode() { m_mode = Mode::Measure; }
void SetVerifyMode() { m_mode = Mode::MODE_VERIFY; } void SetVerifyMode() { m_mode = Mode::Verify; }
bool IsReadMode() const { return m_mode == Mode::MODE_READ; } bool IsReadMode() const { return m_mode == Mode::Read; }
bool IsWriteMode() const { return m_mode == Mode::MODE_WRITE; } bool IsWriteMode() const { return m_mode == Mode::Write; }
bool IsMeasureMode() const { return m_mode == Mode::MODE_MEASURE; } bool IsMeasureMode() const { return m_mode == Mode::Measure; }
bool IsVerifyMode() const { return m_mode == Mode::MODE_VERIFY; } bool IsVerifyMode() const { return m_mode == Mode::Verify; }
template <typename K, class V> template <typename K, class V>
void Do(std::map<K, V>& x) void Do(std::map<K, V>& x)
@ -72,7 +72,7 @@ public:
switch (m_mode) switch (m_mode)
{ {
case MODE_READ: case Mode::Read:
for (x.clear(); count != 0; --count) for (x.clear(); count != 0; --count)
{ {
std::pair<K, V> pair; std::pair<K, V> pair;
@ -82,9 +82,9 @@ public:
} }
break; break;
case MODE_WRITE: case Mode::Write:
case MODE_MEASURE: case Mode::Measure:
case MODE_VERIFY: case Mode::Verify:
for (auto& elem : x) for (auto& elem : x)
{ {
Do(elem.first); Do(elem.first);
@ -102,7 +102,7 @@ public:
switch (m_mode) switch (m_mode)
{ {
case MODE_READ: case Mode::Read:
for (x.clear(); count != 0; --count) for (x.clear(); count != 0; --count)
{ {
V value; V value;
@ -111,9 +111,9 @@ public:
} }
break; break;
case MODE_WRITE: case Mode::Write:
case MODE_MEASURE: case Mode::Measure:
case MODE_VERIFY: case Mode::Verify:
for (const V& val : x) for (const V& val : x)
{ {
Do(val); Do(val);
@ -161,7 +161,7 @@ public:
switch (m_mode) switch (m_mode)
{ {
case MODE_READ: case Mode::Read:
if (present) if (present)
{ {
x = std::make_optional<T>(); x = std::make_optional<T>();
@ -173,9 +173,9 @@ public:
} }
break; break;
case MODE_WRITE: case Mode::Write:
case MODE_MEASURE: case Mode::Measure:
case MODE_VERIFY: case Mode::Verify:
if (present) if (present)
Do(x.value()); Do(x.value());
@ -343,18 +343,18 @@ private:
switch (m_mode) switch (m_mode)
{ {
case MODE_READ: case Mode::Read:
memcpy(data, *m_ptr_current, size); memcpy(data, *m_ptr_current, size);
break; break;
case MODE_WRITE: case Mode::Write:
memcpy(*m_ptr_current, data, size); memcpy(*m_ptr_current, data, size);
break; break;
case MODE_MEASURE: case Mode::Measure:
break; break;
case MODE_VERIFY: case Mode::Verify:
DEBUG_ASSERT_MSG(COMMON, !memcmp(data, *m_ptr_current, size), DEBUG_ASSERT_MSG(COMMON, !memcmp(data, *m_ptr_current, size),
"Savestate verification failure: buf {} != {} (size {}).\n", fmt::ptr(data), "Savestate verification failure: buf {} != {} (size {}).\n", fmt::ptr(data),
fmt::ptr(*m_ptr_current), size); fmt::ptr(*m_ptr_current), size);

View File

@ -100,7 +100,7 @@ std::ostream& operator<<(std::ostream& os, CPUCore core)
void DoState(PointerWrap& p) void DoState(PointerWrap& p)
{ {
// some of this code has been disabled, because // some of this code has been disabled, because
// it changes registers even in MODE_MEASURE (which is suspicious and seems like it could cause // it changes registers even in Mode::Measure (which is suspicious and seems like it could cause
// desyncs) // desyncs)
// and because the values it's changing have been added to CoreTiming::DoState, so it might // and because the values it's changing have been added to CoreTiming::DoState, so it might
// conflict to mess with them here. // conflict to mess with them here.

View File

@ -226,7 +226,7 @@ void LoadFromBuffer(std::vector<u8>& buffer)
Core::RunOnCPUThread( Core::RunOnCPUThread(
[&] { [&] {
u8* ptr = buffer.data(); u8* ptr = buffer.data();
PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::MODE_READ); PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::Read);
DoState(p); DoState(p);
}, },
true); true);
@ -237,14 +237,14 @@ void SaveToBuffer(std::vector<u8>& buffer)
Core::RunOnCPUThread( Core::RunOnCPUThread(
[&] { [&] {
u8* ptr = nullptr; u8* ptr = nullptr;
PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::MODE_MEASURE); PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::Measure);
DoState(p_measure); DoState(p_measure);
const size_t buffer_size = reinterpret_cast<size_t>(ptr); const size_t buffer_size = reinterpret_cast<size_t>(ptr);
buffer.resize(buffer_size); buffer.resize(buffer_size);
ptr = buffer.data(); ptr = buffer.data();
PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::MODE_WRITE); PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::Write);
DoState(p); DoState(p);
}, },
true); true);
@ -412,7 +412,7 @@ void SaveAs(const std::string& filename, bool wait)
[&] { [&] {
// Measure the size of the buffer. // Measure the size of the buffer.
u8* ptr = nullptr; u8* ptr = nullptr;
PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::MODE_MEASURE); PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::Measure);
DoState(p_measure); DoState(p_measure);
const size_t buffer_size = reinterpret_cast<size_t>(ptr); const size_t buffer_size = reinterpret_cast<size_t>(ptr);
@ -422,7 +422,7 @@ void SaveAs(const std::string& filename, bool wait)
std::lock_guard lk(g_cs_current_buffer); std::lock_guard lk(g_cs_current_buffer);
g_current_buffer.resize(buffer_size); g_current_buffer.resize(buffer_size);
ptr = g_current_buffer.data(); ptr = g_current_buffer.data();
PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::MODE_WRITE); PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::Write);
DoState(p); DoState(p);
is_write_mode = p.IsWriteMode(); is_write_mode = p.IsWriteMode();
} }
@ -591,7 +591,7 @@ void LoadAs(const std::string& filename)
if (!buffer.empty()) if (!buffer.empty())
{ {
u8* ptr = buffer.data(); u8* ptr = buffer.data();
PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::MODE_READ); PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::Read);
DoState(p); DoState(p);
loaded = true; loaded = true;
loadedSuccessfully = p.IsReadMode(); loadedSuccessfully = p.IsReadMode();

View File

@ -230,14 +230,14 @@ bool GameFileCache::SyncCacheFile(bool save)
{ {
// Measure the size of the buffer. // Measure the size of the buffer.
u8* ptr = nullptr; u8* ptr = nullptr;
PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::MODE_MEASURE); PointerWrap p_measure(&ptr, 0, PointerWrap::Mode::Measure);
DoState(&p_measure); DoState(&p_measure);
const size_t buffer_size = reinterpret_cast<size_t>(ptr); const size_t buffer_size = reinterpret_cast<size_t>(ptr);
// Then actually do the write. // Then actually do the write.
std::vector<u8> buffer(buffer_size); std::vector<u8> buffer(buffer_size);
ptr = buffer.data(); ptr = buffer.data();
PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::MODE_WRITE); PointerWrap p(&ptr, buffer_size, PointerWrap::Mode::Write);
DoState(&p, buffer_size); DoState(&p, buffer_size);
if (f.WriteBytes(buffer.data(), buffer.size())) if (f.WriteBytes(buffer.data(), buffer.size()))
success = true; success = true;
@ -248,7 +248,7 @@ bool GameFileCache::SyncCacheFile(bool save)
if (!buffer.empty() && f.ReadBytes(buffer.data(), buffer.size())) if (!buffer.empty() && f.ReadBytes(buffer.data(), buffer.size()))
{ {
u8* ptr = buffer.data(); u8* ptr = buffer.data();
PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::MODE_READ); PointerWrap p(&ptr, buffer.size(), PointerWrap::Mode::Read);
DoState(&p, buffer.size()); DoState(&p, buffer.size());
if (p.IsReadMode()) if (p.IsReadMode())
success = true; success = true;