From 4a8c9e40b33e543ea2a948ea735bef48c4a1f277 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Wed, 23 Dec 2015 13:32:50 +0100
Subject: [PATCH] modernize and simplify singleton base class

---
 pub/CHANGELOG            |  1 +
 pub/lib/toplevel.cpp     |  7 +------
 pub/trivia/singleton.hpp | 16 ++--------------
 3 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/pub/CHANGELOG b/pub/CHANGELOG
index c7c037b5..a2c1a13b 100644
--- a/pub/CHANGELOG
+++ b/pub/CHANGELOG
@@ -3,6 +3,7 @@ Release:
 - New functionality:
   - functions kwwmc, kwwms, kwwmp take argument <tau> instead of tau
 - Code cleanup:
+  - modernize and simplify singleton base class
   - got rid of global instances of singletons
 
 Release 2.3.2f of 17nov15:
diff --git a/pub/lib/toplevel.cpp b/pub/lib/toplevel.cpp
index a9cdc4c5..3a1c260c 100644
--- a/pub/lib/toplevel.cpp
+++ b/pub/lib/toplevel.cpp
@@ -53,15 +53,10 @@ void my_gsl_error_handler ( const char * reason, const char * file, int line, in
 }
 
 
-//! At exit, tear down globals.
+//! At exit, currently nothing to do.
 
 void atexit_handler()
 {
-    SFuncRegistry::reset_instance();
-    SGeniRegistry::reset_instance();
-    SCvinRegistry::reset_instance();
-    SVariRegistry::reset_instance();
-    SPloWin::reset_instance();
 }
 
 
diff --git a/pub/trivia/singleton.hpp b/pub/trivia/singleton.hpp
index a1766920..7fc1cbff 100644
--- a/pub/trivia/singleton.hpp
+++ b/pub/trivia/singleton.hpp
@@ -19,26 +19,14 @@ class ISingleton {
  private:
     ISingleton(ISingleton const&) = delete;  //! To prevent copying
     void operator=(ISingleton const&) = delete; //! To prevent copying
-    static T* instance;
  protected:
     ~ISingleton() {};
     ISingleton() {}
     typedef T* T_Pointer;
  public:
-    static T* get_instance()
-        { if ( instance==nullptr )
-                instance = new T();
-            return instance; }
-    static void reset_instance() {
-        delete instance;
-        instance = nullptr;
-    }
+    static T* get_instance() { static T* instance = new T(); return instance; }
 };
 
-// Instantiate static member:
-template<class T>
-typename ISingleton<T>::T_Pointer ISingleton<T>::instance = nullptr;
-
-}
+} // namespace triv
 
 #endif // ISINGLETON_H
-- 
GitLab