Sauce-0.10.1
A C++ Dependency Injection Framework
Public Member Functions | List of all members
sauce::internal::ScopeCache Class Reference

Public Member Functions

template<typename Dependency >
void put (typename Key< Dependency >::Ptr pointer)
 Insert a dependency into the cache. More...
 
template<typename Dependency >
bool get (typename Key< Dependency >::Ptr &out) const
 Probe the cache for a dependency. More...
 

Constructor & Destructor Documentation

◆ ScopeCache()

sauce::internal::ScopeCache::ScopeCache ( )
inline
27 :
28 cache() {}

Member Function Documentation

◆ get()

template<typename Dependency >
bool sauce::internal::ScopeCache::get ( typename Key< Dependency >::Ptr &  out) const
inline

Probe the cache for a dependency.

The return value indicates if a hit was found. On a hit, the out argument will be overwritten with the discovered value.

66 {
67 typedef typename Key<Dependency>::Normalized Normalized;
68 typedef typename Key<Normalized>::Ptr SmartPtr;
69
70 Cache::const_iterator cachedPtr = cache.find(typeIdOf<Normalized>());
71 if (cachedPtr == cache.end()) {
72 return false;
73 }
74
75 out = *static_cast<SmartPtr *>(cachedPtr->second.get());
76 return true;
77 }
Named< Dependency, Unnamed > Normalized
Note Normalized is not Iface, but Named<Iface, Unnamed>.
Definition: key.h:27

◆ put()

template<typename Dependency >
void sauce::internal::ScopeCache::put ( typename Key< Dependency >::Ptr  pointer)
inline

Insert a dependency into the cache.

34 {
35 typedef typename Key<Dependency>::Normalized Normalized;
36 typedef typename Key<Normalized>::Ptr SmartPtr;
37
38 /*
39 * A voice! a voice! It rang deep to the very last. It survived his strength to hide in the
40 * magnificent folds of eloquence the barren darkness of his heart. Oh, he struggled! he
41 * struggled! The wastes of his weary brain were haunted by shadowy images now – images of
42 * wealth and fame revolving obsequiously round his unextinguishable gift of noble and lofty
43 * expression. My Intended, my station, my career, my ideas – these were the subjects for the
44 * occasional utterances of elevated sentiments.
45 */
46
47 /*
48 * (Make the new smart ptr type agnostic by shoving it into *another* smart pointer.
49 * The deleter casts it back so the reference count isn't leaked.)
50 */
51
52 CachedPtr cachedPtr(
53 static_cast<void *>(new SmartPtr(pointer)),
54 ScopeCacheLineDeleter<Normalized>());
55
56 cache.insert(std::make_pair(typeIdOf<Normalized>(), cachedPtr));
57 }

The documentation for this class was generated from the following file: