# HG changeset patch # User Mike Miller # Date 1344796583 14400 # Node ID ad9523348676b4ce393428580a38740b3e8925db # Parent 973296940c8948e52f93c355b7ed4bdcffa24649 Make resource_manager a singleton with Octave conventions * resource-manager.cc (resource_manager::instance_ok): New function. * resource-manager.h (resource_manager::instance): Call instance_ok. (resource_manager::instance_ok, resource_manager::cleanup_instance): New functions. diff -r 973296940c89 -r ad9523348676 gui/src/resource-manager.cc --- a/gui/src/resource-manager.cc Sat Aug 11 18:15:29 2012 -0400 +++ b/gui/src/resource-manager.cc Sun Aug 12 14:36:23 2012 -0400 @@ -25,14 +25,37 @@ #include #include +#include "error.h" #include "file-ops.h" #include "oct-env.h" +#include "singleton-cleanup.h" #include "defaults.h" #include "resource-manager.h" -resource_manager resource_manager::_singleton; +resource_manager *resource_manager::_instance = 0; + +bool +resource_manager::instance_ok () +{ + bool retval = true; + + if (! _instance) + { + _instance = new resource_manager (); + + if (_instance) + singleton_cleanup_list::add (cleanup_instance); + } + + if (! _instance) + { + ::error ("unable to create resource_manager object!"); + } + + return retval; +} resource_manager::resource_manager () { diff -r 973296940c89 -r ad9523348676 gui/src/resource-manager.h --- a/gui/src/resource-manager.h Sat Aug 11 18:15:29 2012 -0400 +++ b/gui/src/resource-manager.h Sun Aug 12 14:36:23 2012 -0400 @@ -32,7 +32,7 @@ static resource_manager * instance () { - return &_singleton; + return (instance_ok ()) ? _instance : 0; } QSettings *get_settings (); @@ -48,9 +48,13 @@ private: resource_manager (); + static bool instance_ok (); + + static void cleanup_instance () { delete _instance; _instance = 0; } + QSettings *_settings; QString _home_path; - static resource_manager _singleton; + static resource_manager *_instance; bool _first_run; };