Now fully use the error checking function instead of the C macro

This commit is contained in:
Arthur Moore 2015-01-10 19:33:46 -05:00
parent d3c5df6750
commit 306c7f3099
1 changed files with 18 additions and 18 deletions

View File

@ -2052,15 +2052,26 @@ public:
} throttle_ctrl;
/////////////////////////////
///Helper functions to convert WX's crazy string types to std::string
std::string ToString(wxCharBuffer aString)
{
return std::string(aString);
}
std::string ToString(const wxChar* aString)
{
return std::string(wxString(aString).mb_str(wxConvUTF8));
}
///Check if a pointer from the XRC file is valid. If it's not, throw an error telling the user.
template <typename T>
void CheckThrowXRCError(T pointer,std::string name)
{
if(pointer == NULL)
{
std::string errormessage = "Unable to load a ";
std::string errormessage = "Unable to load a \"";
errormessage+=typeid(pointer).name();
errormessage+=" from the builtin xrc file: ";
errormessage+="\" from the builtin xrc file: ";
errormessage+=name;
throw std::runtime_error(errormessage);
}
@ -2338,23 +2349,14 @@ bool MainFrame::InitMore(void)
try {
wxDialog *d = NULL;
#define baddialogc(name) { \
std::string errormessage = "Unable to load a dialog control from the builtin xrc file: "; \
errormessage+=name; \
throw std::runtime_error(errormessage); \
}
#define vfld(f, t) \
if(!XRCCTRL(*d, f, t)) \
baddialogc(f);
#define vfld(f, t) CheckThrowXRCError(XRCCTRL(*d, f, t),f)
#define getfld(v, f, t) \
v = XRCCTRL(*d, f, t); \
if(!v) \
baddialogc(f);
CheckThrowXRCError(v,f)
#define getfldv(v, f, t) \
v = XRCCTRL_D(*d, f, t); \
if(!v) \
baddialogc(f.mb_str());
CheckThrowXRCError(v,ToString(f))
//// displayed during run
d=LoadXRCDialog("GBPrinter");
@ -2834,8 +2836,7 @@ bool MainFrame::InitMore(void)
NULL, &BatConfigHandler);
#define getgbaw(n) do { \
wxWindow *w = d->FindWindow(XRCID(n)); \
if(!w) \
baddialogc(n); \
CheckThrowXRCError(w,n); \
w->SetValidator(GBACtrlEnabler()); \
} while(0)
getgbaw("Detect");
@ -3058,8 +3059,7 @@ bool MainFrame::InitMore(void)
wxWindow *prev = NULL, *prevp = NULL;
for(int j = 0; j < NUM_KEYS; j++) {
wxJoyKeyTextCtrl *tc = XRCCTRL_D(*w, joynames[j], wxJoyKeyTextCtrl);
if(!tc)
baddialogc(wxString(joynames[j]).mb_str());
CheckThrowXRCError(tc,ToString(joynames[j]));
wxWindow *p = tc->GetParent();
if(p == prevp)
tc->MoveAfterInTabOrder(prev);