From: Mikko Rasa Date: Sat, 5 Oct 2013 12:15:07 +0000 (+0300) Subject: Better method of preventing duplicate applications X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=0f5501ad79950e9658fb672ac6b97a608e3a2dd9;hp=f042fd992170ee8a50a7f596f1c9cdd9600b8583;ds=sidebyside Better method of preventing duplicate applications Application::run can now be called multiple times, but not recursively. --- diff --git a/source/core/application.cpp b/source/core/application.cpp index 43bb023..d5745ed 100644 --- a/source/core/application.cpp +++ b/source/core/application.cpp @@ -16,21 +16,16 @@ void *Application::data_ = 0; Application::Application(): exit_code(0) -{ } +{ + if(app_) + throw logic_error("instance already exists"); +} int Application::run(int argc, char **argv, void *data) { - static bool called = false; - if(called) - { - IO::cerr.write("Trying to call Application::run_app twice!\n"); - return 125; - } - called = true; - if(!starter_) { - IO::cerr.write("Trying to run with no RegisteredApplication class!\n"); + IO::cerr.write("Application::run called with no RegisteredApplication class!\n"); return 126; } @@ -68,6 +63,7 @@ int Application::run(int argc, char **argv, void *data) } delete app_; + app_ = 0; return 124; }