-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpool.cpp
More file actions
94 lines (87 loc) · 1.94 KB
/
pool.cpp
File metadata and controls
94 lines (87 loc) · 1.94 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "pool.h"
DictPool g_DictPool;
TablePool g_TablePool;
Dictionary* DictPool::Get(char *dictName)
{
string dname(dictName);
map<string, Dictionary*>::iterator it = dictMap.find(dname);
if (it != dictMap.end())
{
return it->second;
}
else
{
Dictionary *dict = new Dictionary(dictName);
dict->Create();
dictMap.insert(map<string, Dictionary*>::value_type(dname, dict));
return dict;
}
}
bool DictPool::Free(char *dictName)
{
string dname(dictName);
map<string, Dictionary*>::iterator it = dictMap.find(dname);
if (it != dictMap.end())
{
it->second->Close();
delete it->second;
dictMap.erase(it);
return true;
}
else
{
return false;
}
}
void DictPool::Close()
{
map<string, Dictionary*>::iterator it = dictMap.begin();
for (; it != dictMap.end(); ++it)
{
it->second->Close();
delete it->second;
}
dictMap.clear();
}
BufferedTable* TablePool::Get(TableInfo *info)
{
string tname(info->TName);
map<string, BufferedTable*>::iterator it = tableMap.find(tname);
if (it != tableMap.end())
{
return it->second;
}
else
{
BufferedTable *table = new BufferedTable(info);
table->Open(true);
tableMap.insert(map<string, BufferedTable*>::value_type(tname, table));
return table;
}
}
bool TablePool::Free(TableInfo *info)
{
string tname(info->TName);
map<string, BufferedTable*>::iterator it = tableMap.find(tname);
if (it != tableMap.end())
{
it->second->Close();
delete it->second;
tableMap.erase(it);
return true;
}
else
{
return false;
}
}
void TablePool::Close()
{
map<string, BufferedTable*>::iterator it = tableMap.begin();
for (; it != tableMap.end(); ++it)
{
it->second->Close();
delete it->second;
}
tableMap.clear();
}