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