📄 task.cpp
字号:
// task.cpp
#include "task.h"
void Panic(TTaskManagerPanic aPanicCode)
{
_LIT(KTaskManagerPanic, "TTaskManager");
User::Panic(KTaskManagerPanic, aPanicCode);
}
TTask::TTask(THerculeanLabours aLabour)
: iLabour(aLabour)
{
__ASSERT_ALWAYS( ((aLabour>=ESlayNemeanLion)&&(aLabour<=ECaptureCerberus)), Panic(EInvalidTaskId));
Initialize();
}
TTask::TTask(const TTask& aTask)
: iLabour(aTask.iLabour)
{
iLabourName.Set(aTask.iLabourName);
}
TTask& TTask::operator=(const TTask& aTask)
{
iLabour=aTask.iLabour;
iLabourName.Set(aTask.iLabourName);
return (*this);
}
void TTask::Initialize()
{
switch (iLabour)
{
case (ESlayNemeanLion):
{
_LIT(KSlayNemeanLion, "SlayNemeanLion");
iLabourName.Set(KSlayNemeanLion);
}
break;
case (ESlayHydra):
{
_LIT(KSlayHydra, "SlayHydra");
iLabourName.Set(KSlayHydra);
}
break;
case (ECaptureCeryneianHind):
{
_LIT(KCaptureCeryneianHind, "CaptureCeryneianHind");
iLabourName.Set(KCaptureCeryneianHind);
}
break;
case (ESlayErymanthianBoar):
{
_LIT(KSlayErymanthianBoar, "SlayErymanthianBoar");
iLabourName.Set(KSlayErymanthianBoar);
}
break;
case (ECleanAugeanStables):
{
_LIT(KCleanAugeanStables, "CleanAugeanStables");
iLabourName.Set(KCleanAugeanStables);
}
break;
case (ECancelCleanAugeanStables):
{
_LIT(KCancelCleanAugeanStables, "CancelCleanAugeanStables");
iLabourName.Set(KCancelCleanAugeanStables);
}
break;
case (ESlayStymphalianBirds):
{
_LIT(KSlayStymphalianBirds, "SlayStymphalianBirds");
iLabourName.Set(KSlayStymphalianBirds);
}
break;
case (ECancelSlayStymphalianBirds):
{
_LIT(KCancelSlayStymphalianBirds, "CancelSlayStymphalianBirds");
iLabourName.Set(KCancelSlayStymphalianBirds);
}
break;
case (ECaptureCretanBull):
{
_LIT(KCaptureCretanBull, "CaptureCretanBull");
iLabourName.Set(KCaptureCretanBull);
}
break;
case (ECaptureMaresOfDiomedes):
{
_LIT(KCaptureMaresOfDiomedes, "CaptureMaresOfDiomedes");
iLabourName.Set(KCaptureMaresOfDiomedes);
}
break;
case (EObtainGirdleOfHippolyta):
{
_LIT(KObtainGirdleOfHippolyta, "ObtainGirdleOfHippolyta");
iLabourName.Set(KObtainGirdleOfHippolyta);
}
break;
case (ECaptureOxenOfGeryon):
{
_LIT(KCaptureOxenOfGeryon, "CaptureOxenOfGeryon");
iLabourName.Set(KCaptureOxenOfGeryon);
}
break;
case (ETakeGoldenApplesOfHesperides):
{
_LIT(KTakeGoldenApplesOfHesperides, "TakeGoldenApplesOfHesperides");
iLabourName.Set(KTakeGoldenApplesOfHesperides);
}
break;
case (ECaptureCerberus):
{
_LIT(KCaptureCerberus, "CaptureCerberus");
iLabourName.Set(KCaptureCerberus);
}
break;
default:
ASSERT(EFalse); // Should never get here
}
}
// If aTask1.iLabour < aTask2.iLabour return -ve value
// If aTask1.iLabour > aTask2.iLabour return +ve value
// If aTask1.iLabour == aTask2.iLabour return zero
/*static*/ TInt TTask::CompareTaskNumbers(const TTask& aTask1, const TTask& aTask2)
{
if (aTask1.iLabour > aTask2.iLabour)
return (1);
else if (aTask1.iLabour < aTask2.iLabour)
return (-1);
else
{
ASSERT(aTask1.iLabour==aTask2.iLabour);
return (0);
}
}
/*static*/ TBool TTask::MatchTasks(const TTask& aTask1, const TTask& aTask2)
{
if (aTask1.iLabour==aTask2.iLabour)
{
ASSERT(aTask1.iLabourName.Compare(aTask2.iLabourName)==0);
return ETrue;
}
return (EFalse);
}
/*static*/ CHerculeanTaskManager* CHerculeanTaskManager::NewLC()
{
CHerculeanTaskManager* me = new (ELeave) CHerculeanTaskManager();
CleanupStack::PushL(me);
me->ConstructL();
return (me);
}
CHerculeanTaskManager::CHerculeanTaskManager()
: iTaskArray(KTaskArrayGranularity)
{}
void CHerculeanTaskManager::ConstructL()
{// Nothing to do
}
CHerculeanTaskManager::~CHerculeanTaskManager()
{
iTaskArray.Close();
}
void CHerculeanTaskManager::AppendTaskL(THerculeanLabours aTaskNumber)
{
TTask tempTask(aTaskNumber);
User::LeaveIfError(iTaskArray.Append(tempTask));
}
// Deletes all tasks of aTaskNumber from the array
void CHerculeanTaskManager::DeleteTask(THerculeanLabours aTaskNumber)
{
TTask tempTask(aTaskNumber);
TInt foundIndex = iTaskArray.Find(tempTask, TTask::MatchTasks);
while (foundIndex!=KErrNotFound)
{
iTaskArray.Remove(foundIndex);
foundIndex = iTaskArray.Find(tempTask, TTask::MatchTasks);
}
}
void CHerculeanTaskManager::GetTask(THerculeanLabours aTaskNumber, TTask& aTask)
{
TTask tempTask(aTaskNumber);
TInt foundIndex = iTaskArray.Find(tempTask, TTask::MatchTasks);
aTask = iTaskArray[foundIndex];
}
// aTaskList is an empty RBuf
// Lists the tasks as they found in the array
void CHerculeanTaskManager::ListTasksL(RBuf & aTaskList)
{
// Get length of descriptor data required
TInt listLength = GetTaskListLength();
ASSERT(listLength>=0);
aTaskList.CreateL(listLength);
TInt count=iTaskArray.Count();
for (TInt index = 0; index<count; index++)
{
TTask task = iTaskArray[index];
aTaskList.Append(KTaskEntry);
aTaskList.Append(task.LabourName());
aTaskList.Append(KNewLine);
}
}
// aTaskList is an empty RBuf
// Sorts the tasks into numerical order starting from the lowest value of iLabour
void CHerculeanTaskManager::ListTasksAscendingL(RBuf & aTaskList)
{
SortTasksAscending();
ListTasksL(aTaskList);
}
void CHerculeanTaskManager::SortTasksAscending()
{
iTaskArray.Sort(TTask::CompareTaskNumbers);
}
// Returns the number of bytes required for a list of tasks
TInt CHerculeanTaskManager::GetTaskListLength()
{
TInt taskEntryLength = (KTaskEntry().Length()) + (KNewLine().Length());
TInt listLength = 0;
TInt count=iTaskArray.Count();
for (TInt index = 0; index<count; index++)
{
TTask task = iTaskArray[index];
listLength+=task.LabourName().Length();
listLength+=taskEntryLength;
}
return (listLength);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -