Symbian3/PDK/Source/GUID-497930CE-4D61-50EE-A63B-3656158EE29C.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 13 Aug 2010 16:47:46 +0100
changeset 14 578be2adaf3e
parent 5 f345bda72bc4
permissions -rw-r--r--
Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     1
<?xml version="1.0" encoding="utf-8"?>
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     2
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     3
<!-- This component and the accompanying materials are made available under the terms of the License 
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     4
"Eclipse Public License v1.0" which accompanies this distribution, 
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     5
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     6
<!-- Initial Contributors:
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     7
    Nokia Corporation - initial contribution.
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     8
Contributors: 
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
     9
-->
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
    10
<!DOCTYPE concept
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
    11
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
    12
<concept xml:lang="en" id="GUID-497930CE-4D61-50EE-A63B-3656158EE29C"><title>Thin Templates</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Symbian platform C++ uses C++ templates in an efficient way called the thin template idiom. </p> <p>Templates are particularly useful for collection classes, such as arrays. The class declaration: </p> <codeblock id="GUID-ACAAAE20-4A81-5C4F-930B-31097FBAD432" xml:space="preserve">class CArrayFixFlat&lt;T&gt; ...</codeblock> <p>specifies a family of array classes, which may contain any type. The template may be instantiated, for instance, as </p> <codeblock id="GUID-D02E8C13-85FA-5DA2-8A5E-5F1C15F4038C" xml:space="preserve">CArrayFixFlat&lt;CCoeControl*&gt;* iControls;</codeblock> <p>which declares an array of <codeph>CCoeControl*</codeph> pointers. Other collection classes use the same idea, for instance <codeph>TPckgBuf&lt;T&gt;</codeph>, <codeph>TSglQue&lt;T&gt;</codeph> etc. </p> <p>Templates may also use other parameters, such as an integer: </p> <codeblock id="GUID-209E8594-EFC2-5F55-AF45-51CE538C1336" xml:space="preserve">class TBufC&lt;TInt S&gt; ...;</codeblock> <p>This type of template class may be instantiated also: </p> <codeblock id="GUID-5ABEBD1D-1B0A-5C57-B35E-260180F31978" xml:space="preserve">TBufC&lt;20&gt; name; </codeblock> <p>The functionality provided by templates is powerful, and highly desirable. Without templates, collection classes usually use <codeph>void*</codeph> pointers: as a result, they are not typesafe. </p> <p>Templates can be difficult to manage. A template really defines a whole family of classes. Each member of that family that is instantiated requires its own object code. Avoidance of object code duplication is a difficult issue in a C++ implementation. For the Symbian platform, object code duplication must be avoided at all costs. The solution used is the <i>thin template idiom</i>. </p> <p>The thin template idiom begins with a base class, code in terms of <codeph>TAny*</codeph> parameters: </p> <codeblock id="GUID-C6ADB9B7-4290-5A6B-B1B4-7D9C88E90B1F" xml:space="preserve">class CArrayFixBase ... {
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
    13
    IMPORT_C const TAny* At(TInt aIndex) const;</codeblock> <p>This base class has the real code, just once. The code resides in a single DLL and is exported from that DLL. The base class may be fat: it may contain an arbitrary amount of code. </p> <p>Then, a derived class is used as follows: </p> <codeblock id="GUID-58361D84-0D13-5E9B-936F-1D4724A71282" xml:space="preserve">class CArrayFix&lt;T&gt; : public CArrayFixBase {
578be2adaf3e Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
Dominic Pinkman <dominic.pinkman@nokia.com>
parents: 5
diff changeset
    14
    inline const T&amp; At(TInt aIndex) const
1
25a17d01db0c Addition of the PDK content and example code for Documentation_content according to Feature bug 1607 and bug 1608
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    15
    {return(*((const T *)CArrayFixBase::At(anIndex)));}</codeblock> <p>Because this class uses only inline functions, it generates no extra code. But because the casting is encapsulated in the inline function, the class is typesafe to its users. The templated class is thin: it generates no code at all. </p> </conbody></concept>