objectList.clear();
DALI_TEST_EQUALS(ClassWithId::gRefCount, 0, TEST_LOCATION);
+ END_TEST;
+}
+
+int UtcDaliOrderedSetReorderCacheMap(void)
+{
+ // Ensure that order of iterator is equal with Order of Insertion.
+ // And also check the order is valid even if change the order by user, after we call ReorderCacheMap.
+
+ // Reset refcount of class
+ ClassWithId::gRefCount = 0;
+
+ // To avoid lucky pass, run this test multiple time.
+ int tryCnt = 3;
+ while(tryCnt--)
+ {
+ int baseId = tryCnt; // random id
+ int id = baseId;
+ int n = 10 + 5 * (tryCnt + 1); // random count
+
+ OrderedSet<ClassWithId> set;
+
+ for(int i = 0; i < n; ++i)
+ {
+ ClassWithId* object = new ClassWithId(id++);
+ set.PushBack(object);
+ }
+
+ int expectId;
+ // Check by for iteration
+ expectId = baseId;
+ for(auto iter = set.Begin(), iterEnd = set.End(); iter != iterEnd; ++iter)
+ {
+ DALI_TEST_EQUALS(expectId++, (*iter)->mId, TEST_LOCATION);
+ }
+ DALI_TEST_EQUALS(expectId, id, TEST_LOCATION);
+
+ // Shuffle it randomly.
+ std::vector<std::pair<int, ClassWithId*>> shuffleList;
+ shuffleList.reserve(n);
+ for(auto iter = set.Begin(), iterEnd = set.End(); iter != iterEnd; ++iter)
+ {
+ shuffleList.emplace_back((*iter)->mId, (*iter));
+ }
+ std::random_shuffle(shuffleList.begin(), shuffleList.end());
+
+ // Change the value of container as shuffled order. After then, call ReorderCacheMap().
+ int shuffleIndex = 0;
+ for(auto iter = set.Begin(), iterEnd = set.End(); iter != iterEnd; ++iter)
+ {
+ (*iter) = shuffleList[shuffleIndex++].second;
+ }
+ set.ReorderCacheMap();
+
+ // Check by iterator. And randomly erase item
+ shuffleIndex = 0;
+ for(auto iter = set.Begin(), iterEnd = set.End(); iter != iterEnd; ++iter)
+ {
+ DALI_TEST_EQUALS(shuffleList[shuffleIndex++].first, (*iter)->mId, TEST_LOCATION);
+ }
+
+ // Randomly erase item, and check again until all items removed.
+ while(!set.IsEmpty())
+ {
+ int removeIndex = rand()%set.Count();
+ auto iter = set.Find(shuffleList[removeIndex].second);
+ DALI_TEST_CHECK(iter != set.End());
+ set.Erase(iter);
+ for(int i = removeIndex + 1; i < n; ++i)
+ {
+ shuffleList[i - 1] = shuffleList[i];
+ }
+ --n;
+
+ shuffleIndex = 0;
+ for(auto iter = set.Begin(), iterEnd = set.End(); iter != iterEnd; ++iter)
+ {
+ DALI_TEST_EQUALS(shuffleList[shuffleIndex++].first, (*iter)->mId, TEST_LOCATION);
+ }
+ }
+ }
+
+ // Check whether leak exist.
+ DALI_TEST_EQUALS(ClassWithId::gRefCount, 0, TEST_LOCATION);
+
END_TEST;
}
\ No newline at end of file
return mMap.size();
}
+ /**
+ * @brief Predicate to determine if the container is empty
+ *
+ * @return true if the container is empty
+ */
+ bool IsEmpty() const
+ {
+ return mMap.empty();
+ }
+
/**
* @brief Reserves space in the ordered set.
*
mList.clear();
}
+ /**
+ * @brief Reorder cache map. It should be called after the value of mList changed.
+ */
+ void ReorderCacheMap()
+ {
+ mMap.clear();
+ for(auto iter = mList.begin(), iterEnd = mList.end(); iter != iterEnd; ++iter)
+ {
+ mMap.insert({*iter, iter});
+ }
+ }
+
private:
// Delete copy operation.
OrderedSet(const OrderedSet&) = delete;
void RenderTaskList::RemoveTask(RenderTask* task)
{
- RenderTaskContainer::ConstIterator end = mRenderTasks.End();
- for(RenderTaskContainer::Iterator iter = mRenderTasks.Begin(); iter != end; ++iter)
+ auto iter = mRenderTasks.Find(task);
+ if(iter != mRenderTasks.End())
{
- if(*iter == task)
- {
- // Destroy the task
- mRenderTasks.Erase(iter);
-
- break; // we're finished
- }
+ // Destroy the task
+ mRenderTasks.Erase(iter);
}
}
void RenderTaskList::SortTasks(OwnerPointer<std::vector<const SceneGraph::RenderTask*>>& sortedTasks)
{
- for(uint32_t i = 0; i < sortedTasks->size(); ++i)
+ DALI_ASSERT_ALWAYS(sortedTasks->size() == mRenderTasks.Count() && "SceneGraph RenderTask list is not matched with Event side RenderTask list!");
+
+ auto iter = mRenderTasks.Begin();
+ for(auto sortedIter = sortedTasks->begin(), sortedIterEnd = sortedTasks->end(); sortedIter != sortedIterEnd; ++sortedIter, ++iter)
{
- const SceneGraph::RenderTask* task = (*sortedTasks)[i];
+ const SceneGraph::RenderTask* task = *sortedIter;
SceneGraph::RenderTask* castedTask = const_cast<SceneGraph::RenderTask*>(task);
- mRenderTasks[i] = castedTask;
+ (*iter) = castedTask;
}
+
+ // We should call Reorder after the order of container changed.
+ mRenderTasks.ReorderCacheMap();
}
uint32_t RenderTaskList::GetTaskCount()