流的operator<<() 内部流程

流的operator<<() 内部流程

首先,在symbian内部,它申明了这么一个模板方法:
template <class T>
inline RWriteStream& operator<<(RWriteStream& aStream,const T& anObject)
    {
    DoExternalizeL(anObject,aStream,Externalization(&anObject));
    return aStream;
    }

接着又定义了DoExternalizeL的两个overload方法:
template <class T>
inline void DoExternalizeL(const T& anObject,RWriteStream& aStream,Externalize::Member)
    {anObject.ExternalizeL(aStream);}

template <class T>
inline void DoExternalizeL(const T& anObject,RWriteStream& aStream,Externalize::Function)
    {ExternalizeL(anObject,aStream);}

根据不同的的Externalization类型,会选择两个不同的调用方法。

在store框架中,默认了一个原形是:
Externalize::Member Externalization(const TAny*)
这就解释了,为什么在store体系下,流只用在该类中加入ExternalizeL方法就可以执行operator<<()调用了。

而Implementation for a class without ExternalizeL() & InternalizeL()介绍过一种方法:
implement the following Externalization() and Internalization() global functions:

inline Externalize::Function Externalization(const TNonstore*)
          {return Externalize::Function();}
inline Internalize::Function Internalization(TNonstore*)
          {return Internalize::Function();}

declare the following ExternalizeL() and InternalizeL() global functions:

void ExternalizeL(const TNonstore& aClass,RWriteStream& aStream);
void InternalizeL(TNonstore& aClass,RReadStream& aStream);

implement the ExternalizeL() and InternalizeL() global functions to implement the streaming of TNonstore’s components. For this example class:

也就是根据上面这个原理来实现的。

 

Leave a Reply

Your email address will not be published. Required fields are marked *