1 #include "lottieloader.h"
2 #include "lottieparser.h"
5 #include<unordered_map>
11 static LottieFileCache &get() {
12 static LottieFileCache CACHE;
16 std::shared_ptr<LOTModel> find(std::string &key);
17 void add(std::string &key, std::shared_ptr<LOTModel> value);
21 std::unordered_map<std::string, std::shared_ptr<LOTModel>> mHash;
25 LottieFileCache::~LottieFileCache()
29 std::shared_ptr<LOTModel>
30 LottieFileCache::find(std::string &key)
32 auto search = mHash.find(key);
33 if (search != mHash.end()) {
34 return search->second;
41 LottieFileCache::add(std::string &key, std::shared_ptr<LOTModel> value)
46 LottieLoader::LottieLoader()
51 bool LottieLoader::load(std::string &path)
53 if (path.empty()) return false;
55 LottieFileCache &fileCache = LottieFileCache::get();
57 mModel = fileCache.find(path);
65 printf("failed to open \n");
68 std::stringstream buf;
71 LottieParser parser(const_cast<char *>(buf.str().data()));
72 mModel = parser.model();
73 fileCache.add(path, mModel);
81 std::shared_ptr<LOTModel> LottieLoader::model()