From: Subhransu Mohanty Date: Wed, 27 Jan 2021 09:20:24 +0000 (+0900) Subject: Add EraseIf() api to OwnerContainer for proper implementaion of Erase-Remove idiom. X-Git-Tag: dali_2.0.11~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F87%2F252387%2F2;p=platform%2Fcore%2Fuifw%2Fdali-core.git Add EraseIf() api to OwnerContainer for proper implementaion of Erase-Remove idiom. std::remove_if() moves the end object to the removed object position. as OwnerContainer keeps the raw pointer, have introduced a higher order function which will free the object if predicate returns true. Change-Id: I0e69fee7ef115d9e15cc36e8cbe6889b3ad77c4d --- diff --git a/dali/devel-api/common/owner-container.h b/dali/devel-api/common/owner-container.h index c8c37d5..b010f41 100644 --- a/dali/devel-api/common/owner-container.h +++ b/dali/devel-api/common/owner-container.h @@ -86,6 +86,32 @@ public: } /** + * @brief Erases all elements that satisfy the predicate from the OwnerContainer. + * + * @param[in] predicate The predicate + */ + template + void EraseIf(Predicate predicate) + { + auto begin = Vector::Begin(); + auto end = Vector::End(); + + auto function = [predicate](auto& obj) { + if(predicate(obj)) + { + delete obj; + return true; + } + else + { + return false; + } + }; + + Vector::Erase(std::remove_if(begin, end, function), end); + } + + /** * Erases a range of elements.(delete from heap). */ Iterator Erase(Iterator first, Iterator last) diff --git a/dali/internal/update/animation/scene-graph-animation.cpp b/dali/internal/update/animation/scene-graph-animation.cpp index 1ac2e43..4c60adc 100644 --- a/dali/internal/update/animation/scene-graph-animation.cpp +++ b/dali/internal/update/animation/scene-graph-animation.cpp @@ -483,10 +483,7 @@ void Animation::UpdateAnimators( BufferIndex bufferIndex, bool bake, bool animat if(cleanup) { //Remove animators whose PropertyOwner has been destroyed - mAnimators.Erase(std::remove_if(mAnimators.begin(), - mAnimators.end(), - [](auto& animator) { return animator->Orphan(); }), - mAnimators.end()); + mAnimators.EraseIf([](auto& animator) { return animator->Orphan(); }); } }