changeset 15162:ad9523348676 gui

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.
author Mike Miller <mtmiller@ieee.org>
date Sun, 12 Aug 2012 14:36:23 -0400
parents 973296940c89
children dbc43bd95477 886d1fc9d575
files gui/src/resource-manager.cc gui/src/resource-manager.h
diffstat 2 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gui/src/resource-manager.cc
+++ b/gui/src/resource-manager.cc
@@ -25,14 +25,37 @@
 #include <QDir>
 #include <QNetworkProxy>
 
+#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 ()
 {
--- a/gui/src/resource-manager.h
+++ b/gui/src/resource-manager.h
@@ -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;
 };