1 #include "lottieloader.h"
2 #include "lottieparser.h"
5 #include <unordered_map>
9 class LottieFileCache {
12 static LottieFileCache &get()
14 static LottieFileCache CACHE;
18 std::shared_ptr<LOTModel> find(std::string &key);
19 void add(std::string &key, std::shared_ptr<LOTModel> value);
24 std::unordered_map<std::string, std::shared_ptr<LOTModel>> mHash;
27 LottieFileCache::~LottieFileCache() {}
28 std::shared_ptr<LOTModel> LottieFileCache::find(std::string &key)
30 auto search = mHash.find(key);
31 if (search != mHash.end()) {
32 return search->second;
38 void LottieFileCache::add(std::string &key, std::shared_ptr<LOTModel> value)
43 LottieLoader::LottieLoader() {}
45 bool LottieLoader::load(std::string &path)
47 LottieFileCache &fileCache = LottieFileCache::get();
49 mModel = fileCache.find(path);
50 if (mModel) return true;
56 vCritical << "failed to open file = " << path.c_str();
59 std::stringstream buf;
62 LottieParser parser(const_cast<char *>(buf.str().data()));
63 mModel = parser.model();
64 fileCache.add(path, mModel);
72 std::shared_ptr<LOTModel> LottieLoader::model()