From 5d88c3954968b8eccb86363055bda55300ac2586 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 6 Jan 2005 18:38:34 +0000 Subject: Modify the singleton code once more to help overcome an issue with MSVC 7 (see also patch #1095133) svn-id: r16454 --- base/plugins.h | 2 +- common/config-manager.h | 2 +- common/singleton.h | 27 ++++++++++++++------------- common/system.cpp | 2 +- common/system.h | 4 ++-- gui/newgui.h | 2 +- sound/audiocd.h | 2 +- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/base/plugins.h b/base/plugins.h index 6252bfeaaf..04c90ddf0c 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -117,7 +117,7 @@ private: bool tryLoadPlugin(Plugin *plugin); - friend SingletonBaseType *makeInstance<>(); + friend class Common::Singleton; PluginManager(); public: diff --git a/common/config-manager.h b/common/config-manager.h index 45d7912b64..e23d211348 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -114,7 +114,7 @@ public: */ private: - friend SingletonBaseType *makeInstance<>(); + friend class Singleton; ConfigManager(); void loadFile(const String &filename); diff --git a/common/singleton.h b/common/singleton.h index a436d506b8..9e6cc5438b 100644 --- a/common/singleton.h +++ b/common/singleton.h @@ -23,18 +23,6 @@ #ifndef COMMON_SINGLETON_H #define COMMON_SINGLETON_H -/** - * The default object factory used by the template class Singleton. - * By specialising this template function, one can make a singleton use a - * custom object factory. For example, to support encapsulation, your - * singleton class might be pure virtual (or "abstract" in Java terminology), - * and you specialise makeInstance to return an instance of a subclass. - */ -template -T* makeInstance() { - return new T(); -} - namespace Common { /** @@ -49,6 +37,19 @@ private: static T* _singleton; + /** + * The default object factory used by the template class Singleton. + * By specialising this template function, one can make a singleton use a + * custom object factory. For example, to support encapsulation, your + * singleton class might be pure virtual (or "abstract" in Java terminology), + * and you specialise makeInstance to return an instance of a subclass. + */ + //template + static T* makeInstance() { + return new T(); + } + + public: static T& instance() { // TODO: We aren't thread safe. For now we ignore it since the @@ -59,7 +60,7 @@ public: // order might become an issue. There are various approaches // to solve that problem, but for now this is sufficient if (!_singleton) - _singleton = makeInstance(); + _singleton = makeInstance(); return *_singleton; } protected: diff --git a/common/system.cpp b/common/system.cpp index db020a2e5f..9487052de1 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -34,7 +34,7 @@ DECLARE_SINGLETON(OSystem); template <> -OSystem *makeInstance<>() { +OSystem *Common::Singleton::makeInstance() { // Attention: Do not call parseGraphicsMode() here, nor any other function // which needs to access the OSystem instance, else you get stuck in an // endless loop. diff --git a/common/system.h b/common/system.h index 617cb5c052..11831de0de 100644 --- a/common/system.h +++ b/common/system.h @@ -32,10 +32,10 @@ class OSystem; /** - * Custome object factory for OSystem. + * Custom object factory for OSystem. */ template <> -OSystem *makeInstance<>(); +extern OSystem *Common::Singleton::makeInstance(); /** diff --git a/gui/newgui.h b/gui/newgui.h index e8c0eae556..f57cb68488 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -56,7 +56,7 @@ typedef Common::FixedStack DialogStack; class NewGui : public Common::Singleton { typedef Common::String String; friend class Dialog; - friend SingletonBaseType *makeInstance<>(); + friend class Common::Singleton; NewGui(); public: diff --git a/sound/audiocd.h b/sound/audiocd.h index e852b2939f..d523bc5a46 100644 --- a/sound/audiocd.h +++ b/sound/audiocd.h @@ -54,7 +54,7 @@ public: Status getStatus() const; private: - friend SingletonBaseType *makeInstance<>(); + friend class Common::Singleton; AudioCDManager(); int getCachedTrack(int track); -- cgit v1.2.3