Sauce-0.10.1: sauce/internal/locker_factory.h Source File

Sauce-0.10.1 A C++ Dependency Injection Framework

- Main Page
- Classes
- Files

- File List

locker_factory.h
1 #ifndef SAUCE_INTERNAL_LOCKER_FACTORY_H_
2 #define SAUCE_INTERNAL_LOCKER_FACTORY_H_
3
4 namespace sauce {
5 namespace internal {
6
10 class Lock {
11 public:
12 virtual ~Lock() {}
13 };
14
18 class NullLock: public Lock {};
19
23 template<typename Locker>
24 class LockerLock: public Lock {
25 sauce::auto_ptr<Locker> locker;
26
27 public:
28
29 LockerLock(sauce::auto_ptr<Locker> locker):
30 locker(locker) {}
31 };
32
43 class LockFactory {
44 public:
45 virtual ~LockFactory() {}
46
47 virtual sauce::auto_ptr<Lock> createLock() = 0;
48 };
49
50 class NullLockFactory: public LockFactory {
51 public:
52 sauce::auto_ptr<Lock> createLock() {
53 sauce::auto_ptr<Lock> lock(new NullLock());
54 return lock;
55 }
56 };
57
58 template<typename Locker, typename Lockable>
59 class LockerLockFactory: public LockFactory {
60 Lockable & lockable;
61
62 public:
63
64 LockerLockFactory(Lockable & lockable):
65 lockable(lockable) {}
66
67 sauce::auto_ptr<Lock> createLock() {
68 sauce::auto_ptr<Locker> locker(new Locker(lockable));
69 sauce::auto_ptr<Lock> lock(new LockerLock<Locker>(locker));
70 return lock;
71 }
72 };
73
74 }
75
76 namespace i = ::sauce::internal;
77
78 }
79
80 #endif // SAUCE_INTERNAL_LOCKER_FACTORY_H_