Skip to content

Commit

Permalink
STYLE: SingletonIndex does not need to store the unused func parameter
Browse files Browse the repository at this point in the history
No longer stored the `func` parameter from `SingletonIndex::SetGlobalInstance`,
as it was never actually retrieved afterwards.

Deprecated the `SingletonIndex::SingletonData` type alias, as it is no longer
used internally anymore, and it should not be public either.
  • Loading branch information
N-Dekker committed Aug 20, 2023
1 parent c3ae515 commit 9d3c6b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
20 changes: 11 additions & 9 deletions Modules/Core/Common/include/itkSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ class ITKCommon_EXPORT SingletonIndex
public:
/** Standard class types. */
using Self = SingletonIndex;
using SingletonData = std::map<std::string, std::tuple<void *, std::function<void(void *)>, std::function<void()>>>;

#ifndef ITK_LEGACY_REMOVE
using SingletonData [[deprecated("The internal representation of the singleton data is private, and may not "
"correspond with SingletonData anymore.")]] =
std::map<std::string, std::tuple<void *, std::function<void(void *)>, std::function<void()>>>;
#endif

// obtain a global registered in the singleton index under the
// globalName, if unknown then nullptr will be returned.
Expand All @@ -67,10 +72,10 @@ class ITKCommon_EXPORT SingletonIndex
bool
SetGlobalInstance(const char * globalName,
T * global,
std::function<void(void *)> func,
std::function<void(void *)> itkNotUsed(func),
std::function<void()> deleteFunc)
{
return this->SetGlobalInstancePrivate(globalName, global, func, deleteFunc);
return this->SetGlobalInstancePrivate(globalName, global, deleteFunc);
}

/** Set/Get the pointer to GlobalSingleton.
Expand All @@ -93,17 +98,14 @@ class ITKCommon_EXPORT SingletonIndex
// If globalName is already registered than false is return,
// otherwise global is added to the singleton index under globalName
bool
SetGlobalInstancePrivate(const char * globalName,
void * global,
std::function<void(void *)> func,
std::function<void()> deleteFunc);
SetGlobalInstancePrivate(const char * globalName, void * global, std::function<void()> deleteFunc);

/** The static GlobalSingleton. This is initialized to nullptr as the first
* stage of static initialization. It is then populated on the first call to
* itk::Singleton::Modified() but it can be overridden with SetGlobalSingleton().
* */
SingletonData m_GlobalObjects;
static Self * m_Instance;
std::map<std::string, std::tuple<void *, std::function<void()>>> m_GlobalObjects;
static Self * m_Instance;
// static SingletonIndexPrivate * m_GlobalSingleton;
};

Expand Down
12 changes: 4 additions & 8 deletions Modules/Core/Common/src/itkSingleton.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ namespace itk
void *
SingletonIndex::GetGlobalInstancePrivate(const char * globalName)
{
SingletonData::iterator it;
it = m_GlobalObjects.find(globalName);
const auto it = m_GlobalObjects.find(globalName);
if (it == m_GlobalObjects.end())
{
return nullptr;
Expand All @@ -99,13 +98,10 @@ SingletonIndex::GetGlobalInstancePrivate(const char * globalName)
// If globalName is already registered remove it from map,
// otherwise global is added to the singleton index under globalName
bool
SingletonIndex::SetGlobalInstancePrivate(const char * globalName,
void * global,
std::function<void(void *)> func,
std::function<void()> deleteFunc)
SingletonIndex::SetGlobalInstancePrivate(const char * globalName, void * global, std::function<void()> deleteFunc)
{
m_GlobalObjects.erase(globalName);
m_GlobalObjects.insert(std::make_pair(globalName, std::make_tuple(global, func, deleteFunc)));
m_GlobalObjects.insert(std::make_pair(globalName, std::make_tuple(global, deleteFunc)));
return true;
}

Expand All @@ -130,7 +126,7 @@ SingletonIndex::~SingletonIndex()
{
for (auto & pair : m_GlobalObjects)
{
std::get<2>(pair.second)();
std::get<1>(pair.second)();
}
}

Expand Down

0 comments on commit 9d3c6b3

Please sign in to comment.