15 #include "asyncTaskCollection.h"
24 AsyncTaskCollection() {
43 void AsyncTaskCollection::
61 if (_tasks.get_ref_count() > 1) {
62 AsyncTasks old_tasks = _tasks;
63 _tasks = AsyncTasks::empty_array(0);
64 _tasks.v() = old_tasks.v();
67 _tasks.push_back(task);
80 for (
int i = 0; task_index == -1 && i < (int)_tasks.size(); i++) {
81 if (_tasks[i] == task) {
86 if (task_index == -1) {
96 if (_tasks.get_ref_count() > 1) {
97 AsyncTasks old_tasks = _tasks;
98 _tasks = AsyncTasks::empty_array(0);
99 _tasks.v() = old_tasks.v();
102 _tasks.erase(_tasks.begin() + task_index);
117 for (
int i = 0; i < other_num_tasks; i++) {
131 AsyncTasks new_tasks;
133 for (
int i = 0; i < num_tasks; i++) {
136 new_tasks.push_back(task);
152 AsyncTasks new_tasks;
155 for (
int i = 0; i < num_tasks; i++) {
157 bool duplicated =
false;
159 for (
int j = 0; j < i && !duplicated; j++) {
164 new_tasks.push_back(task);
207 for (
int i = 0; i < num_tasks; i++) {
209 if (task->get_name() == name) {
223 return _tasks.size();
233 nassertr(index >= 0 && index < (
int)_tasks.size(), NULL);
235 return _tasks[index];
250 if (_tasks.get_ref_count() > 1) {
251 AsyncTasks old_tasks = _tasks;
252 _tasks = AsyncTasks::empty_array(0);
253 _tasks.v() = old_tasks.v();
256 nassertv(index >= 0 && index < (
int)_tasks.size());
257 _tasks.erase(_tasks.begin() + index);
269 nassertr(index >= 0 && index < (
int)_tasks.size(), NULL);
271 return _tasks[index];
282 return _tasks.size();
294 out <<
"1 AsyncTask";
307 write(ostream &out,
int indent_level)
const {
309 indent(out, indent_level) << *
get_task(i) <<
"\n";
bool has_task(AsyncTask *task) const
Returns true if the indicated AsyncTask appears in this collection, false otherwise.
int size() const
Returns the number of tasks in the collection.
void clear()
Removes all AsyncTasks from the collection.
int get_num_tasks() const
Returns the number of AsyncTasks in the collection.
void add_task(AsyncTask *task)
Adds a new AsyncTask to the collection.
A list of tasks, for instance as returned by some of the AsyncTaskManager query functions.
AsyncTask * find_task(const string &name) const
Returns the task in the collection with the indicated name, if any, or NULL if no task has that name...
void add_tasks_from(const AsyncTaskCollection &other)
Adds all the AsyncTasks indicated in the other collection to this task.
void remove_tasks_from(const AsyncTaskCollection &other)
Removes from this collection all of the AsyncTasks listed in the other collection.
void remove_duplicate_tasks()
Removes any duplicate entries of the same AsyncTasks on this collection.
AsyncTask * get_task(int index) const
Returns the nth AsyncTask in the collection.
This class represents a concrete task performed by an AsyncManager.
bool remove_task(AsyncTask *task)
Removes the indicated AsyncTask from the collection.
void output(ostream &out) const
Writes a brief one-line description of the AsyncTaskCollection to the indicated output stream...
AsyncTask * operator[](int index) const
Returns the nth AsyncTask in the collection.
void write(ostream &out, int indent_level=0) const
Writes a complete multi-line description of the AsyncTaskCollection to the indicated output stream...