-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
65 lines (48 loc) · 916 Bytes
/
main.cc
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
#include "object_pool.h"
#include "class_factory.h"
class I {
public:
virtual ~I() = default;
virtual void Say() = 0;
};
class A : public I {
public:
A() = default;
explicit A(int a) : a_(a) {}
void Say() override {
}
private:
int a_ = 0;
};
void TestObjectPool() {
auto pool = ObjectPool<A>::Create();
auto a = pool->ResolveUnique(1);
a.reset();
try
{
auto b = pool->ResolveShared();
}
catch (...)
{
//nop
}
auto c = pool->ResolveShared(7);
auto d = pool->ResolveUnique(2);
//b.reset();
//c.reset();
pool.reset();
}
void TestClassFactory() {
ClassFactory cf;
cf.Register<A>("A");
auto p = cf.CreateObject<A>("A");
p->Say();
cf.Register<A, int>("A");
p = cf.CreateObject<A>("A", 123);
p->Say();
}
int main() {
TestObjectPool();
TestClassFactory();
return 0;
}