1 #ifndef DALI_INTERNAL_UPDATE_RESETTER_CONTAINER_H
2 #define DALI_INTERNAL_UPDATE_RESETTER_CONTAINER_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 namespace Dali::Internal::SceneGraph
24 * Template class to manage node/property resetters
26 template<class ResetterType>
27 class ResetterContainer
30 // std::list offers fast delete and fast iteration.
31 using ContainerType = std::list<ResetterType*>;
32 using Iterator = typename ContainerType::iterator;
33 using ConstIterator = typename ContainerType::const_iterator;
35 ResetterContainer() = default;
37 ResetterContainer(const ResetterContainer&) = delete;
38 ResetterContainer(ResetterContainer&&) = delete;
41 * Ensure all resetters are destroyed when the container is destroyed
49 * Add a resetter to the container
50 * @param[in] resetterPtr A pointer to the resetter.
51 * The container takes ownership.
53 void PushBack(ResetterType* resetterPtr)
55 mContainer.push_back(resetterPtr);
59 * @return true if the container is empty
63 return mContainer.empty();
67 * Clear the container, destroying all extant resetters.
74 iter = EraseObject(iter);
79 * @return an iterator to the start of the container
83 return mContainer.begin();
86 * Support for C++11 Range-based for loop
87 * @return an iterator to the start of the container.
91 return mContainer.begin();
94 * @return an iterator to the start of the container
96 ConstIterator Begin() const
98 return mContainer.begin();
101 * Support for C++11 Range-based for loop
102 * @return an iterator to the start of the container.
104 ConstIterator begin() const
106 return mContainer.begin();
110 * @return an iterator to the end of the container.
114 return mContainer.end();
117 * Support for C++11 Range-based for loop
118 * @return an iterator to the end of the container.
122 return mContainer.end();
125 * @return an iterator to the end of the container.
127 ConstIterator End() const
129 return mContainer.end();
132 * Support for C++11 Range-based for loop
133 * @return an iterator to the end of the container.
135 ConstIterator end() const
137 return mContainer.end();
141 * Erase a resetter from the container
143 Iterator EraseObject(Iterator iter)
146 return mContainer.erase(iter);
150 * Iterate over the container, resetting all the referenced
151 * properties. If a resetter has finished (e.g. it's animation /
152 * constraint has ended, or it's baked 2 values), then it is removed
154 * @param[in] bufferIndex The buffer index of the property to be reset
156 void ResetToBaseValues(BufferIndex bufferIndex)
158 if(!mContainer.empty())
160 auto end = mContainer.end();
161 auto iter = mContainer.begin();
164 (*iter)->ResetToBaseValue(bufferIndex);
165 if((*iter)->IsFinished())
167 iter = EraseObject(iter);
169 else // Skip to next element
178 ContainerType mContainer; ///< The list of resetters
181 } // namespace Dali::Internal::SceneGraph
183 #endif // DALI_INTERNAL_UPDATE_RESETTER_CONTAINER_H