mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-23 22:58:44 +00:00
common: code refactoring for the IteractorAccessor.
The instantiation of the accessor is unnecessary as it does not require any internal context. Simplifying its usage would be beneficial.
This commit is contained in:
parent
b2692484b7
commit
084e78d98d
5 changed files with 12 additions and 13 deletions
|
@ -26,15 +26,15 @@
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
static bool accessChildren(Iterator* it, IteratorAccessor& itrAccessor, function<bool(const Paint* paint)> func)
|
static bool accessChildren(Iterator* it, function<bool(const Paint* paint)> func)
|
||||||
{
|
{
|
||||||
while (auto child = it->next()) {
|
while (auto child = it->next()) {
|
||||||
//Access the child
|
//Access the child
|
||||||
if (!func(child)) return false;
|
if (!func(child)) return false;
|
||||||
|
|
||||||
//Access the children of the child
|
//Access the children of the child
|
||||||
if (auto it2 = itrAccessor.iterator(child)) {
|
if (auto it2 = IteratorAccessor::iterator(child)) {
|
||||||
if (!accessChildren(it2, itrAccessor, func)) {
|
if (!accessChildren(it2, func)) {
|
||||||
delete(it2);
|
delete(it2);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,8 @@ unique_ptr<Picture> Accessor::set(unique_ptr<Picture> picture, function<bool(con
|
||||||
if (!func(p)) return picture;
|
if (!func(p)) return picture;
|
||||||
|
|
||||||
//Children
|
//Children
|
||||||
IteratorAccessor itrAccessor;
|
if (auto it = IteratorAccessor::iterator(p)) {
|
||||||
if (auto it = itrAccessor.iterator(p)) {
|
accessChildren(it, func);
|
||||||
accessChildren(it, itrAccessor, func);
|
|
||||||
delete(it);
|
delete(it);
|
||||||
}
|
}
|
||||||
return picture;
|
return picture;
|
||||||
|
|
|
@ -32,7 +32,7 @@ class IteratorAccessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//Utility Method: Iterator Accessor
|
//Utility Method: Iterator Accessor
|
||||||
Iterator* iterator(const Paint* paint)
|
static Iterator* iterator(const Paint* paint)
|
||||||
{
|
{
|
||||||
return paint->pImpl->iterator();
|
return paint->pImpl->iterator();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
namespace tvg
|
namespace tvg
|
||||||
{
|
{
|
||||||
|
|
||||||
class SaveModule : public IteratorAccessor
|
class SaveModule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~SaveModule() {}
|
virtual ~SaveModule() {}
|
||||||
|
|
|
@ -356,7 +356,7 @@ TvgBinCounter TvgSaver::serializeChild(const Paint* parent, const Paint* child,
|
||||||
|
|
||||||
TvgBinCounter TvgSaver::serializeScene(const Scene* scene, const Matrix* pTransform, const Matrix* cTransform)
|
TvgBinCounter TvgSaver::serializeScene(const Scene* scene, const Matrix* pTransform, const Matrix* cTransform)
|
||||||
{
|
{
|
||||||
auto it = this->iterator(scene);
|
auto it = IteratorAccessor::iterator(scene);
|
||||||
if (it->count() == 0) {
|
if (it->count() == 0) {
|
||||||
delete(it);
|
delete(it);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -568,7 +568,7 @@ TvgBinCounter TvgSaver::serializeShape(const Shape* shape, const Matrix* pTransf
|
||||||
/* Picture has either a vector scene or a bitmap. */
|
/* Picture has either a vector scene or a bitmap. */
|
||||||
TvgBinCounter TvgSaver::serializePicture(const Picture* picture, const Matrix* pTransform, const Matrix* cTransform)
|
TvgBinCounter TvgSaver::serializePicture(const Picture* picture, const Matrix* pTransform, const Matrix* cTransform)
|
||||||
{
|
{
|
||||||
auto it = this->iterator(picture);
|
auto it = IteratorAccessor::iterator(picture);
|
||||||
|
|
||||||
//Case - Vector Scene:
|
//Case - Vector Scene:
|
||||||
if (it->count() == 1) {
|
if (it->count() == 1) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ using namespace emscripten;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace tvg;
|
using namespace tvg;
|
||||||
|
|
||||||
class __attribute__((visibility("default"))) ThorvgWasm : public IteratorAccessor
|
class __attribute__((visibility("default"))) ThorvgWasm
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static unique_ptr<ThorvgWasm> create()
|
static unique_ptr<ThorvgWasm> create()
|
||||||
|
@ -282,7 +282,7 @@ private:
|
||||||
{
|
{
|
||||||
//paint
|
//paint
|
||||||
if (paint->identifier() != Shape::identifier()) {
|
if (paint->identifier() != Shape::identifier()) {
|
||||||
auto it = this->iterator(paint);
|
auto it = IteratorAccessor::iterator(paint);
|
||||||
if (it->count() > 0) {
|
if (it->count() > 0) {
|
||||||
layers->reserve(layers->count + it->count());
|
layers->reserve(layers->count + it->count());
|
||||||
it->begin();
|
it->begin();
|
||||||
|
@ -313,7 +313,7 @@ private:
|
||||||
}
|
}
|
||||||
//paint
|
//paint
|
||||||
if (parent->identifier() != Shape::identifier()) {
|
if (parent->identifier() != Shape::identifier()) {
|
||||||
auto it = this->iterator(parent);
|
auto it = IteratorAccessor::iterator(parent);
|
||||||
if (it->count() > 0) {
|
if (it->count() > 0) {
|
||||||
it->begin();
|
it->begin();
|
||||||
while (auto child = it->next()) {
|
while (auto child = it->next()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue