mirror of
				https://github.com/cookiengineer/audacity
				synced 2025-10-31 22:23:54 +01:00 
			
		
		
		
	Make static "Destroy" methods for certain singletons unnecessary.
This commit is contained in:
		| @@ -109,7 +109,6 @@ public: | ||||
| class ModuleManagerInterface /* not final */ | ||||
| { | ||||
| public: | ||||
|    virtual ~ModuleManagerInterface() {}; | ||||
|  | ||||
|    // Modules call this to register their interface | ||||
|    virtual void RegisterModule(ModuleInterface *module) = 0; | ||||
|   | ||||
| @@ -54,7 +54,6 @@ class ModuleInterface; | ||||
| class PluginManagerInterface /* not final */ | ||||
| { | ||||
| public: | ||||
|    virtual ~PluginManagerInterface() {}; | ||||
|  | ||||
|    virtual bool IsPluginRegistered(const wxString & path) = 0; | ||||
|  | ||||
|   | ||||
| @@ -1984,10 +1984,6 @@ int AudacityApp::OnExit() | ||||
|    // Terminate the PluginManager (must be done before deleting the locale) | ||||
|    PluginManager::Get().Terminate(); | ||||
|  | ||||
|    // Done with plugins and modules | ||||
|    PluginManager::Destroy(); | ||||
|    ModuleManager::Destroy(); | ||||
|  | ||||
|    if (mLocale) | ||||
|       delete mLocale; | ||||
|  | ||||
|   | ||||
| @@ -47,12 +47,6 @@ DeviceManager* DeviceManager::Instance() | ||||
|    return &dm; | ||||
| } | ||||
|  | ||||
| /// Releases memory assosiated with the singleton | ||||
| void DeviceManager::Destroy() | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| const std::vector<DeviceSourceMap> &DeviceManager::GetInputDeviceMaps() | ||||
| { | ||||
|    if (!m_inited) | ||||
|   | ||||
| @@ -51,9 +51,6 @@ class DeviceManager final | ||||
|    /// Gets the singleton instance | ||||
|    static DeviceManager* Instance(); | ||||
|  | ||||
|    /// Releases memory assosiated with the singleton | ||||
|    static void Destroy(); | ||||
|  | ||||
|    /// Gets a NEW list of devices by terminating and restarting portaudio | ||||
|    /// Assumes that DeviceManager is only used on the main thread. | ||||
|    void Rescan(); | ||||
| @@ -74,7 +71,7 @@ class DeviceManager final | ||||
|  protected: | ||||
|    //private constructor - Singleton. | ||||
|    DeviceManager(); | ||||
|    virtual ~DeviceManager(); | ||||
|    ~DeviceManager(); | ||||
|    /// Does an initial scan. | ||||
|    /// Called by GetInputDeviceMaps and GetOutputDeviceMaps when needed. | ||||
|    void Init(); | ||||
|   | ||||
| @@ -180,7 +180,7 @@ void * Module::GetSymbol(const wxString &name) | ||||
| // ============================================================================ | ||||
|  | ||||
| // The one and only ModuleManager | ||||
| ModuleManager *ModuleManager::mInstance = NULL; | ||||
| std::unique_ptr<ModuleManager> ModuleManager::mInstance{}; | ||||
|  | ||||
| // Provide builtin modules a means to identify themselves | ||||
| static wxArrayPtrVoid *pBuiltinModuleList = NULL; | ||||
| @@ -358,21 +358,12 @@ ModuleManager & ModuleManager::Get() | ||||
| { | ||||
|    if (!mInstance) | ||||
|    { | ||||
|       mInstance = new ModuleManager(); | ||||
|       mInstance.reset(safenew ModuleManager); | ||||
|    } | ||||
|  | ||||
|    return *mInstance; | ||||
| } | ||||
|  | ||||
| void ModuleManager::Destroy() | ||||
| { | ||||
|    if (mInstance) | ||||
|    { | ||||
|       delete mInstance; | ||||
|       mInstance = NULL; | ||||
|    } | ||||
| } | ||||
|  | ||||
| bool ModuleManager::DiscoverProviders() | ||||
| { | ||||
|    InitializeBuiltins(); | ||||
|   | ||||
| @@ -88,7 +88,6 @@ public: | ||||
|    // ------------------------------------------------------------------------- | ||||
|  | ||||
|    static ModuleManager & Get(); | ||||
|    static void Destroy(); | ||||
|  | ||||
|    void Initialize(CommandHandler & cmdHandler); | ||||
|    int Dispatch(ModuleDispatchTypes type); | ||||
| @@ -110,14 +109,15 @@ public: | ||||
| private: | ||||
|    // I'm a singleton class | ||||
|    ModuleManager(); | ||||
|    virtual ~ModuleManager(); | ||||
|    ~ModuleManager(); | ||||
|  | ||||
|    void InitializeBuiltins(); | ||||
|    ModuleInterface *LoadModule(const wxString & path); | ||||
|  | ||||
| private: | ||||
|    friend ModuleInterfaceDeleter; | ||||
|    static ModuleManager *mInstance; | ||||
|    friend std::default_delete<ModuleManager>; | ||||
|    static std::unique_ptr<ModuleManager> mInstance; | ||||
|  | ||||
|    ModuleMainMap mModuleMains; | ||||
|    ModuleMap mDynModules; | ||||
|   | ||||
| @@ -1666,7 +1666,7 @@ bool PluginManager::RemovePrivateConfig(const PluginID & ID, const wxString & gr | ||||
| // ============================================================================ | ||||
|  | ||||
| // The one and only PluginManager | ||||
| PluginManager *PluginManager::mInstance = NULL; | ||||
| std::unique_ptr<PluginManager> PluginManager::mInstance{}; | ||||
|  | ||||
| // ---------------------------------------------------------------------------- | ||||
| // Creation/Destruction | ||||
| @@ -1679,6 +1679,9 @@ PluginManager::PluginManager() | ||||
|  | ||||
| PluginManager::~PluginManager() | ||||
| { | ||||
|    // Ensure termination (harmless if already done) | ||||
|    Terminate(); | ||||
|  | ||||
|    if (mSettings) | ||||
|    { | ||||
|       delete mSettings; | ||||
| @@ -1700,20 +1703,12 @@ PluginManager & PluginManager::Get() | ||||
| { | ||||
|    if (!mInstance) | ||||
|    { | ||||
|       mInstance = new PluginManager(); | ||||
|       mInstance.reset(safenew PluginManager); | ||||
|    } | ||||
|  | ||||
|    return *mInstance; | ||||
| } | ||||
|  | ||||
| void PluginManager::Destroy() | ||||
| { | ||||
|    if (mInstance) | ||||
|    { | ||||
|       delete mInstance; | ||||
|    } | ||||
| } | ||||
|  | ||||
| void PluginManager::Initialize() | ||||
| { | ||||
|    // Always load the registry first | ||||
|   | ||||
| @@ -16,6 +16,7 @@ | ||||
| #include <wx/fileconf.h> | ||||
| #include <wx/string.h> | ||||
|  | ||||
| #include "MemoryX.h" | ||||
| #include <map> | ||||
|  | ||||
| #include "audacity/EffectInterface.h" | ||||
| @@ -172,8 +173,6 @@ class PluginRegistrationDialog; | ||||
| class PluginManager final : public PluginManagerInterface | ||||
| { | ||||
| public: | ||||
|    PluginManager(); | ||||
|    virtual ~PluginManager(); | ||||
|  | ||||
|    // PluginManagerInterface implementation | ||||
|  | ||||
| @@ -234,7 +233,6 @@ public: | ||||
|    void Terminate(); | ||||
|  | ||||
|    static PluginManager & Get(); | ||||
|    static void Destroy(); | ||||
|  | ||||
|    static PluginID GetID(ModuleInterface *module); | ||||
|    static PluginID GetID(EffectIdentInterface *effect); | ||||
| @@ -270,6 +268,10 @@ public: | ||||
|    void UnregisterPlugin(const PluginID & ID); | ||||
|  | ||||
| private: | ||||
|    // private! Use Get() | ||||
|    PluginManager(); | ||||
|    ~PluginManager(); | ||||
|  | ||||
|    void Load(); | ||||
|    void LoadGroup(PluginType type); | ||||
|    void Save(); | ||||
| @@ -309,7 +311,8 @@ private: | ||||
|    int b64decode(const wxString &in, void *out); | ||||
|  | ||||
| private: | ||||
|    static PluginManager *mInstance; | ||||
|    friend std::default_delete<PluginManager>; | ||||
|    static std::unique_ptr<PluginManager> mInstance; | ||||
|  | ||||
|    bool IsDirty(); | ||||
|    void SetDirty(bool dirty = true); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user