|
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-D0BD34C9-7793-5FA0-8864-FD7444D62F90" xml:lang="en"><title>How to |
|
13 form links</title><shortdesc>This document describes how to use links within a doubly linked |
|
14 list.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
15 <p>To form a doubly linked list of <codeph>CMyClass</codeph> objects, include |
|
16 the link object <codeph>TDblQueLink</codeph> as a component of <codeph>CMyClass</codeph>:</p> |
|
17 <codeblock id="GUID-E595B603-FC0D-5AF3-9228-7D40C3A08271" xml:space="preserve">class CMyClass : public CBase |
|
18 { |
|
19 ... |
|
20 TDblQueLink iDlink; |
|
21 ... |
|
22 };</codeblock> |
|
23 <fig id="GUID-30C9DE23-1805-594C-9F7F-BD4A161DE59A"> |
|
24 <image href="GUID-F342B002-0667-5D51-AE2D-3CF534D70B62_d0e217456_href.png" placement="inline"/> |
|
25 </fig> |
|
26 <p>Although any kind of object can be an element of a linked list, most lists |
|
27 consist of elements which are all of the same type.</p> |
|
28 <p>An object can participate in more than one list. For example, to allow <codeph>CMyClass</codeph> objects |
|
29 to participate in two doubly linked lists, include two separate <codeph>TDblQueLink</codeph> objects |
|
30 as components of <codeph>CMyClass</codeph>:</p> |
|
31 <codeblock id="GUID-2027BF61-9834-5915-9911-3420CAC7061A" xml:space="preserve">class CMyClass : public CBase |
|
32 { |
|
33 ... |
|
34 TDblQueLink iDlink1; |
|
35 ... |
|
36 TDblQueLink iDlink2; |
|
37 };</codeblock> |
|
38 <fig id="GUID-DC3DDF09-2F30-5704-ACB0-378622DDDD88"> |
|
39 <image href="GUID-B131AE10-B9B1-53D2-8CAA-A9045957D6F9_d0e217479_href.png" placement="inline"/> |
|
40 </fig> |
|
41 <p>Elements can also be objects constructed from a variety of classes, all |
|
42 ultimately derived from the same base class, where that base class includes |
|
43 the link object as a component. For example, if <codeph>CBc</codeph> is a |
|
44 base class for <codeph>CD1</codeph> which, in turn, is a base class for <codeph>CD2</codeph>, |
|
45 then the elements of the list can consist of a mix of <codeph>CBc</codeph> or <codeph>CDc1</codeph> or <codeph>CDc2</codeph> objects.</p> |
|
46 <codeblock id="GUID-C274DD90-E21A-5BAD-8094-79CE23CDA1B9" xml:space="preserve">class CBc : public CBase |
|
47 { |
|
48 ... |
|
49 TDblQueLink iDlink; |
|
50 ... |
|
51 };</codeblock> |
|
52 <codeblock id="GUID-6BAAB6AA-421F-51CE-8650-2FEDA3EB0A83" xml:space="preserve">class CDc1 : public CBclass |
|
53 { |
|
54 ... |
|
55 } |
|
56 </codeblock> |
|
57 <codeblock id="GUID-1C1A9078-0F8A-5E24-82CF-BD0C199B4050" xml:space="preserve">class CDc2 : public CDc1 |
|
58 { |
|
59 ... |
|
60 } |
|
61 </codeblock> |
|
62 <fig id="GUID-F8769477-6B6C-5531-9675-AC66FE6B6E3D"> |
|
63 <image href="GUID-38FF81FD-0C23-586D-AFAE-9F0761A36BAD_d0e217514_href.png" placement="inline"/> |
|
64 </fig> |
|
65 <p>New link elements are inserted into an existing list using either <codeph>TDblQueLink::Enque()</codeph> or <codeph>TDblQueLink::AddBefore()</codeph> function. Note that <codeph>AddBefore()</codeph> is not available in v5. |
|
66 These are prototyped as:</p> |
|
67 <codeblock id="GUID-DDD3FDA3-4635-5AFE-9C17-994E5E4D1C59" xml:space="preserve">void Enque(TDblQueLinkBase* aLink); |
|
68 </codeblock> |
|
69 <codeblock id="GUID-F3E72D69-0180-5BAD-A2C6-E31704820AAF" xml:space="preserve">void AddBefore(TDblQueLinkBase* aLink);</codeblock> |
|
70 <p>Calling <codeph>Enque()</codeph> on an element means that this element |
|
71 is added to the list so that its position follows the element <i>aLink</i>, |
|
72 as the following figure shows.</p> |
|
73 <fig id="GUID-F46E770B-8BDC-5E61-9E28-043FDAA3B193"> |
|
74 <image href="GUID-3E1199E4-4F19-58BB-B1EC-8975A04B68FF_d0e217546_href.png" placement="inline"/> |
|
75 </fig> |
|
76 <p>Calling <codeph>AddBefore()</codeph> on an element means that this element |
|
77 is added to the list so that its position precedes the element <i>aLink</i>, |
|
78 as the following figure shows.</p> |
|
79 <fig id="GUID-0E6C9ADF-0182-52CC-A3D1-AE83F540E42B"> |
|
80 <image href="GUID-2AB5AA00-71B2-58F4-AE17-9A38D1E5AA99_d0e217560_href.png" placement="inline"/> |
|
81 </fig> |
|
82 <p>Note that new elements cannot be inserted at the beginning or end of a |
|
83 list using these functions. The <codeph>AddFirst()</codeph> and <codeph>AddLast()</codeph> members |
|
84 of the header class <codeph>TDblQue<class T></codeph> must be used |
|
85 instead.</p> |
|
86 </conbody></concept> |