6 #include "../core/event.h" 15 void loadResource(
const std::string &url, std::string &data);
16 void loadResource(
const std::string &url, std::vector<uint8_t> &data);
23 class ResourceBase :
public std::enable_shared_from_this<ResourceBase> {
24 bool _invalidate_connected =
false;
25 EventFlag _invalidated{ResourceEvents::instance().reload};
28 void cleanup(
const std::function<
void()> &callback);
29 bool invalidated() { _invalidated.poll(); }
32 static void setCleanupFunction(
33 const std::function<
void(
const std::function<
void()> &)> &callback);
41 std::map<std::tuple<ARGS...>, std::weak_ptr<T>> _map;
44 std::shared_ptr<T> load(
const ARGS &... args) {
45 std::lock_guard<std::mutex> lock(_mutex);
46 auto &item = _map[std::make_tuple(args...)];
47 std::shared_ptr<T> ret = item.lock();
49 ret = std::make_shared<T>(args...);
54 std::shared_ptr<T> fetchExisting(
const ARGS &... args) {
55 std::lock_guard<std::mutex> lock(_mutex);
56 auto &item = _map[std::make_tuple(args...)];
60 std::lock_guard<std::mutex> lock(_mutex);