1 #ifndef OPENMW_COMPONENTS_WEAKCACHE_HPP
2 #define OPENMW_COMPONENTS_WEAKCACHE_HPP
5 #include <unordered_map>
12 template <
typename Key,
typename T>
18 using Map = std::unordered_map<Key, WeakPtr>;
53 template <
typename Key,
typename T>
68 template <
typename Key,
typename T>
73 return *
this =
iterator(mCache, next, mEnd);
76 template <
typename Key,
typename T>
82 template <
typename Key,
typename T>
85 return !(*
this == other);
88 template <
typename Key,
typename T>
95 template <
typename Key,
typename T>
99 if (shouldPrune)
prune();
102 template <
typename Key,
typename T>
105 auto searchIt =
mData.find(key);
106 if (searchIt !=
mData.end())
107 return searchIt->second.lock();
112 template <
typename Key,
typename T>
118 template <
typename Key,
typename T>
124 template <
typename Key,
typename T>
130 auto it =
mData.find(key);
131 if (it !=
mData.end() && it->second.use_count() == 0)
std::unordered_map< std::string, WeakPtr > Map
Definition: weakcache.hpp:18
iterator end()
Definition: weakcache.hpp:119
StrongPtr get(Key key)
Definition: weakcache.hpp:103
Map::iterator mCurrent
Definition: weakcache.hpp:30
bool operator==(const iterator &other)
Definition: weakcache.hpp:77
iterator & operator++()
Definition: weakcache.hpp:69
StrongPtr mPtr
Definition: weakcache.hpp:31
void prune()
Removes known invalid entries.
Definition: weakcache.hpp:125
Definition: weakcache.hpp:20
Map mData
Definition: weakcache.hpp:48
std::weak_ptr< CSMWorld::ActorAdapter::RaceData > WeakPtr
Definition: weakcache.hpp:16
std::shared_ptr< CSMWorld::ActorAdapter::RaceData > StrongPtr
Definition: weakcache.hpp:17
Definition: weakcache.hpp:13
void insert(Key key, StrongPtr value, bool prune=true)
Stores a weak pointer to the item.
Definition: weakcache.hpp:96
Map::iterator mEnd
Definition: weakcache.hpp:30
std::vector< Key > mDirty
Definition: weakcache.hpp:49
iterator(WeakCache *cache, typename Map::iterator current, typename Map::iterator end)
Definition: weakcache.hpp:54
WeakCache * mCache
Definition: weakcache.hpp:29
bool operator!=(const iterator &other)
Definition: weakcache.hpp:83
StrongPtr operator*()
Definition: weakcache.hpp:89
iterator begin()
Definition: weakcache.hpp:113