From 369d786f0e56e621401a401b8460f8efcfa3ce14 Mon Sep 17 00:00:00 2001 From: Swift Date: Sun, 7 Jun 2026 22:32:59 -0500 Subject: [PATCH] debugger: use ConvertString instead --- src/gui/wxgui/debugger/DumpCtrl.cpp | 18 ++++------ src/gui/wxgui/debugger/RegisterWindow.cpp | 41 +++++++++++------------ src/gui/wxgui/helpers/wxHelpers.h | 22 ------------ 3 files changed, 25 insertions(+), 56 deletions(-) diff --git a/src/gui/wxgui/debugger/DumpCtrl.cpp b/src/gui/wxgui/debugger/DumpCtrl.cpp index 7e2d369c..3e8565b5 100644 --- a/src/gui/wxgui/debugger/DumpCtrl.cpp +++ b/src/gui/wxgui/debugger/DumpCtrl.cpp @@ -1,6 +1,5 @@ #include "wxgui/wxgui.h" #include "wxgui/debugger/DumpCtrl.h" -#include "wxgui/helpers/wxHelpers.h" #include "Cafe/OS/RPL/rpl.h" #include "Cafe/OS/RPL/rpl_structs.h" #include "Cafe/HW/Espresso/Debugger/Debugger.h" @@ -403,22 +402,17 @@ bool DumpCtrl::WriteNumericDialog(uint32 address) if (dialog.ShowModal() != wxID_OK) return false; - const std::optional opt = parse_numeric(dialog.GetValue()); - - if (!opt.has_value()) - { - wxMessageBox(_("Invalid value."), _("Error"), wxOK | wxICON_ERROR, this); - return false; - } + + const T newValue = ConvertString(dialog.GetValue().ToStdString()); if constexpr (std::is_same::value) - memory_writeU8(address, opt.value()); + memory_writeU8(address, newValue); else if constexpr (std::is_same::value) - memory_writeU16(address, opt.value()); + memory_writeU16(address, newValue); else if constexpr (std::is_same::value) - memory_writeU32(address, opt.value()); + memory_writeU32(address, newValue); else if constexpr (std::is_same::value) - memory_writeFloat(address, opt.value()); + memory_writeFloat(address, newValue); return true; } diff --git a/src/gui/wxgui/debugger/RegisterWindow.cpp b/src/gui/wxgui/debugger/RegisterWindow.cpp index cd9aa4d7..d9241bef 100644 --- a/src/gui/wxgui/debugger/RegisterWindow.cpp +++ b/src/gui/wxgui/debugger/RegisterWindow.cpp @@ -1,6 +1,5 @@ #include "wxgui/wxgui.h" #include "wxgui/debugger/RegisterWindow.h" -#include "wxgui/helpers/wxHelpers.h" #include @@ -9,6 +8,7 @@ #include "Cafe/OS/RPL/rpl.h" #include "Cafe/OS/RPL/rpl_structs.h" #include "Cafe/HW/Espresso/EspressoISA.h" +#include "util/helpers/helpers.h" enum { @@ -359,15 +359,14 @@ void RegisterWindow::OnMouseDClickEvent(wxMouseEvent& event) wxTextEntryDialog set_value_dialog(this, _("Enter a new value."), wxString::Format(_("Set R%d value"), register_index), wxString::Format("0x%08x", register_value)); if (set_value_dialog.ShowModal() == wxID_OK) { - const std::optional opt = parse_numeric(set_value_dialog.GetValue()); - if (opt.has_value()) + const uint32 value = ConvertString(set_value_dialog.GetValue().ToStdString()); + + if (debugSession = debugger_lockDebugSession(); debugSession) { - if (debugSession = debugger_lockDebugSession(); debugSession) - { - debugSession->gpr[register_index] = opt.value(); - debugger_unlockDebugSession(debugSession); - } + debugSession->gpr[register_index] = value; + debugger_unlockDebugSession(debugSession); } + OnUpdateView(); } return; @@ -380,15 +379,14 @@ void RegisterWindow::OnMouseDClickEvent(wxMouseEvent& event) wxTextEntryDialog set_value_dialog(this, _("Enter a new value."), wxString::Format(_("Set FP0_%d value"), register_index), wxString::Format("%lf", register_value)); if (set_value_dialog.ShowModal() == wxID_OK) { - const std::optional opt = parse_numeric(set_value_dialog.GetValue()); - if (opt.has_value()) + const double value = ConvertString(set_value_dialog.GetValue().ToStdString()); + + if (debugSession = debugger_lockDebugSession(); debugSession) { - if (debugSession = debugger_lockDebugSession(); debugSession) - { - debugSession->fpr[register_index].fp0 = opt.value(); - debugger_unlockDebugSession(debugSession); - } + debugSession->fpr[register_index].fp0 = value; + debugger_unlockDebugSession(debugSession); } + OnUpdateView(); } @@ -402,15 +400,14 @@ void RegisterWindow::OnMouseDClickEvent(wxMouseEvent& event) wxTextEntryDialog set_value_dialog(this, _("Enter a new value."), wxString::Format(_("Set FP1_%d value"), register_index), wxString::Format("%lf", register_value)); if (set_value_dialog.ShowModal() == wxID_OK) { - const std::optional opt = parse_numeric(set_value_dialog.GetValue()); - if (opt.has_value()) + const double value = ConvertString(set_value_dialog.GetValue().ToStdString()); + + if (debugSession = debugger_lockDebugSession(); debugSession) { - if (debugSession = debugger_lockDebugSession(); debugSession) - { - debugSession->fpr[register_index].fp1 = opt.value(); - debugger_unlockDebugSession(debugSession); - } + debugSession->fpr[register_index].fp1 = value; + debugger_unlockDebugSession(debugSession); } + OnUpdateView(); } return; diff --git a/src/gui/wxgui/helpers/wxHelpers.h b/src/gui/wxgui/helpers/wxHelpers.h index 489362cc..fa42338b 100644 --- a/src/gui/wxgui/helpers/wxHelpers.h +++ b/src/gui/wxgui/helpers/wxHelpers.h @@ -5,8 +5,6 @@ #include #include -#include - template <> struct fmt::formatter : formatter { @@ -108,23 +106,3 @@ void update_slider_text(wxCommandEvent& event, const wxFormatString& format = "% uint32 fix_raw_keycode(uint32 keycode, uint32 raw_flags); WindowSystem::WindowHandleInfo initHandleContextFromWxWidgetsWindow(wxWindow* wxw); - -template -std::optional parse_numeric(const wxString& text) -{ - try - { - if (std::is_same::value) - return std::stof(text.ToStdString()); - - else if (std::is_same::value) - return std::stod(text.ToStdString()); - - // it's integral - return static_cast(std::stol(text.ToStdString(), nullptr, 0)); - } - catch (...) - { - return std::nullopt; - } -}