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 if (path.empty()) return false;
57 LottieFileCache &fileCache = LottieFileCache::get();
59 mModel = fileCache.find(path);
67 cout << "failed to open file = " << path.c_str() << endl;
70 std::stringstream buf;
73 LottieParser parser(const_cast<char *>(buf.str().data()));
74 mModel = parser.model();
75 fileCache.add(path, mModel);
83 std::shared_ptr<LOTModel> LottieLoader::model()