8 #include <resource_retriever/retriever.h> 17 static std::mutex g_cleanup_mutex;
18 static std::function<void(const std::function<void()> &)> g_cleanup_function =
21 void ResourceBase::cleanup(
const std::function<
void()> &callback) {
22 std::lock_guard<std::mutex> lock(g_cleanup_mutex);
23 if (g_cleanup_function) {
24 g_cleanup_function(callback);
30 void ResourceBase::setCleanupFunction(
31 const std::function<
void(
const std::function<
void()> &)> &callback) {
32 std::lock_guard<std::mutex> lock(g_cleanup_mutex);
33 g_cleanup_function = callback;
36 static resource_retriever::Retriever &resourceRetreiver() {
37 static thread_local resource_retriever::Retriever retriever;
41 void loadResource(
const std::string &url, std::string &data) {
42 auto resource = resourceRetreiver().get(url);
43 data.assign((
const char *)resource.data.get(), resource.size);
46 void loadResource(
const std::string &url, std::vector<uint8_t> &data) {
47 auto resource = resourceRetreiver().get(url);
48 data.assign((
const uint8_t *)resource.data.get(),
49 (
const uint8_t *)resource.data.get() + resource.size);