diff --git a/Modules/Core/Common/include/itkSingleton.h b/Modules/Core/Common/include/itkSingleton.h index f538521043f..d058a0485b3 100644 --- a/Modules/Core/Common/include/itkSingleton.h +++ b/Modules/Core/Common/include/itkSingleton.h @@ -64,20 +64,29 @@ class ITKCommon_EXPORT SingletonIndex } - // Returns true. - // // It is assumed that the global will remain valid until the start // of globals being destroyed. template - bool + void + SetGlobalInstance(const char * globalName, T * global, std::function deleteFunc) + { + this->SetGlobalInstancePrivate(globalName, global, deleteFunc); + } + +#ifndef ITK_LEGACY_REMOVE + template + [[deprecated("Prefer calling the SetGlobalInstance(globalName, global, deleteFunc) overload (without the unused func " + "parameter)!")]] bool SetGlobalInstance(const char * globalName, T * global, std::function itkNotUsed(func), std::function deleteFunc) { - this->SetGlobalInstancePrivate(globalName, global, deleteFunc); + this->SetGlobalInstance(globalName, global, deleteFunc); + // Just returns true for backward compatibility (legacy only). return true; } +#endif /** Set/Get the pointer to GlobalSingleton. * Note that SetGlobalSingleton is not concurrent thread safe. */ @@ -114,7 +123,7 @@ class ITKCommon_EXPORT SingletonIndex // A wrapper for a global variable registered in the singleton index. template T * -Singleton(const char * globalName, std::function itkNotUsed(func), std::function deleteFunc) +Singleton(const char * globalName, std::function deleteFunc) { static SingletonIndex * singletonIndex = SingletonIndex::GetInstance(); Unused(singletonIndex); @@ -122,10 +131,21 @@ Singleton(const char * globalName, std::function itkNotUsed(func), if (instance == nullptr) { instance = new T; - SingletonIndex::GetInstance()->SetGlobalInstance(globalName, instance, {}, deleteFunc); + SingletonIndex::GetInstance()->SetGlobalInstance(globalName, instance, deleteFunc); } return instance; } + + +#ifndef ITK_LEGACY_REMOVE +template +[[deprecated("Prefer calling the Singleton(globalName, deleteFunc) overload (without the unused func parameter)!")]] T * +Singleton(const char * globalName, std::function itkNotUsed(func), std::function deleteFunc) +{ + return Singleton(globalName, deleteFunc); +} +#endif + } // end namespace itk #endif diff --git a/Modules/Core/Common/include/itkSingletonMacro.h b/Modules/Core/Common/include/itkSingletonMacro.h index ceb60c51cb6..8796233e0ca 100644 --- a/Modules/Core/Common/include/itkSingletonMacro.h +++ b/Modules/Core/Common/include/itkSingletonMacro.h @@ -49,7 +49,7 @@ m_##VarName = nullptr; \ }; \ auto * old_instance = SingletonIndex::GetInstance()->GetGlobalInstance(#SingletonName); \ - m_##VarName = Singleton(#SingletonName, {}, deleteLambda); \ + m_##VarName = Singleton(#SingletonName, deleteLambda); \ if (old_instance == nullptr) \ { \ Init; \ diff --git a/Modules/Core/Common/src/itkObjectFactoryBase.cxx b/Modules/Core/Common/src/itkObjectFactoryBase.cxx index 1dbd7467811..e6247322a49 100644 --- a/Modules/Core/Common/src/itkObjectFactoryBase.cxx +++ b/Modules/Core/Common/src/itkObjectFactoryBase.cxx @@ -130,8 +130,7 @@ auto ObjectFactoryBase::GetPimplGlobalsPointer() -> ObjectFactoryBasePrivate * { const auto deleteLambda = []() { m_PimplGlobals->UnRegister(); }; - ObjectFactoryBasePrivate * globalInstance = - Singleton("ObjectFactoryBase", SynchronizeObjectFactoryBase, deleteLambda); + ObjectFactoryBasePrivate * globalInstance = Singleton("ObjectFactoryBase", deleteLambda); if (globalInstance != m_PimplGlobals) { SynchronizeObjectFactoryBase(globalInstance);