diff options
| -rw-r--r-- | base/plugins.h | 2 | ||||
| -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 | ||||
| -rw-r--r-- | gui/newgui.h | 2 | ||||
| -rw-r--r-- | 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<SingletonBaseType>;  	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<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();  /** 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<Dialog *> DialogStack;  class NewGui : public Common::Singleton<NewGui> {  	typedef Common::String String;  	friend class Dialog; -	friend SingletonBaseType *makeInstance<>(); +	friend class Common::Singleton<SingletonBaseType>;  	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<SingletonBaseType>;  	AudioCDManager();  	int getCachedTrack(int track);  | 
