#ifndef _THORVG_H_
#define _THORVG_H_
+#include <functional>
#include <memory>
#include <string>
~Accessor();
/**
- * @brief Access the Picture scene stree nodes.
+ * @brief Access the Picture scene tree nodes.
*
* @param[in] picture The picture node to traverse the internal scene-tree.
* @param[in] func The callback function calling for every paint nodes of the Picture.
std::unique_ptr<Picture> access(std::unique_ptr<Picture> picture, bool(*func)(const Paint* paint)) noexcept;
/**
- * @brief Access the Picture scene stree 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] func The callback function calling for every paint nodes of the Picture.
- * @param[in] data Data will be passed to callback function.
*
* @return Return the given @p picture instance.
*
* @note The bitmap based picture might not have the scene-tree.
+ *
+ * @BETA_API
*/
- std::unique_ptr<Picture> access(std::unique_ptr<Picture> picture, bool(*func)(const Paint* paint, void* data), void* data) noexcept;
+ std::unique_ptr<Picture> set(std::unique_ptr<Picture> picture, std::function<bool(const Paint* paint)> func) noexcept;
/**
* @brief Creates a new Accessor object.
/* Internal Class Implementation */
/************************************************************************/
-static bool accessChildren(Iterator* it, bool(*func)(const Paint* paint), IteratorAccessor& itrAccessor)
+static bool accessChildren(Iterator* it, IteratorAccessor& itrAccessor, function<bool(const Paint* paint)> func)
{
while (auto child = it->next()) {
//Access the child
//Access the children of the child
if (auto it2 = itrAccessor.iterator(child)) {
- if (!accessChildren(it2, func, itrAccessor)) {
- delete(it2);
- return false;
- }
- delete(it2);
- }
- }
- return true;
-}
-
-
-static bool accessChildren(Iterator* it, bool(*func)(const Paint* paint, void* data), IteratorAccessor& itrAccessor, void* data)
-{
- while (auto child = it->next()) {
- //Access the child
- if (!func(child, data)) return false;
-
- //Access the children of the child
- if (auto it2 = itrAccessor.iterator(child)) {
- if (!accessChildren(it2, func, itrAccessor, data)) {
+ if (!accessChildren(it2, itrAccessor, func)) {
delete(it2);
return false;
}
//Children
IteratorAccessor itrAccessor;
if (auto it = itrAccessor.iterator(p)) {
- accessChildren(it, func, itrAccessor);
+ accessChildren(it, itrAccessor, func);
delete(it);
}
return picture;
}
-unique_ptr<Picture> Accessor::access(unique_ptr<Picture> picture, bool(*func)(const Paint* paint, void* data), void* data) noexcept
+unique_ptr<Picture> Accessor::set(unique_ptr<Picture> picture, function<bool(const Paint* paint)> func) noexcept
{
auto p = picture.get();
if (!p || !func) return picture;
//Use the Preorder Tree-Search
//Root
- if (!func(p, data)) return picture;
+ if (!func(p)) return picture;
//Children
IteratorAccessor itrAccessor;
if (auto it = itrAccessor.iterator(p)) {
- accessChildren(it, func, itrAccessor, data);
+ accessChildren(it, itrAccessor, func);
delete(it);
}
return picture;