2 #ifndef DALI_TOOLKIT_INTERNAL_ROUND_ROBIN_CONTAINER_VIEW_H
3 #define DALI_TOOLKIT_INTERNAL_ROUND_ROBIN_CONTAINER_VIEW_H
6 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
33 * @brief RoundRobinContainerView is a view to a container that allows iterating through the elements cyclically.
36 class RoundRobinContainerView
39 using ContainerType = std::vector<T>;
42 * @brief Constructs a new RoundRobinControlView with the given number elements using the provided factory.
43 * @param[in] numberOfElements The number of elements in the container
44 * @param[in] factory Factory function of functor that will be used to create instances of the elements
46 template<typename FactoryType>
47 RoundRobinContainerView(size_t numberOfElements, const FactoryType& factory)
51 mElements.reserve(numberOfElements);
52 for(unsigned i = {}; i < numberOfElements; ++i)
54 mElements.push_back(factory());
59 * @brief Clear all elements.
67 * @brief Reset the position of the iterator returned by GetNext() to the first element.
75 * @brief Returns the next element on the container.
76 * @return Iterator for the next element
78 typename ContainerType::iterator GetNext()
82 return mElements.begin() + mNextIndex++;
86 * @brief Returns the iterator to the end of the container.
88 * Can be used to compare against GetNext() to check if the container is empty.
90 * @return The container end() element
92 typename ContainerType::const_iterator End() const
94 return mElements.cend();
98 * @brief Returns the element count.
99 * @return The element count
101 size_t GetElementCount() const
103 return mElements.size();
107 ~RoundRobinContainerView() = default;
109 RoundRobinContainerView(const RoundRobinContainerView&) = delete;
110 RoundRobinContainerView& operator=(const RoundRobinContainerView&) = delete;
111 RoundRobinContainerView(RoundRobinContainerView&&) = default;
112 RoundRobinContainerView& operator=(RoundRobinContainerView&&) = default;
116 * @brief Check the current index and reset if necessary.
118 void SetValidNextIndex()
120 if(mNextIndex >= mElements.size())
127 ContainerType mElements; //< container of elements
128 size_t mNextIndex; //< index to the next element to be viewed
131 } // namespace Internal
133 } // namespace Toolkit
137 #endif // DALI_TOOLKIT_INTERNAL_ROUND_ROBIN_CONTAINER_VIEW_H