From 76ef5906a068fc55cb46ed043b3b983c9b68c957 Mon Sep 17 00:00:00 2001 From: wowzaman12 Date: Sat, 28 Mar 2015 01:12:57 +0000 Subject: [PATCH] Move XRC pointer checking/error throwing to a templated function (More backporting from Arthur, next few commits will be importing his improvements) --- src/wx/guiinit.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index 4e12146b..5dab13d2 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -7,6 +7,7 @@ #include "wxvbam.h" +#include #include #include @@ -1942,19 +1943,27 @@ public: } throttle_ctrl; ///////////////////////////// +//Check if a pointer from the XRC file is valid. If it's not, throw an error telling the user. +template +void CheckThrowXRCError(T pointer,std::string name) +{ + if(pointer == NULL) + { + std::string errormessage = "Unable to load a "; + errormessage+=typeid(pointer).name(); + errormessage+=" from the builtin xrc file: "; + errormessage+=name; + throw std::runtime_error(errormessage); + } +} wxDialog * MainFrame::LoadXRCDialog(const char * name) { wxString dname = wxString::FromUTF8(name); /* using this instead of LoadDialog() allows non-wxDialog classes that */ /* are derived from wxDialog (like wxPropertySheetDialog) to work */ wxDialog * dialog = wxDynamicCast(wxXmlResource::Get()->LoadObject(this, dname, wxEmptyString), wxDialog); - if(!dialog) - { - std::string errormessage = "Unable to load a dialog from the builtin xrc file: "; - errormessage+=name; - throw std::runtime_error(errormessage); - return NULL; - } + CheckThrowXRCError(dialog,name); + /* wx-2.9.1 doesn't set parent for propertysheetdialogs for some reason */ /* this will generate a gtk warning but it is necessary for later */ /* retrieval using FindWindow() */