diff options
author | Max Horn | 2005-01-06 18:38:34 +0000 |
---|---|---|
committer | Max Horn | 2005-01-06 18:38:34 +0000 |
commit | 5d88c3954968b8eccb86363055bda55300ac2586 (patch) | |
tree | f45c5bada27815e466bab2089d00684fa6ee2436 /common | |
parent | 9cfb8d3bb506f07b5373f4ba56a747a027778a47 (diff) | |
download | scummvm-rg350-5d88c3954968b8eccb86363055bda55300ac2586.tar.gz scummvm-rg350-5d88c3954968b8eccb86363055bda55300ac2586.tar.bz2 scummvm-rg350-5d88c3954968b8eccb86363055bda55300ac2586.zip |
Modify the singleton code once more to help overcome an issue with MSVC 7 (see also patch #1095133)
svn-id: r16454
Diffstat (limited to 'common')
-rw-r--r-- | common/config-manager.h | 2 | ||||
-rw-r--r-- | common/singleton.h | 27 | ||||
-rw-r--r-- | common/system.cpp | 2 | ||||
-rw-r--r-- | common/system.h | 4 |
4 files changed, 18 insertions, 17 deletions
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<SingletonBaseType>; 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 <class T> -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 <class T> + 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<T>(); + _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<OSystem>::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<OSystem>::makeInstance(); /** |