From 6377407e38c99948c1df42bae4960cc967b2ee8f Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Wed, 12 Sep 2018 10:09:44 +0900 Subject: [PATCH] lottie: update the loadfromData() api signature. Change-Id: I801f39d06ce67d30be37dc14733ad99ae3a54da2 --- example/lottieview.cpp | 4 ++-- example/lottieview.h | 2 +- inc/lottieanimation.h | 2 +- src/lottie/lottieanimation.cpp | 6 +++--- src/lottie/lottieloader.cpp | 9 ++++----- src/lottie/lottieloader.h | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/example/lottieview.cpp b/example/lottieview.cpp index 5fc234d..bc7eb40 100644 --- a/example/lottieview.cpp +++ b/example/lottieview.cpp @@ -241,13 +241,13 @@ void LottieView::setFilePath(const char *filePath) } } -void LottieView::loadFromData(const char *jsonData, const char *key) +void LottieView::loadFromData(const std::string &jsonData, const std::string &key) { if (mPlayer = Animation::loadFromData(jsonData, key)) { mFrameRate = mPlayer->frameRate(); mTotalFrame = mPlayer->totalFrame(); } else { - printf("load failed from data key : %s\n", key); + printf("load failed from data key : %s\n", key.c_str()); } } diff --git a/example/lottieview.h b/example/lottieview.h index 08e98cf..deae8e5 100644 --- a/example/lottieview.h +++ b/example/lottieview.h @@ -30,7 +30,7 @@ public: void setSize(int w, int h); void setPos(int x, int y); void setFilePath(const char *filePath); - void loadFromData(const char *jsonData, const char *key); + void loadFromData(const std::string &jsonData, const std::string &key); void show(); void hide(); void loop(bool loop); diff --git a/inc/lottieanimation.h b/inc/lottieanimation.h index b75019d..c2a4e26 100644 --- a/inc/lottieanimation.h +++ b/inc/lottieanimation.h @@ -109,7 +109,7 @@ public: * lottie resource represented by JSON string data. */ static std::unique_ptr - loadFromData(const char *jsonData, const char *key); + loadFromData(std::string jsonData, const std::string &key); /** * @brief Returns default framerate of the lottie resource. diff --git a/src/lottie/lottieanimation.cpp b/src/lottie/lottieanimation.cpp index 0ccb41a..07dfcb0 100644 --- a/src/lottie/lottieanimation.cpp +++ b/src/lottie/lottieanimation.cpp @@ -190,15 +190,15 @@ static RenderTaskScheduler render_scheduler; * @param path add the details */ std::unique_ptr -Animation::loadFromData(const char *jsonData, const char *key) +Animation::loadFromData(std::string jsonData, const std::string &key) { - if (!jsonData) { + if (jsonData.empty()) { vWarning << "jason data is empty"; return nullptr; } LottieLoader loader; - if (loader.loadFromData(jsonData, key)) { + if (loader.loadFromData(std::move(jsonData), key)) { auto animation = std::make_unique(); animation->d->init(loader.model()); return animation; diff --git a/src/lottie/lottieloader.cpp b/src/lottie/lottieloader.cpp index eb30298..6d2f4cc 100644 --- a/src/lottie/lottieloader.cpp +++ b/src/lottie/lottieloader.cpp @@ -65,17 +65,16 @@ bool LottieLoader::load(const std::string &path) return true; } -bool LottieLoader::loadFromData(const char *jsonData, const char *key) +bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key) { LottieFileCache &fileCache = LottieFileCache::get(); - std::string keyString(key); - mModel = fileCache.find(std::string(keyString)); + mModel = fileCache.find(key); if (mModel) return true; - LottieParser parser(const_cast(std::string(jsonData).c_str())); + LottieParser parser(const_cast(jsonData.c_str())); mModel = parser.model(); - fileCache.add(keyString, mModel); + fileCache.add(key, mModel); return true; } diff --git a/src/lottie/lottieloader.h b/src/lottie/lottieloader.h index da6bb35..42b8e53 100644 --- a/src/lottie/lottieloader.h +++ b/src/lottie/lottieloader.h @@ -9,7 +9,7 @@ class LottieLoader { public: bool load(const std::string &filePath); - bool loadFromData(const char *jsonData, const char *key); + bool loadFromData(std::string &&jsonData, const std::string &key); std::shared_ptr model(); private: std::shared_ptr mModel; -- 2.7.4