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_
sauce::internal::PendingThrower::throwLater
void throwLater()
Save an exception of the given type to throw when it is safe.
Definition: pending_thrower.h:39
sauce::internal
Definition: binder.h:317
sauce::internal::PendingThrower::clear
PendingThrow clear()
Clear and return any saved exception.
Definition: pending_thrower.h:58
sauce::internal::PendingThrower::throwAnyPending
void throwAnyPending()
Throw and clear any saved exception.
Definition: pending_thrower.h:46
sauce
Definition: binder.h:21
sauce::internal::PendingThrower
A mixin to defer and throw pending exceptions.
Definition: pending_thrower.h:23