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

View File

@ -100,7 +100,7 @@ std::ostream& operator<<(std::ostream& os, CPUCore core)
void DoState(PointerWrap& p)
{
// 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)
// and because the values it's changing have been added to CoreTiming::DoState, so it might
// conflict to mess with them here.

View File

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

View File

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