Sauce-0.10.1 A C++ Dependency Injection Framework

- Main Page
- Classes
- Files

- File List

self_injector.h
1 #ifndef SAUCE_INTERNAL_SELF_INJECTOR_H_
2 #define SAUCE_INTERNAL_SELF_INJECTOR_H_
3
4 #include <sauce/memory.h>
5
6 namespace sauce {
7 namespace internal {
8
15 template<typename T>
16 class SelfInjector { // TODO Ditch this thing.
17 typedef sauce::shared_ptr<T> Ptr;
18
19 template<typename DoesNotRequest>
20 void setSelfIfRequested(Ptr, ...) {}
21
22 template<typename Requests>
23 void setSelfIfRequested(Ptr ptr, typename Requests::RequestsSelfInjection *) {
24 sauce::weak_ptr<typename Requests::RequestsSelfInjection> weak(ptr);
25 ptr->setSelf(weak);
26 }
27
28 public:
29
30 void setSelf(Ptr ptr) {
31 setSelfIfRequested<T>(ptr, 0);
32 }
33 };
34
35 }
36
37 namespace i = ::sauce::internal;
38
39 }
40
41 #endif // SAUCE_INTERNAL_SELF_INJECTOR_H_
sauce::internal::SelfInjector
If a type requests injection of its own smart pointer, do so.
Definition: self_injector.h:16
sauce::internal
Definition: binder.h:317
sauce
Definition: binder.h:21