21 #ifndef yap_WeakPtrCache_h
22 #define yap_WeakPtrCache_h
57 using cache_type = std::set<weak_ptr_type, std::owner_less<weak_ptr_type> >;
125 {
return Cache_.empty(); }
150 typename cache_type::iterator
begin()
151 {
return Cache_.begin(); }
154 typename cache_type::const_iterator
begin()
const
155 {
return Cache_.begin(); }
158 typename cache_type::iterator
end()
162 typename cache_type::const_iterator
end()
const
168 virtual std::ostream&
print(std::ostream& os)
const
170 for (
auto& w : *
this)
172 os << *w.lock() << std::endl;
191 inline std::ostream& operator<<(std::ostream& os, const WeakPtrCache<T>& C)
193 os <<
"contains " << C.size() <<
" elements, of which "
194 << C.count_expired() <<
" have expired" << std::endl;
std::shared_ptr< SpinAmplitude > shared_ptr_type
std::shared_ptr to T
Definition: WeakPtrCache.h:49
Template for a cache of weak_ptr's to objects.
Definition: WeakPtrCache.h:37
WeakPtrCache()=default
Default constructor (defaulted)
WeakPtrCache(std::vector< shared_ptr_type > V)
Construct cache from vector.
Definition: WeakPtrCache.h:77
std::set< weak_ptr_type, std::owner_less< weak_ptr_type > > cache_type
A std::set of weak_ptr_type.
Definition: WeakPtrCache.h:57
size_t size() const
Definition: WeakPtrCache.h:128
WeakPtrCache & operator=(const WeakPtrCache &)=default
copy assignment operator (defaulted)
virtual std::ostream & print(std::ostream &os) const
stream the cache elements as a table
Definition: WeakPtrCache.h:168
cache_type Cache_
set of weak pointers to objects
Definition: WeakPtrCache.h:185
bool empty() const
Definition: WeakPtrCache.h:124
virtual bool equal(const shared_ptr_type &A, const shared_ptr_type &B) const =0
override to implement equality checking
void removeExpired()
remove expired Cache_ elements
Definition: WeakPtrCache.h:136
cache_type::iterator begin()
Definition: WeakPtrCache.h:150
cache_type::const_iterator begin() const
Definition: WeakPtrCache.h:154
std::weak_ptr< SpinAmplitude > weak_ptr_type
std::weak_ptr to T
Definition: WeakPtrCache.h:53
cache_type::iterator end()
Definition: WeakPtrCache.h:158
shared_ptr_type operator[](shared_ptr_type t)
Definition: WeakPtrCache.h:110
virtual ~WeakPtrCache()=default
virtual desctructor (defaulted)
cache_type::const_iterator end() const
Definition: WeakPtrCache.h:162
virtual void addToCache(shared_ptr_type t)
add element to cache
Definition: WeakPtrCache.h:179
weak_ptr_type find(shared_ptr_type t) const
Definition: WeakPtrCache.h:93
size_t count_expired() const
Definition: WeakPtrCache.h:132
Abstract base class implementing a spin amplitude.
Definition: SpinAmplitude.h:46