PatchEngine: Make PatchType an enum class

Makes the enum strongly typed. A function for retrieving the string
representation of the enum is also added, which allows hiding the array
that contains all of the strings from view (i.e. we operate on the API,
not the exposed internals). This also allows us to bounds check any
querying for the strings.
This commit is contained in:
Lioncash
2018-05-13 14:10:58 -04:00
parent a166cf2481
commit 0995cfef6a
6 changed files with 53 additions and 40 deletions

View File

@ -161,24 +161,24 @@ QGroupBox* NewPatchDialog::CreateEntry(int index)
connect(byte, &QRadioButton::toggled, [this, index](bool checked) {
if (checked)
m_patch.entries[index].type = PatchEngine::PATCH_8BIT;
m_patch.entries[index].type = PatchEngine::PatchType::Patch8Bit;
});
connect(word, &QRadioButton::toggled, [this, index](bool checked) {
if (checked)
m_patch.entries[index].type = PatchEngine::PATCH_16BIT;
m_patch.entries[index].type = PatchEngine::PatchType::Patch16Bit;
});
connect(dword, &QRadioButton::toggled, [this, index](bool checked) {
if (checked)
m_patch.entries[index].type = PatchEngine::PATCH_32BIT;
m_patch.entries[index].type = PatchEngine::PatchType::Patch32Bit;
});
auto entry_type = m_patch.entries[index].type;
byte->setChecked(entry_type == PatchEngine::PATCH_8BIT);
word->setChecked(entry_type == PatchEngine::PATCH_16BIT);
dword->setChecked(entry_type == PatchEngine::PATCH_32BIT);
byte->setChecked(entry_type == PatchEngine::PatchType::Patch8Bit);
word->setChecked(entry_type == PatchEngine::PatchType::Patch16Bit);
dword->setChecked(entry_type == PatchEngine::PatchType::Patch32Bit);
offset->setText(
QStringLiteral("%1").arg(m_patch.entries[index].address, 10, 16, QLatin1Char('0')));