2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19 * @author Radoslaw Wicik (r.wicik@samsung.com)
21 * @brief Implementation file for task list
24 #include <dpl/task_list.h>
25 #include <dpl/assert.h>
28 TaskList::TaskList() :
32 m_currentTask = m_tasks.end();
37 for (Tasks::iterator i = m_tasks.begin(); i != m_tasks.end(); ++i) {
42 void TaskList::AddTask(Task *task)
44 Assert(!m_running && "AddTask is not allowed after calling NextStep");
45 m_tasks.push_back(task);
46 m_currentTask = m_tasks.begin();
49 bool TaskList::NextStep()
54 m_currentTask != m_tasks.end() &&
55 "Task list is empty or all tasks done");
59 bool result = (*m_currentTask)->NextStep();
61 if (result || m_switched) {
65 return ++m_currentTask != m_tasks.end();
68 bool TaskList::Abort()
70 m_tasks.erase(m_currentTask, m_tasks.end());
72 for (Tasks::iterator i = m_tasks.begin(); i != m_tasks.end();) {
73 //If given task does not have any "abortSteps", remove it from the list
82 if (m_tasks.empty()) {
86 m_currentTask = m_tasks.begin();
91 void TaskList::SwitchToTask(Task *task)
93 Tasks::iterator i = std::find(m_tasks.begin(), m_tasks.end(), task);
94 Assert(i != m_tasks.end());
99 size_t TaskList::GetTaskCount() const
101 return static_cast<size_t>(m_tasks.size());
104 size_t TaskList::GetStepCount() const
108 for (Tasks::const_iterator i = m_tasks.begin(); i != m_tasks.end(); ++i) {
109 count += (*i)->GetStepCount();