#include "../include/ResourceCache.hpp" #include #include using namespace std; namespace dchat { unordered_map fonts; const sf::Font& ResourceCache::getFont(const string &filepath) { auto it = fonts.find(filepath); if(it != fonts.end()) return *it->second; sf::Font *font = new sf::Font(); if(!font->loadFromFile(filepath)) { delete font; string errMsg = "Failed to load font: "; errMsg += filepath; throw runtime_error(errMsg); } fonts[filepath] = font; return *font; } }