Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Series60 2nd/3rd平台上序列化TTime对象

From Wiki
Jump to: navigation, search
Article Metadata

文章
beover1984 在 10 Aug 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

当程序的配置文件数据项比较多,类型比较多时通常使用二进制的形式来保存数据,RReadStream和RWriteStream提供了多种数值型和描述符类型的输入输出方法,但是其它基本类型就需要自己处理一下了,比如TTime,Symbian系统中使用一个64位整型来保存日期和时间,这样当序列化TTimer对象是就可以取出这个64位数值进行保存了,可是接下来会发现RReadStream和RWriteStream根本没有提供64位整型的输入输出方法,这时需要我们把64位整型拆分成两个32位整型数然后进行保存,下面的代码演示了如何序列化一个TTime对象,并展示了Series 2nd和3rd平台上的不同处理方法:

void ExternalizeL(RWriteStream& aStream) 
{
TTime time;
time.HomeTime();
//Decomposes TTime object into two TUint32 objects.
TUint32 low(0), high(0);
#if defined __SERIES60_3X__
low = I64LOW(time.Int64());
high = I64HIGH(time.Int64());
#else
low = time.Int64().Low();
high = time.Int64().High();
#endif
aStream.WriteUint32L( low );
aStream.WriteUint32L( high );
}
 
void InternalizeL(RReadStream& aStream)
{
//Two TUint32 objects combine to a TInt64 object for constructing a TTime object.
TUint32 low(0), high(0);
low = aStream.ReadUint32L();
high = aStream.ReadUint32L();
TInt64 timeVal( 0 );
#if defined __SERIES60_3X__
timeVal=MAKE_TINT64(high, low );
#else
timeVal = TInt64( high, low );
#endif
TTime time = timeVal;
}

补充: 64位整型在Symbian 8.1b之前和之后的版本上需要不同的处理方法,这是因为TInt64在Symbian 8.1b之前是以类的方式提供的,而在Symbian 8.1b之后则是内置的数据类型。

This page was last modified on 15 December 2011, at 10:21.
282 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×