|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept xml:lang="en" id="GUID-DA4160B0-7B63-5C84-B3C6-190100530EDE"><title>How to use templated stream operators</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Templated stream operators are straight forward to use. For example, given the class <codeph>TSimple</codeph> defined as:</p> <codeblock id="GUID-E705AC6E-6671-552D-90A3-6BEF66E30A0C" xml:space="preserve"> class TSimple |
|
13 { |
|
14 public : |
|
15 void InternalizeL(RReadStream& aStream); |
|
16 void ExternalizeL(RWriteStream& aStream) const; |
|
17 ... |
|
18 TInt8 iInt8Value; |
|
19 TInt64 iInt64Value; |
|
20 TRect iRectangle; |
|
21 TUid iUid; |
|
22 CBufSeg* iSegBuffer; |
|
23 }</codeblock> <p><codeph>ExternalizeL()</codeph> and <codeph>InternalizeL()</codeph> might be implemented as:</p> <codeblock id="GUID-F89A6EEB-FA20-5A2B-A3DB-33630212DD70" xml:space="preserve">void TSimple::ExternalizeL(RWriteStream& aStream) const |
|
24 { |
|
25 aStream << iInt8Value; |
|
26 aStream << iInt64Value; |
|
27 aStream << iRectangle |
|
28 aStream << iUid; |
|
29 aStream << *iSegBuffer; |
|
30 }</codeblock> <codeblock id="GUID-DABABB0C-435F-594C-9424-F27EBDC00F17" xml:space="preserve">void TSimple::InternalizeL(RReadStream& aStream) |
|
31 { |
|
32 aStream >> iInt8Value; |
|
33 aStream >> iInt64Value; |
|
34 aStream >> iRectangle |
|
35 aStream >> iUid; |
|
36 aStream >> *iSegBuffer; |
|
37 }</codeblock> <p>The templated operators can also be used on an object of type <codeph>TSimple</codeph>. For example:</p> <codeblock id="GUID-326FFA1F-3614-5257-A3F9-1908F25E5DC8" xml:space="preserve">TSimple simple; |
|
38 ... |
|
39 aStream << simple; |
|
40 ...</codeblock> <p>The <codeph>operator<<</codeph> results in call to <codeph>TSimple::ExternalizeL()</codeph> function and this, in turn, calls <codeph>operator<<</codeph> on <codeph>TSimple</codeph>'s data members.</p> </conbody></concept> |