📄 todo.cpp
字号:
#include"ToDo.h"
#include"ToDoList.h"
const TDesC& CToDo::GetSubject() const
{
return *iSubject; //因为定义的是指针类型,而返回的是引用,所以要加*
}
void CToDo::SetSubject(const TDesC& aSubject)
{
delete iSubject;
iSubject = aSubject.AllocL();
}
const TDesC& CToDo::Location() const
{
return *iLocation;
}
void CToDo::SetLocation(const TDesC& aLocation)
{
delete iLocation;
iLocation = aLocation.AllocL();
}
const TDesC& CToDo::Comments() const
{
return *iComments;
}
void CToDo::SetComments(const TDesC& aComments)
{
delete iComments;
iComments = HBufC::NewL(aComments.Length());
*iComments = aComments;
}
const TDesC& CToDo::Person() const
{
return iPerson;
}
void CToDo::SetPerson(const TDesC& aPerson)
{
iPerson = aPerson;
}
const TInt16 CToDo::Alarm() const
{
return iAlarm;
}
void CToDo::SetAlarm(TInt16 aAlarm)
{
iAlarm = aAlarm;
}
const TInt CToDo::Priority() const
{
return iPriority;
}
void CToDo::SetPriority(TInt16 aPriority)
{
iPriority = aPriority;
}
const TDateTime CToDo::Time() const
{
return iTime;
}
void CToDo::SetTime(TDateTime aTime)
{
iTime = aTime;
}
const TDateTime CToDo::Date() const
{
return iDate;
}
void CToDo::SetDate(TDateTime aDate)
{
iDate = aDate;
}
CToDo* CToDo::NewLC(const TDesC& aSubject, TDateTime& aTime, TDateTime& aDate, const TDesC& aLocation, const TDesC& aPerson,
TInt16 aAlarm, TInt16 aPriority, const TDesC& aComments)
{
CToDo* self = new(ELeave)CToDo(aTime, aDate,aPerson,aAlarm, aPriority);
CleanupStack::PushL(self);
self->ConstructL(aSubject, aLocation, aComments);
return self;
}
CToDo* CToDo::NewL(const TDesC& aSubject, TDateTime& aTime, TDateTime& aDate, const TDesC& aLocation, const TDesC& aPerson,
TInt16 aAlarm, TInt16 aPriority, const TDesC& aComments)
{
CToDo* self = CToDo::NewLC(aSubject, aTime, aDate, aLocation, aPerson, aAlarm,aPriority,aComments);
CleanupStack::Pop(self);
return self;
}
CToDo* CToDo::NewLC(RReadStream& aStream)
{
CToDo* self = new(ELeave)CToDo;
CleanupStack::PushL(self);
aStream >> *self;
return self;
}
CToDo* CToDo::NewL(RReadStream& aStream)
{
CToDo* self = CToDo::NewLC(aStream);
CleanupStack::Pop(self);
return self;
}
CToDo* CToDo::NewLC()
{
CToDo* todo = new(ELeave)CToDo;
CleanupStack::PushL(todo);
todo->ConstructL();
return todo;
}
CToDo* CToDo::NewL()
{
CToDo* todo = CToDo::NewLC();
CleanupStack::Pop(todo);
return todo;
}
CToDo::~CToDo()
{
delete iSubject;
delete iLocation;
delete iComments;
}
void CToDo::ExternalizeL( RWriteStream& aStream ) const
{
TInt32 len = iSubject->Des().MaxLength();// tbufc 中没有最大值,所以用des调用
aStream << len;
aStream << *iSubject;
TTime time1(iTime);
TInt64 number1 = time1.Int64();
TBuf<20> bufValue;
bufValue.AppendNum( number1 );
aStream << bufValue;
TTime time2(iDate);
TInt64 number2 = time2.Int64();
bufValue.Zero();
bufValue.AppendNum( number2 );
aStream << bufValue;
TInt32 len1 = iLocation->Des().MaxLength();
aStream<< len1;
aStream << *iLocation;
aStream << iPerson;
aStream.WriteInt16L(iAlarm);
aStream.WriteInt16L(iPriority);
TInt32 len2 = iComments->Des().MaxLength();
aStream<< len2;
aStream << *iComments;
}
void CToDo::InternalizeL( RReadStream& aStream )
{
TInt32 len = 0;//从流中读数据时,是按顺序读的,哪个先写进去,哪个就先读出来,跟len没关系
aStream >> len;
delete iSubject;
iSubject = NULL;
iSubject = HBufC::NewL( aStream, len );
TInt64 number1 = 0;
TBufC<20> bufValue;
TPtr ptrValue( bufValue.Des() );
aStream >> ptrValue;
TLex lex( bufValue );
lex.Val(number1);
TTime time1( number1 );
iTime = time1.DateTime();
TInt64 number2 = 0;
TBufC<20> bufValue2;
ptrValue.Set( bufValue.Des() );
aStream >> ptrValue;
lex = bufValue;
lex.Val( number2 );
TTime time2( number2 );
iDate = time2.DateTime();
TInt32 len1 = 0;
aStream >> len1;
delete iLocation;
iLocation = NULL;
iLocation = HBufC::NewL(aStream, len1);
TPtr personPtr = iPerson.Des();
aStream >> personPtr;
iAlarm = aStream.ReadInt16L();
iPriority = aStream.ReadInt16L();
TInt32 len2 = 0;
aStream >> len2;
delete iComments;
iComments = NULL;
iComments = HBufC::NewL(aStream, len2);
}
CToDo::CToDo(TDateTime& aTime,TDateTime& aDate, const TDesC& aPerson,TInt16 aAlarm, TInt16 aPriority)
:iTime(aTime),iDate(aDate),iPerson(aPerson),iAlarm(aAlarm), iPriority(aPriority)
{
}
void CToDo::ConstructL(const TDesC& aSubject, const TDesC& aLocation, const TDesC& aComments)
{
iSubject = HBufC::NewL(aSubject.Length()); //hbufc 可以使用带RReadStream参数的NewL或NewLC从文件输入流中构建对象
*iSubject = aSubject;// 用hbufc在流中建立对象
// iName = aName.AllocL();
iLocation = aLocation.AllocL();
iComments = aComments.AllocL();
}
void CToDo::ConstructL()
{
iSubject = HBufC::NewL(1);
*iSubject = _L("");
iLocation = HBufC::NewL(1);
*iLocation = _L("");
iComments = HBufC::NewL(1);
*iComments = _L("");
}
/*void CToDo::Print()
{
console->Printf(_L("the subject is %S\n "), iSubject);
console->Printf(_L("the time is %d-%d-%d \n"), iTime.Year(),iTime.Month(), iTime.Day());
console->Printf(_L("the time is %d:%d:%d \n"), iDate.Hour(),iDate.Minute(), iDate.Second());
console->Printf(_L("the location is %S\n"), iLocation);
console->Printf(_L("the person is %S\n"), iPerson);
console->Printf(_L("the alarm is %S\n"), iAlarm);
console->Printf(_L("the priority is %S\n"), iPriority);
console->Printf(_L("the comments is %S\n"), iComments);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -