Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions Modules/Core/Common/include/itkSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ITKCommon_EXPORT SingletonIndex
}


// returns true if the globalName has not been registered yet.
// Returns true.
//
// It is assumed that the global will remain valid until the start
// of globals being destroyed.
Expand All @@ -70,7 +70,8 @@ class ITKCommon_EXPORT SingletonIndex
std::function<void(void *)> func,
std::function<void()> deleteFunc)
{
return this->SetGlobalInstancePrivate(globalName, global, func, deleteFunc);
this->SetGlobalInstancePrivate(globalName, global, func, deleteFunc);
return true;
}

/** Set/Get the pointer to GlobalSingleton.
Expand All @@ -90,9 +91,9 @@ class ITKCommon_EXPORT SingletonIndex
// work, and could use some type of Holder<T> class for intrinsic types
void *
GetGlobalInstancePrivate(const char * globalName);
// If globalName is already registered than false is return,
// otherwise global is added to the singleton index under globalName
bool

// global is added or set to the singleton index under globalName
void
SetGlobalInstancePrivate(const char * globalName,
void * global,
std::function<void(void *)> func,
Expand All @@ -119,11 +120,7 @@ Singleton(const char * globalName, std::function<void(void *)> func, std::functi
if (instance == nullptr)
{
instance = new T;
if (!SingletonIndex::GetInstance()->SetGlobalInstance<T>(globalName, instance, func, deleteFunc))
{
delete instance;
instance = nullptr;
}
SingletonIndex::GetInstance()->SetGlobalInstance<T>(globalName, instance, func, deleteFunc);
}
return instance;
}
Expand Down
8 changes: 3 additions & 5 deletions Modules/Core/Common/src/itkSingleton.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,15 @@ SingletonIndex::GetGlobalInstancePrivate(const char * globalName)
return std::get<0>(it->second);
}

// If globalName is already registered remove it from map,
// If globalName is already registered, set its global as specified,
// otherwise global is added to the singleton index under globalName
bool
void
SingletonIndex::SetGlobalInstancePrivate(const char * globalName,
void * global,
std::function<void(void *)> func,
std::function<void()> deleteFunc)
{
m_GlobalObjects.erase(globalName);
m_GlobalObjects.insert(std::make_pair(globalName, std::make_tuple(global, func, deleteFunc)));
return true;
m_GlobalObjects.insert_or_assign(globalName, std::make_tuple(global, func, deleteFunc));
}

SingletonIndex *
Expand Down