API: enable users to use an accessor to traverse Scene

remove the restriction of targeting only Picture.
now, any kind of paints can be adaptable here.
This commit is contained in:
Hermet Park 2024-12-26 13:48:26 +09:00 committed by Hermet Park
parent 041ab1117b
commit 5e102dfd25
2 changed files with 9 additions and 9 deletions

View file

@ -2131,7 +2131,7 @@ public:
/** /**
* @brief Set the access function for traversing the Picture scene tree nodes. * @brief Set the access function for traversing the Picture scene tree nodes.
* *
* @param[in] picture The picture node to traverse the internal scene-tree. * @param[in] paint The paint node to traverse the internal scene-tree.
* @param[in] func The callback function calling for every paint nodes of the Picture. * @param[in] func The callback function calling for every paint nodes of the Picture.
* @param[in] data Data passed to the @p func as its argument. * @param[in] data Data passed to the @p func as its argument.
* *
@ -2139,7 +2139,7 @@ public:
* *
* @note Experimental API * @note Experimental API
*/ */
Result set(Picture* picture, std::function<bool(const Paint* paint, void* data)> func, void* data) noexcept; Result set(Paint* paint, std::function<bool(const Paint* paint, void* data)> func, void* data) noexcept;
/** /**
* @brief Generate a unique ID (hash key) from a given name. * @brief Generate a unique ID (hash key) from a given name.

View file

@ -50,27 +50,27 @@ static bool accessChildren(Iterator* it, function<bool(const Paint* paint, void*
/* External Class Implementation */ /* External Class Implementation */
/************************************************************************/ /************************************************************************/
Result Accessor::set(Picture* picture, function<bool(const Paint* paint, void* data)> func, void* data) noexcept Result Accessor::set(Paint* paint, function<bool(const Paint* paint, void* data)> func, void* data) noexcept
{ {
if (!picture || !func) return Result::InvalidArguments; if (!paint || !func) return Result::InvalidArguments;
//Use the Preorder Tree-Search //Use the Preorder Tree-Search
picture->ref(); paint->ref();
//Root //Root
if (!func(picture, data)) { if (!func(paint, data)) {
picture->unref(); paint->unref();
return Result::Success; return Result::Success;
} }
//Children //Children
if (auto it = IteratorAccessor::iterator(picture)) { if (auto it = IteratorAccessor::iterator(paint)) {
accessChildren(it, func, data); accessChildren(it, func, data);
delete(it); delete(it);
} }
picture->unref(false); paint->unref(false);
return Result::Success; return Result::Success;
} }