From 39b77361c5598c90faa32222b996f90756521600 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 30 Jul 2020 15:10:59 +0900 Subject: [PATCH] common: code refactoring. changed just internal variable & method names. no logical changes. Change-Id: I01782ec59dec3ff2232e03de7b3863100d9cc27f --- src/lib/tvgCanvasImpl.h | 8 ++++---- src/lib/tvgPaint.cpp | 10 +++++----- src/lib/tvgPaint.h | 24 +++++++++++++++++------- src/lib/tvgScene.cpp | 2 +- src/lib/tvgSceneImpl.h | 14 ++++---------- src/lib/tvgShape.cpp | 2 +- src/lib/tvgShapeImpl.h | 6 ------ 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/lib/tvgCanvasImpl.h b/src/lib/tvgCanvasImpl.h index a1b9b78..2776735 100644 --- a/src/lib/tvgCanvasImpl.h +++ b/src/lib/tvgCanvasImpl.h @@ -56,7 +56,7 @@ struct Canvas::Impl if (!renderer->clear()) return Result::InsufficientCondition; for (auto paint : paints) { - paint->IMPL->method->dispose(*renderer); + paint->IMPL->method()->dispose(*renderer); delete(paint); } paints.clear(); @@ -70,13 +70,13 @@ struct Canvas::Impl //Update single paint node if (paint) { - if (!paint->IMPL->method->update(*renderer, nullptr, RenderUpdateFlag::None)) { + if (!paint->IMPL->method()->update(*renderer, nullptr, RenderUpdateFlag::None)) { return Result::InsufficientCondition; } //Update retained all paint nodes } else { for(auto paint: paints) { - if (!paint->IMPL->method->update(*renderer, nullptr, RenderUpdateFlag::None)) { + if (!paint->IMPL->method()->update(*renderer, nullptr, RenderUpdateFlag::None)) { return Result::InsufficientCondition; } } @@ -91,7 +91,7 @@ struct Canvas::Impl if (!renderer->preRender()) return Result::InsufficientCondition; for(auto paint: paints) { - if(!paint->IMPL->method->render(*renderer)) return Result::InsufficientCondition; + if(!paint->IMPL->method()->render(*renderer)) return Result::InsufficientCondition; } if (!renderer->postRender()) return Result::InsufficientCondition; diff --git a/src/lib/tvgPaint.cpp b/src/lib/tvgPaint.cpp index cbd68c6..8aa62d2 100644 --- a/src/lib/tvgPaint.cpp +++ b/src/lib/tvgPaint.cpp @@ -39,35 +39,35 @@ Paint :: ~Paint() Result Paint::rotate(float degree) noexcept { - if (IMPL->method->rotate(degree)) return Result::Success; + if (IMPL->method()->rotate(degree)) return Result::Success; return Result::FailedAllocation; } Result Paint::scale(float factor) noexcept { - if (IMPL->method->scale(factor)) return Result::Success; + if (IMPL->method()->scale(factor)) return Result::Success; return Result::FailedAllocation; } Result Paint::translate(float x, float y) noexcept { - if (IMPL->method->translate(x, y)) return Result::Success; + if (IMPL->method()->translate(x, y)) return Result::Success; return Result::FailedAllocation; } Result Paint::transform(const Matrix& m) noexcept { - if (IMPL->method->transform(m)) return Result::Success; + if (IMPL->method()->transform(m)) return Result::Success; return Result::FailedAllocation; } Result Paint::bounds(float* x, float* y, float* w, float* h) const noexcept { - if (IMPL->method->bounds(x, y, w, h)) return Result::Success; + if (IMPL->method()->bounds(x, y, w, h)) return Result::Success; return Result::InsufficientCondition; } diff --git a/src/lib/tvgPaint.h b/src/lib/tvgPaint.h index 31dcbf4..45e4c01 100644 --- a/src/lib/tvgPaint.h +++ b/src/lib/tvgPaint.h @@ -19,9 +19,9 @@ namespace tvg { - struct PaintMethod + struct StrategyMethod { - virtual ~PaintMethod(){} + virtual ~StrategyMethod(){} virtual bool dispose(RenderMethod& renderer) = 0; virtual bool update(RenderMethod& renderer, const RenderTransform* pTransform, uint32_t pFlag) = 0; @@ -37,21 +37,31 @@ namespace tvg struct Paint::Impl { - PaintMethod* method = nullptr; + StrategyMethod* smethod = nullptr; ~Impl() { - if (method) delete(method); + if (smethod) delete(smethod); + } + + void method(StrategyMethod* method) + { + smethod = method; + } + + StrategyMethod* method() + { + return smethod; } }; template - struct TransformMethod : PaintMethod + struct PaintMethod : StrategyMethod { T* inst = nullptr; - TransformMethod(T* inst) : inst(_inst) {} - ~TransformMethod(){} + PaintMethod(T* _inst) : inst(_inst) {} + ~PaintMethod(){} bool rotate(float degree) override { diff --git a/src/lib/tvgScene.cpp b/src/lib/tvgScene.cpp index 4d04364..d34d57a 100644 --- a/src/lib/tvgScene.cpp +++ b/src/lib/tvgScene.cpp @@ -25,7 +25,7 @@ Scene::Scene() : pImpl(make_unique()) { - Paint::IMPL->method = IMPL->transformMethod(); + Paint::IMPL->method(new PaintMethod(IMPL)); } diff --git a/src/lib/tvgSceneImpl.h b/src/lib/tvgSceneImpl.h index bd49714..0ba1f1f 100644 --- a/src/lib/tvgSceneImpl.h +++ b/src/lib/tvgSceneImpl.h @@ -40,7 +40,7 @@ struct Scene::Impl bool dispose(RenderMethod& renderer) { for (auto paint : paints) { - paint->IMPL->method->dispose(renderer); + paint->IMPL->method()->dispose(renderer); delete(paint); } paints.clear(); @@ -51,7 +51,7 @@ struct Scene::Impl bool updateInternal(RenderMethod &renderer, const RenderTransform* transform, uint32_t flag) { for(auto paint: paints) { - if (!paint->IMPL->method->update(renderer, transform, flag)) return false; + if (!paint->IMPL->method()->update(renderer, transform, flag)) return false; } return true; } @@ -94,7 +94,7 @@ struct Scene::Impl bool render(RenderMethod &renderer) { for(auto paint: paints) { - if(!paint->IMPL->method->render(renderer)) return false; + if(!paint->IMPL->method()->render(renderer)) return false; } return true; } @@ -118,7 +118,7 @@ struct Scene::Impl auto w2 = 0.0f; auto h2 = 0.0f; - if (paint->IMPL->method->bounds(&x2, &y2, &w2, &h2)) return false; + if (paint->IMPL->method()->bounds(&x2, &y2, &w2, &h2)) return false; //Merge regions if (x2 < x) x = x2; @@ -203,12 +203,6 @@ struct Scene::Impl if (!loader->read()) return Result::Unknown; return Result::Success; } - - PaintMethod* transformMethod() - { - return new TransformMethod(this); - } - }; #endif //_TVG_SCENE_IMPL_H_ \ No newline at end of file diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index f42c160..7d26614 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -31,7 +31,7 @@ constexpr auto PATH_KAPPA = 0.552284f; Shape :: Shape() : pImpl(make_unique(this)) { - Paint::IMPL->method = IMPL->transformMethod(); + Paint::IMPL->method(new PaintMethod(IMPL)); } diff --git a/src/lib/tvgShapeImpl.h b/src/lib/tvgShapeImpl.h index 955deb6..a7755da 100644 --- a/src/lib/tvgShapeImpl.h +++ b/src/lib/tvgShapeImpl.h @@ -236,12 +236,6 @@ struct Shape::Impl return true; } - - - PaintMethod* transformMethod() - { - return new TransformMethod(this); - } }; #endif //_TVG_SHAPE_IMPL_H_ \ No newline at end of file -- 2.7.4