Symbian3/PDK/Source/GUID-0C8389B8-91DF-58A1-A2A1-945A18CCBB10.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     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 id="GUID-0C8389B8-91DF-58A1-A2A1-945A18CCBB10" xml:lang="en"><title>Using
       
    13 TLitC operators</title><shortdesc>Explains how to use <codeph>TLitC</codeph> operations.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>The <codeph>TLitC</codeph> class offers four operators, two of which are
       
    15 conversion operators.</p>
       
    16 <p>The conversion operators are invoked by the compiler when a <codeph>TLitC&lt;TInt&gt;</codeph> type
       
    17 is passed to a function which takes the following argument types:</p>
       
    18 <ul>
       
    19 <li id="GUID-BEF085A9-56B5-579F-A316-B68C108BED9B"><p>a reference by value,
       
    20 i.e. a <codeph>TRefByValue&lt;class              T&gt;</codeph> type</p> </li>
       
    21 <li id="GUID-911E904A-83F8-52B1-BAA1-0C993683BAD3"><p>a const reference to
       
    22 a descriptor, i.e. a <codeph>const              TDesC&amp;</codeph> type</p> </li>
       
    23 </ul>
       
    24 <p>The other two operators return:</p>
       
    25 <ul>
       
    26 <li id="GUID-B42C7636-5E8F-5BD6-98C8-1EF0E7AD388D"><p>a pointer to a constant
       
    27 descriptor, i.e. a <codeph>const              TDesC*</codeph> type</p> </li>
       
    28 <li id="GUID-141D07F5-4D60-5940-A404-2718494D6CCB"><p>a reference to a constant
       
    29 descriptor, i.e. a <codeph>const              TDesC&amp;</codeph> type</p> </li>
       
    30 </ul>
       
    31 <p>The following code fragments show the situations where the operators are
       
    32 called on a <codeph>TLitC</codeph>. The fragments are similar for both <codeph>TLitC8</codeph> and <codeph>TLitC16</codeph>.</p>
       
    33 <section id="GUID-AF4A4619-1C5A-4022-9700-4EB09C9001FE"><title>Reference by value conversion operator operator const __TRefDesC()</title> <p>The
       
    34 following code fragment shows the operator in use:</p> <codeblock id="GUID-63CE5630-61CB-5428-8F7C-EB84445FD63A" xml:space="preserve">...
       
    35 TBuf&lt;256&gt; x;
       
    36 ...
       
    37 _LIT(KTxtFormat,"There are %d cm in a metre");
       
    38 x.Format(KTxtFormat,100);
       
    39 ...
       
    40 </codeblock> </section>
       
    41 <section id="GUID-6B904805-4C60-4721-B02D-6999CA18E2F5"><title>Const descriptor reference conversion operator operator const
       
    42 TDesC&amp;</title> <p>The following code fragment shows the operator in use:</p> <codeblock id="GUID-8D7F387D-B675-5EC4-B88D-4389F4D5B961" xml:space="preserve">...
       
    43 _LIT(KSomeData,"Some data");
       
    44 ...
       
    45 TPtrC x(KSomeData);</codeblock> </section>
       
    46 <section id="GUID-6389D8D4-CC0E-45AA-81EC-43E86C28A7AE"><title>Address of operator operator&amp;()</title> <p>The following
       
    47 code fragment shows the operator in use:</p> <codeblock id="GUID-1AE87D87-53AD-5E88-864A-785D95598D02" xml:space="preserve">class CX...
       
    48  {
       
    49  void Foo(const TDesC* aDesC);
       
    50  };
       
    51 
       
    52 ...
       
    53 _LIT(KLiteral,"some text");
       
    54 ...
       
    55 CX* anx;
       
    56 ...
       
    57 anx-&gt;Foo(&amp;KLiteral);
       
    58 ...</codeblock> </section>
       
    59 <section id="GUID-52E52945-1FFD-4B49-96C0-2D423B829033"><title>Reference operator operator()</title> <p>The following code
       
    60 fragment shows the operator in use:</p> <codeblock id="GUID-2A7C5828-7C2B-58F2-819E-9EAAD6071457" xml:space="preserve">...
       
    61 _LIT(KKeywordSelect,"select");
       
    62 if (KKeywordSelect().CompareF(token)&lt;0)
       
    63 ...</codeblock> </section>
       
    64 </conbody></concept>