home *** CD-ROM | disk | FTP | other *** search
- /* ==========
- * PedTask.cc
- * ==========
- */
-
- #include <string.h>
-
- #include "NGLIterator.hh"
-
- #include "PedTask.hh"
- #include "PedChore.hh"
-
- PedTask::PedTask(PedTask *inParent)
- : mParent(inParent), mName(NULL)
- {
- if (mParent) {
- mParent->AddSubtask(this);
- }
- }
-
- PedTask::~PedTask()
- {
- if (mParent) {
- mParent->RemoveSubtask(this);
- }
- delete [] mName;
- }
-
- const char *
- PedTask::Name() const
- {
- return mName ? mName : "";
- }
-
- void
- PedTask::SetName(const char *inName)
- {
- delete [] mName;
- long size = strlen(inName);
- mName = new char [size + 1];
- strcpy(mName, inName);
- }
-
- void
- PedTask::AddSubtask(PedTask *inTask)
- {
- if (inTask != NULL) {
- mSubTasks.Append(inTask);
- }
- }
-
- void
- PedTask::RemoveSubtask(PedTask *inTask)
- {
- if (inTask != NULL) {
- mSubTasks.Remove(inTask);
- }
- }
-
- void
- PedTask::ScheduleRepeatChore(PedChore *inChore)
- {
- if (inChore != NULL) {
- mRepeatQueue.Append(inChore);
- }
- }
-
- void
- PedTask::UnscheduleRepeatChore(PedChore *inChore)
- {
- if (inChore != NULL) {
- mRepeatQueue.Remove(inChore);
- }
- }
-
- void
- PedTask::ScheduleIdleChore(PedChore *inChore)
- {
- if (inChore != NULL) {
- mIdleQueue.Append(inChore);
- }
- }
-
- void
- PedTask::UnscheduleIdleChore(PedChore *inChore)
- {
- if (inChore != NULL) {
- mIdleQueue.Remove(inChore);
- }
- }
-
- void
- PedTask::DoRepeatChores()
- {
- RunQueue(mRepeatQueue);
- NGLIterator<PedTask *> iter(mSubTasks);
- PedTask *subtask;
- while (iter.GetNext(subtask)) {
- subtask->DoRepeatChores();
- }
- }
-
- void
- PedTask::DoIdleChores()
- {
- RunQueue(mIdleQueue);
- NGLIterator<PedTask *> iter(mSubTasks);
- PedTask *subtask;
- while (iter.GetNext(subtask)) {
- subtask->DoIdleChores();
- }
- }
-
- void
- PedTask::RunQueue(PedQueueChore &inQueue)
- {
- /*
- // Check for empty queue
- if (inQueue.Count() == 0) return;
-
- // Mark off the existing chores from any new ones
- inQueue.Append(NULL);
-
- PedChore *chore;
- while (chore = inQueue.Behead()) {
- chore->Perform();
- }
- // We hit the NULL entry, which has already been removed.
- */
-
- NGLIterator<PedChore *> iter(inQueue);
- PedChore *chore;
- while (iter.GetNext(chore)) {
- chore->Perform();
- }
-
- }
-