29 double PixelsPerSecond { 0.0 };
31 int64_t FirstSample { -1 };
39 virtual void Dispose();
44 uint64_t LastCacheAccess { 0 };
46 uint64_t LastUpdate { 0 };
48 bool IsComplete {
false };
50 bool AwaitsEviction {
false };
58 constexpr static uint32_t CacheElementWidth = 256;
66 double GetScaledSampleRate() const noexcept;
68 void UpdateViewportWidth(int64_t width) noexcept;
69 int64_t GetMaxViewportWidth() const noexcept;
74 void SetScaledSampleRate(
double scaledSampleRate);
83 using Lookup = std::vector<LookupElement>;
95 size_t RightOffset {};
114 bool CreateNewItems();
116 void DisposeNewItems();
120 void PerformCleanup();
122 void PerformFullCleanup(int64_t currentSize, int64_t itemsToEvict);
133 double mScaledSampleRate {};
136 int64_t mMaxWidth { 1600 };
138 uint64_t mCacheAccessIndex {};
140 int32_t mCacheSizeMultiplier { 4 };
142 template <
typename CacheElementType>
147template <
typename CacheElementType>
223 GraphicsDataCacheBase::Lookup::const_iterator
mIterator;
225 template <
typename T>
230template<
typename CacheElementType>
258 return { { base,
true }, { base,
false } };
280 if constexpr (std::is_assignable_v<
286 else if constexpr (std::is_constructible_v<
289 element = CacheElementType(
key);
301 CacheElementType* element =
nullptr;
309 if (element ==
nullptr)
312 element =
mCache.back().get();
315 if (element ==
nullptr)
337 if (element ==
nullptr)
342 mFreeList.push_back(
static_cast<CacheElementType*
>(element));
355 std::deque<std::unique_ptr<CacheElementType>>
mCache;
A base class for the GraphicsDataCache. Implements LRU policy.
virtual ~GraphicsDataCacheBase()=default
std::vector< size_t > mLRUHelper
virtual void DisposeElement(GraphicsDataCacheElementBase *element)=0
This method is called, when the cache element should be evicted. Implementation may not deallocate th...
virtual bool UpdateElement(const GraphicsDataCacheKey &key, GraphicsDataCacheElementBase &element)=0
This method is called on all elements matching the request that are not complete (i....
BaseLookupResult PerformBaseLookup(const ZoomInfo &zoomInfo, double t0, double t1)
Perform a lookup inside the cache. This method modifies mLookup and invalidates any previous result.
void Invalidate()
Invalidate the cache content.
virtual GraphicsDataCacheElementBase * CreateElement(const GraphicsDataCacheKey &key)=0
Create a new Cache element. Implementation is responsible of the lifetime control.
std::vector< LookupElement > Lookup
Cache lookup is a vector, with items sorted using Key.
~GraphicsDataCache() override
IteratorRange< GraphicsDataCacheIterator< CacheElementType > > PerformLookup(const ZoomInfo &zoomInfo, double t0, double t1)
const CacheElementType * PerformLookup(GraphicsDataCacheKey key)
GraphicsDataCache(const GraphicsDataCache &)=delete
std::vector< CacheElementType * > mFreeList
std::function< std::unique_ptr< CacheElementType >()> ElementFactory
void setInitializer(Initializer initializer)
GraphicsDataCache(double scaledSampleRate, ElementFactory elementFactory)
GraphicsDataCache & operator=(const GraphicsDataCache &)=delete
GraphicsDataCacheElementBase * CreateElement(const GraphicsDataCacheKey &key) override
Create a new Cache element. Implementation is responsible of the lifetime control.
virtual void CheckCache(const ZoomInfo &, double, double)
void DisposeElement(GraphicsDataCacheElementBase *element) override
This method is called, when the cache element should be evicted. Implementation may not deallocate th...
std::deque< std::unique_ptr< CacheElementType > > mCache
virtual bool InitializeElement(const GraphicsDataCacheKey &key, CacheElementType &element)
std::function< bool(const GraphicsDataCacheKey &Key, CacheElementType &element)> Initializer
bool UpdateElement(const GraphicsDataCacheKey &key, GraphicsDataCacheElementBase &element) override
This method is called on all elements matching the request that are not complete (i....
ElementFactory mElementFactory
A class that implements an iterator for the cache lookup result.
GraphicsDataCacheIterator()=default
std::ptrdiff_t difference_type
GraphicsDataCacheIterator & operator=(const GraphicsDataCacheIterator &)=default
GraphicsDataCacheIterator(GraphicsDataCacheIterator &&)=default
GraphicsDataCacheIterator operator++(int)
CacheElementType value_type
GraphicsDataCacheIterator(const GraphicsDataCacheBase::BaseLookupResult &base, bool begin)
friend bool operator!=(const GraphicsDataCacheIterator &lhs, const GraphicsDataCacheIterator &rhs)
reference operator*() const
friend bool operator==(const GraphicsDataCacheIterator &lhs, const GraphicsDataCacheIterator &rhs)
GraphicsDataCacheBase::BaseLookupResult mBaseLookup
GraphicsDataCacheIterator & operator=(GraphicsDataCacheIterator &&)=default
GraphicsDataCacheIterator & operator++()
size_t GetRightOffset() const
std::forward_iterator_tag iterator_category
GraphicsDataCacheIterator(const GraphicsDataCacheIterator &)=default
size_t GetLeftOffset() const
GraphicsDataCacheBase::Lookup::const_iterator mIterator
RegisteredInitializer initializer
bool Begin(const FilePath &dataDir)
const char * begin(const char *str) noexcept
A result of the cache lookup.
size_t RightOffset
Offset from the right for the last element that matches the request.
Lookup::iterator Begin
Iterator to the first cache element that fulfills the request.
size_t LeftOffset
First column of the first element that matches the request.
Lookup::iterator End
Iterator past the last cache element that fulfills the request.
Element of the cache lookup.
A base class for the for cache elements.
virtual void Dispose()
This method is called when the item is evicted from the cache. Default implementation is empty.
virtual ~GraphicsDataCacheElementBase()=default
A key into the graphics data cache.
A convenience for use with range-for.