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
23 #include <dpl/task_list.h>
24 #include <dpl/assert.h>
32 m_currentTask = m_tasks.end();
37 for (Tasks::iterator i = m_tasks.begin(); i != m_tasks.end(); ++i)
41 void TaskList::AddTask(Task *task)
43 Assert(!m_running && "AddTask is not allowed after calling NextStep");
44 m_tasks.push_back(task);
45 m_currentTask = m_tasks.begin();
48 bool TaskList::NextStep()
52 Assert(m_currentTask != m_tasks.end() && "Task list is empty or all tasks done");
56 bool result = (*m_currentTask)->NextStep();
58 if (result || m_switched)
61 return ++m_currentTask != m_tasks.end();
64 bool TaskList::Abort()
66 m_tasks.erase(m_currentTask,m_tasks.end());
68 for (Tasks::iterator i = m_tasks.begin(); i != m_tasks.end();)
70 //If given task does not have any "abortSteps", remove it from the list
83 m_currentTask=m_tasks.begin();
88 void TaskList::SwitchToTask(Task *task)
90 Tasks::iterator i = std::find(m_tasks.begin(), m_tasks.end(), task);
91 Assert(i != m_tasks.end());
96 size_t TaskList::GetTaskCount() const
98 return static_cast<size_t>(m_tasks.size());
101 size_t TaskList::GetStepCount() const
105 for (Tasks::const_iterator i = m_tasks.begin(); i != m_tasks.end(); ++i)
106 count += (*i)->GetStepCount();