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

Sauce-0.10.1 A C++ Dependency Injection Framework

- Main Page
- Classes
- Files

- File List

pending_thrower.h
1 #ifndef SAUCE_INTERNAL_PENDING_THROWER_H_
2 #define SAUCE_INTERNAL_PENDING_THROWER_H_
3
4 namespace sauce {
5 namespace internal {
6
7 typedef void (*PendingThrow)();
8
15 template<typename Exception>
16 void pendingThrowFactory() {
17 throw Exception();
18 }
19
23 class PendingThrower { // Tempted to call it PendingThrowDown
24 PendingThrow pending;
25
26 public:
27
28 PendingThrower():
29 pending(NULL) {}
30
38 template<typename Exception>
39 void throwLater() {
40 pending = &pendingThrowFactory<Exception>;
41 }
42
46 void throwAnyPending() {
47 PendingThrow toThrow = clear();
48 if (toThrow) {
49 toThrow();
50 }
51 }
52
58 PendingThrow clear() {
59 PendingThrow toThrow = pending;
60 pending = NULL;
61 return toThrow;
62 }
63 };
64
65 }
66
67 namespace i = ::sauce::internal;
68
69 }
70
71 #endif // SAUCE_INTERNAL_PENDING_THROWER_H_