Templated stream operators are straight forward to use. For example, given the class TSimple defined as:
class TSimple
{
public :
void InternalizeL(RReadStream& aStream);
void ExternalizeL(RWriteStream& aStream) const;
...
TInt8 iInt8Value;
TInt64 iInt64Value;
TRect iRectangle;
TUid iUid;
CBufSeg* iSegBuffer;
} ExternalizeL() and InternalizeL() might be implemented as:
void TSimple::ExternalizeL(RWriteStream& aStream) const
{
aStream << iInt8Value;
aStream << iInt64Value;
aStream << iRectangle
aStream << iUid;
aStream << *iSegBuffer;
} void TSimple::InternalizeL(RReadStream& aStream)
{
aStream >> iInt8Value;
aStream >> iInt64Value;
aStream >> iRectangle
aStream >> iUid;
aStream >> *iSegBuffer;
} The templated operators can also be used on an object of type TSimple. For example:
TSimple simple; ... aStream << simple; ...
The operator<< results in call to TSimple::ExternalizeL() function and this, in turn, calls operator<< on TSimple's data members.