1 #include "lottieloader.h"
2 #include "lottieparser.h"
5 #include<unordered_map>
13 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);
23 std::unordered_map<std::string, std::shared_ptr<LOTModel>> mHash;
27 LottieFileCache::~LottieFileCache()
31 std::shared_ptr<LOTModel>
32 LottieFileCache::find(std::string &key)
34 auto search = mHash.find(key);
35 if (search != mHash.end()) {
36 return search->second;
43 LottieFileCache::add(std::string &key, std::shared_ptr<LOTModel> value)
48 LottieLoader::LottieLoader()
53 bool LottieLoader::load(std::string &path)
55 LottieFileCache &fileCache = LottieFileCache::get();
57 mModel = fileCache.find(path);
65 cout << "failed to open file = " << path.c_str() << endl;
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()