Fix clang code model warning

This commit is contained in:
subhransu mohanty 2019-07-09 16:06:12 +09:00 committed by Subhransu
parent ff38323a65
commit 3094041f54
6 changed files with 44 additions and 53 deletions

View File

@ -367,14 +367,9 @@ void Animation::setValue(Point_Type, Property prop, const std::string &keypath,
d->setValue(keypath, LOTVariant(prop, value)); d->setValue(keypath, LOTVariant(prop, value));
} }
Animation::~Animation() = default;
Animation::Animation() : d(std::make_unique<AnimationImpl>()) {} Animation::Animation() : d(std::make_unique<AnimationImpl>()) {}
/*
* this is only to supress build fail
* because unique_ptr expects the destructor in the same translation unit.
*/
Animation::~Animation() {}
Surface::Surface(uint32_t *buffer, size_t width, size_t height, Surface::Surface(uint32_t *buffer, size_t width, size_t height,
size_t bytesPerLine) size_t bytesPerLine)
: mBuffer(buffer), : mBuffer(buffer),

View File

@ -1253,7 +1253,7 @@ void LOTPolystarItem::updatePath(VPath &path, int frameNo)
path.reset(); path.reset();
VMatrix m; VMatrix m;
if (mData->mType == LOTPolystarData::PolyType::Star) { if (mData->mPolyType == LOTPolystarData::PolyType::Star) {
path.addPolystar(points, innerRadius, outerRadius, innerRoundness, path.addPolystar(points, innerRadius, outerRadius, innerRoundness,
outerRoundness, 0.0, 0.0, 0.0, mData->direction()); outerRoundness, 0.0, 0.0, 0.0, mData->direction());
} else { } else {

View File

@ -22,7 +22,7 @@
#include<vector> #include<vector>
#include<memory> #include<memory>
#include<unordered_map> #include<unordered_map>
#include <algorithm> #include <cmath>
#include"vpoint.h" #include"vpoint.h"
#include"vrect.h" #include"vrect.h"
#include"vinterpolator.h" #include"vinterpolator.h"
@ -102,7 +102,7 @@ inline const LottieColor operator*(float m, const LottieColor &c)
class LottieShapeData class LottieShapeData
{ {
public: public:
void reserve(int size) { void reserve(size_t size) {
mPoints.reserve(mPoints.size() + size); mPoints.reserve(mPoints.size() + size);
} }
void toPath(VPath& path) { void toPath(VPath& path) {
@ -110,23 +110,23 @@ public:
if (mPoints.empty()) return; if (mPoints.empty()) return;
int size = mPoints.size(); auto size = mPoints.size();
const VPointF *points = mPoints.data(); auto points = mPoints.data();
/* reserve exact memory requirement at once /* reserve exact memory requirement at once
* ptSize = size + 1(size + close) * ptSize = size + 1(size + close)
* elmSize = size/3 cubic + 1 move + 1 close * elmSize = size/3 cubic + 1 move + 1 close
*/ */
path.reserve(size + 1 , size/3 + 2); path.reserve(size + 1 , size/3 + 2);
path.moveTo(points[0]); path.moveTo(points[0]);
for (int i = 1 ; i < size; i+=3) { for (size_t i = 1 ; i < size; i+=3) {
path.cubicTo(points[i], points[i+1], points[i+2]); path.cubicTo(points[i], points[i+1], points[i+2]);
} }
if (mClosed) if (mClosed)
path.close(); path.close();
} }
public: public:
std::vector<VPointF> mPoints; std::vector<VPointF> mPoints;
bool mClosed = false; /* "c" */ bool mClosed = false; /* "c" */
}; };
@ -617,7 +617,7 @@ inline int LOTLayerData::timeRemap(int frameNo) const
* Time streach factor is already applied to the layers inFrame and outFrame. * Time streach factor is already applied to the layers inFrame and outFrame.
* @TODO need to find out if timestreatch also affects the in and out frame of the * @TODO need to find out if timestreatch also affects the in and out frame of the
* child layers or not. */ * child layers or not. */
return frameNo / mTimeStreatch; return int(frameNo / mTimeStreatch);
} }
class LOTFillData : public LOTData class LOTFillData : public LOTData
@ -797,7 +797,7 @@ public:
Intersect, Intersect,
Difference Difference
}; };
float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0;} float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0f;}
bool isStatic() const {return mIsStatic;} bool isStatic() const {return mIsStatic;}
public: public:
LOTAnimatable<LottieShapeData> mShape; LOTAnimatable<LottieShapeData> mShape;
@ -835,7 +835,7 @@ public:
}; };
LOTPolystarData():LOTPath(LOTData::Type::Polystar){} LOTPolystarData():LOTPath(LOTData::Type::Polystar){}
public: public:
LOTPolystarData::PolyType mType{PolyType::Polygon}; LOTPolystarData::PolyType mPolyType{PolyType::Polygon};
LOTAnimatable<VPointF> mPos; LOTAnimatable<VPointF> mPos;
LOTAnimatable<float> mPointCount{0}; LOTAnimatable<float> mPointCount{0};
LOTAnimatable<float> mInnerRadius{0}; LOTAnimatable<float> mInnerRadius{0};
@ -867,9 +867,9 @@ public:
Segment segment(int frameNo) const { Segment segment(int frameNo) const {
float start = mStart.value(frameNo)/100.0f; float start = mStart.value(frameNo)/100.0f;
float end = mEnd.value(frameNo)/100.0f; float end = mEnd.value(frameNo)/100.0f;
float offset = fmod(mOffset.value(frameNo), 360.0f)/ 360.0f; float offset = std::fmod(mOffset.value(frameNo), 360.0f)/ 360.0f;
float diff = fabs(start - end); float diff = std::abs(start - end);
if (vCompare(diff, 0.0f)) return Segment(0, 0); if (vCompare(diff, 0.0f)) return Segment(0, 0);
if (vCompare(diff, 1.0f)) return Segment(0, 1); if (vCompare(diff, 1.0f)) return Segment(0, 1);

View File

@ -95,7 +95,7 @@ public:
v_.SetInt64(i); v_.SetInt64(i);
return true; return true;
} }
bool Uint64(uint64_t u) bool Uint64(int64_t u)
{ {
st_ = kHasNumber; st_ = kHasNumber;
v_.SetUint64(u); v_.SetUint64(u);
@ -143,7 +143,6 @@ public:
protected: protected:
explicit LookaheadParserHandler(char *str); explicit LookaheadParserHandler(char *str);
void ParseNext();
protected: protected:
enum LookaheadParsingState { enum LookaheadParsingState {
@ -168,13 +167,14 @@ protected:
static const int parseFlags = kParseDefaultFlags | kParseInsituFlag; static const int parseFlags = kParseDefaultFlags | kParseInsituFlag;
}; };
class LottieParserImpl : protected LookaheadParserHandler { class LottieParserImpl : public LookaheadParserHandler {
public: public:
LottieParserImpl(char *str, const char *dir_path) LottieParserImpl(char *str, const char *dir_path)
: LookaheadParserHandler(str), mDirPath(dir_path) : LookaheadParserHandler(str), mDirPath(dir_path)
{ {
ParseNext();
} }
void ParseNext();
public: public:
bool EnterObject(); bool EnterObject();
bool EnterArray(); bool EnterArray();
@ -190,9 +190,7 @@ public:
void SkipArray(); void SkipArray();
void SkipValue(); void SkipValue();
Value *PeekValue(); Value *PeekValue();
int PeekType(); // returns a rapidjson::Type, or -1 for no value (at end of int PeekType() const;
// object/array)
bool IsValid() { return st_ != kError; } bool IsValid() { return st_ != kError; }
void Skip(const char *key); void Skip(const char *key);
@ -280,10 +278,9 @@ LookaheadParserHandler::LookaheadParserHandler(char *str)
: v_(), st_(kInit), r_(), ss_(str) : v_(), st_(kInit), r_(), ss_(str)
{ {
r_.IterativeParseInit(); r_.IterativeParseInit();
ParseNext();
} }
void LookaheadParserHandler::ParseNext() void LottieParserImpl::ParseNext()
{ {
if (r_.HasParseError()) { if (r_.HasParseError()) {
st_ = kError; st_ = kError;
@ -338,17 +335,17 @@ const char *LottieParserImpl::NextObjectKey()
// #ifdef DEBUG_PARSER // #ifdef DEBUG_PARSER
// vDebug<<"Object: Exiting nested loop"; // vDebug<<"Object: Exiting nested loop";
// #endif // #endif
return 0; return nullptr;
} }
if (st_ != kExitingObject) { if (st_ != kExitingObject) {
RAPIDJSON_ASSERT(false); RAPIDJSON_ASSERT(false);
st_ = kError; st_ = kError;
return 0; return nullptr;
} }
ParseNext(); ParseNext();
return 0; return nullptr;
} }
bool LottieParserImpl::NextArrayValue() bool LottieParserImpl::NextArrayValue()
@ -431,7 +428,7 @@ const char *LottieParserImpl::GetString()
if (st_ != kHasString) { if (st_ != kHasString) {
st_ = kError; st_ = kError;
RAPIDJSON_ASSERT(false); RAPIDJSON_ASSERT(false);
return 0; return nullptr;
} }
const char *result = v_.GetString(); const char *result = v_.GetString();
@ -476,10 +473,12 @@ Value *LottieParserImpl::PeekValue()
return &v_; return &v_;
} }
return 0; return nullptr;
} }
int LottieParserImpl::PeekType() // returns a rapidjson::Type, or -1 for no value (at end of
// object/array)
int LottieParserImpl::PeekType() const
{ {
if (st_ >= kHasNull && st_ <= kHasKey) { if (st_ >= kHasNull && st_ <= kHasKey) {
return v_.GetType(); return v_.GetType();
@ -621,9 +620,9 @@ static constexpr const unsigned char B64index[256] = {
25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51}; 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
std::string b64decode(const void *data, const size_t len) std::string b64decode(const char *data, const size_t len)
{ {
unsigned char *p = (unsigned char *)data; auto p = reinterpret_cast<const unsigned char *>(data);
int pad = len > 0 && (len % 4 || p[len - 1] == '='); int pad = len > 0 && (len % 4 || p[len - 1] == '=');
const size_t L = ((len + 3) / 4 - pad) * 4; const size_t L = ((len + 3) / 4 - pad) * 4;
std::string str(L / 4 * 3 + pad, '\0'); std::string str(L / 4 * 3 + pad, '\0');
@ -764,7 +763,7 @@ void LottieParserImpl::parseLayers(LOTCompositionData *comp)
LottieColor LottieParserImpl::toColor(const char *str) LottieColor LottieParserImpl::toColor(const char *str)
{ {
LottieColor color; LottieColor color;
int len = strlen(str); auto len = strlen(str);
// some resource has empty color string // some resource has empty color string
// return a default color for those cases. // return a default color for those cases.
@ -776,15 +775,15 @@ LottieColor LottieParserImpl::toColor(const char *str)
char tmp[3] = {'\0', '\0', '\0'}; char tmp[3] = {'\0', '\0', '\0'};
tmp[0] = str[1]; tmp[0] = str[1];
tmp[1] = str[2]; tmp[1] = str[2];
color.r = std::strtol(tmp, NULL, 16) / 255.0; color.r = std::strtol(tmp, nullptr, 16) / 255.0f;
tmp[0] = str[3]; tmp[0] = str[3];
tmp[1] = str[4]; tmp[1] = str[4];
color.g = std::strtol(tmp, NULL, 16) / 255.0; color.g = std::strtol(tmp, nullptr, 16) / 255.0f;
tmp[0] = str[5]; tmp[0] = str[5];
tmp[1] = str[6]; tmp[1] = str[6];
color.b = std::strtol(tmp, NULL, 16) / 255.0; color.b = std::strtol(tmp, nullptr, 16) / 255.0f;
return color; return color;
} }
@ -1233,8 +1232,8 @@ std::shared_ptr<LOTData> LottieParserImpl::parsePolystarObject()
parseProperty(obj->mRotation); parseProperty(obj->mRotation);
} else if (0 == strcmp(key, "sy")) { } else if (0 == strcmp(key, "sy")) {
int starType = GetInt(); int starType = GetInt();
if (starType == 1) obj->mType = LOTPolystarData::PolyType::Star; if (starType == 1) obj->mPolyType = LOTPolystarData::PolyType::Star;
if (starType == 2) obj->mType = LOTPolystarData::PolyType::Polygon; if (starType == 2) obj->mPolyType = LOTPolystarData::PolyType::Polygon;
} else if (0 == strcmp(key, "d")) { } else if (0 == strcmp(key, "d")) {
obj->mDirection = GetInt(); obj->mDirection = GetInt();
} else if (0 == strcmp(key, "hd")) { } else if (0 == strcmp(key, "hd")) {
@ -1813,10 +1812,10 @@ void LottieParserImpl::getValue(LottieShapeData &obj)
vCritical << "The Shape data are corrupted"; vCritical << "The Shape data are corrupted";
points = std::vector<VPointF>(); points = std::vector<VPointF>();
} else { } else {
int size = vertices.size(); auto size = vertices.size();
points.reserve(3 * size + 4); points.reserve(3 * size + 4);
points.push_back(vertices[0]); points.push_back(vertices[0]);
for (int i = 1; i < size; i++) { for (size_t i = 1; i < size; i++) {
points.push_back(vertices[i - 1] + points.push_back(vertices[i - 1] +
outPoint[i - 1]); // CP1 = start + outTangent outPoint[i - 1]); // CP1 = start + outTangent
points.push_back(vertices[i] + points.push_back(vertices[i] +
@ -2060,7 +2059,7 @@ void LottieParserImpl::parseProperty(LOTAnimatable<T> &obj)
} }
} }
#if LOTTIE_DUMP_TREE_SUPPORT #ifdef LOTTIE_DUMP_TREE_SUPPORT
class LOTDataInspector { class LOTDataInspector {
public: public:
@ -2243,13 +2242,9 @@ public:
#endif #endif
LottieParser::~LottieParser() LottieParser::~LottieParser() = default;
{
delete d;
}
LottieParser::LottieParser(char *str, const char *dir_path) LottieParser::LottieParser(char *str, const char *dir_path)
: d(new LottieParserImpl(str, dir_path)) : d(std::make_unique<LottieParserImpl>(str, dir_path))
{ {
d->parseComposition(); d->parseComposition();
} }

View File

@ -20,6 +20,7 @@
#define LOTTIEPARSER_H #define LOTTIEPARSER_H
#include "lottiemodel.h" #include "lottiemodel.h"
#include <memory>
class LottieParserImpl; class LottieParserImpl;
class LottieParser { class LottieParser {
@ -28,7 +29,7 @@ public:
LottieParser(char* str, const char *dir_path); LottieParser(char* str, const char *dir_path);
std::shared_ptr<LOTModel> model(); std::shared_ptr<LOTModel> model();
private: private:
LottieParserImpl *d; std::unique_ptr<LottieParserImpl> d;
}; };
#endif // LOTTIEPARSER_H #endif // LOTTIEPARSER_H

View File

@ -467,7 +467,7 @@ public:
class RleTaskScheduler { class RleTaskScheduler {
public: public:
FTOutline outlineRef; FTOutline outlineRef{};
SW_FT_Stroker stroker; SW_FT_Stroker stroker;
public: public: