2022-04-23 22:28:01 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
2022-07-02 17:44:29 +02:00
|
|
|
#include <QPixmap>
|
2022-04-23 22:28:01 +02:00
|
|
|
|
|
|
|
class MemoryImageCache {
|
|
|
|
public:
|
|
|
|
MemoryImageCache(size_t maxsize = 25);
|
|
|
|
|
2022-07-02 17:44:29 +02:00
|
|
|
void addImage(QPixmap, const std::string& title, int type);
|
|
|
|
QPixmap getImage(const std::string& title, int type);
|
2022-04-23 22:28:01 +02:00
|
|
|
private:
|
|
|
|
void cleanUp();
|
|
|
|
|
|
|
|
struct CachedImage {
|
|
|
|
time_t lastaccessed = 0;
|
2022-07-02 17:44:29 +02:00
|
|
|
QPixmap imageref;
|
2022-04-23 22:28:01 +02:00
|
|
|
std::string title;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
bool operator<(const CachedImage& other) const;
|
|
|
|
};
|
|
|
|
static std::function<bool(const CachedImage&)> getImageMatcher(const std::string& title, int type);
|
|
|
|
|
|
|
|
std::list<CachedImage> cache;
|
|
|
|
size_t maxsize;
|
|
|
|
};
|