-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniSingleton.cpp
38 lines (34 loc) · 1.04 KB
/
UniSingleton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma execution_character_set("utf-8")
#include "UniSingleton.h"
// static instance of manager
CSingletonMgr CSingletonMgr::ms_instance;
// Clear all singleton instances
void CSingletonMgr::clear()
{
for (; !m_mapInstances.empty();)
{
auto iter = m_mapInstances.begin();
//TRACE("destroy singleton: %s\n", iter->first);
CSingletonMgr::PBase* pObj = iter->second;
m_mapInstances.erase(iter);
delete pObj;
}
}
// Remove the instance of _class
// @param lpszType: Specifies the type name of singleton you want to remove
// @param del: If true, delete the instance of singleton
// @return: If the instance is successfully deleted, return ture, otherwise it returns false
bool CSingletonMgr::remove(const char* lpszType, bool del)
{
std::map<const char*, CSingletonMgr::PBase*>::iterator iter = m_mapInstances.find(lpszType);
if (iter != m_mapInstances.end())
{
//TRACE("destroy singleton: %s\n", iter->first);
CSingletonMgr::PBase* pObj = iter->second;
m_mapInstances.erase(iter);
if (del)
delete pObj;
return true;
}
return false;
}