{
DALI_ASSERT_DEBUG(mNode && "Operation on NULL JSON node");
- CollectNodes collector;
+ DeleteNodesWithoutSelf otherDeletor(mNode);
- DepthFirst(mNode, collector);
-
- for(CollectNodes::iterator iter = collector.nodes.begin(); iter != collector.nodes.end(); ++iter)
- {
- if(*iter != mNode)
- {
- delete *iter;
- }
- }
+ DepthFirst(mNode, otherDeletor);
mNode->mFirstChild = NULL;
mNode->mLastChild = NULL;
#define DALI_SCRIPT_TREE_NODE_MANIPULATOR_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
};
/*
+ * Delete nodes immediately, instead of self
+ */
+struct DeleteNodesWithoutSelf
+{
+ DeleteNodesWithoutSelf(TreeNode* self)
+ : mSelf(self){};
+
+ /*
+ * Call operator to add nodes to the list
+ */
+ void operator()(TreeNode*& n)
+ {
+ DALI_ASSERT_DEBUG(n && "Operation on NULL JSON node");
+ if(mSelf != n)
+ {
+ delete n;
+ }
+ }
+
+ const TreeNode* mSelf; ///< self node what we should not remove.
+};
+
+/*
* Depth first walk of nodes applying given operation (unary_function)
*/
template<typename Operation>