From d411b51acf8844edd22a8e95aa9ade3467239435 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 22 Oct 2021 21:04:15 +0900 Subject: [PATCH] common: introduce iterator +++ auto picture = tvg::Picture::gen(); auto func = [](const tvg::Paint* paint, const tvg::Paint* parent, bool hasChildren) -> int { if (paint->identifier() == Shape::identifier()) //TODO: override properties. //return true to continue, return false to stop. return true; }; picture = tvg::Iteratorv::iterate(move(picture), func); Change-Id: I2ea956cb46b20547239686969c2e403e23fc8943 --- inc/thorvg.h | 10 +++++++++- src/lib/meson.build | 1 + src/lib/tvgInitializer.cpp | 2 +- src/lib/tvgIterator.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/lib/tvgIterator.cpp diff --git a/inc/thorvg.h b/inc/thorvg.h index 49e112d..127663c 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -1533,6 +1533,14 @@ public: _TVG_DECLARE_PRIVATE(Saver); }; + +class TVG_EXPORT Iteratorv final +{ +public: + static std::unique_ptr iterate(std::unique_ptr picture, int(*func)(const Paint* paint, const Paint* parent, bool hasChildren)) noexcept; +}; + + /** @}*/ } //namespace @@ -1541,4 +1549,4 @@ public: } #endif -#endif //_THORVG_H_ +#endif //_THORVG_H_ \ No newline at end of file diff --git a/src/lib/meson.build b/src/lib/meson.build index 9c31700..2d747f7 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -30,6 +30,7 @@ source_file = [ 'tvgFill.cpp', 'tvgGlCanvas.cpp', 'tvgInitializer.cpp', + 'tvgIterator.cpp', 'tvgLinearGradient.cpp', 'tvgLzw.cpp', 'tvgLoader.cpp', diff --git a/src/lib/tvgInitializer.cpp b/src/lib/tvgInitializer.cpp index 83ec50b..f1b1885 100644 --- a/src/lib/tvgInitializer.cpp +++ b/src/lib/tvgInitializer.cpp @@ -149,4 +149,4 @@ Result Initializer::term(CanvasEngine engine) noexcept uint16_t THORVG_VERSION_NUMBER() { return _version; -} +} \ No newline at end of file diff --git a/src/lib/tvgIterator.cpp b/src/lib/tvgIterator.cpp new file mode 100644 index 0000000..d0d4d1d --- /dev/null +++ b/src/lib/tvgIterator.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgCommon.h" + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + + + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +unique_ptr Iteratorv::iterate(unique_ptr root, int(*func)(const Paint* paint, const Paint* parent, bool hasChild)) noexcept +{ + //TODO: Preorder traversal + + return nullptr; +} \ No newline at end of file -- 2.7.4