|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of Parent Child Interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ParentChildIntfc.h" |
|
20 |
|
21 // --------------------------------------------------------------------------- |
|
22 // Destructor |
|
23 // --------------------------------------------------------------------------- |
|
24 CParentIntfc::~CParentIntfc() |
|
25 { |
|
26 TInt count = iChildrenList.Count(); |
|
27 CChildIntfc* childPtr(NULL); |
|
28 for (TInt index(0); index < count; index++) |
|
29 { |
|
30 if (GetChild(index, childPtr) == KErrNone) |
|
31 { |
|
32 childPtr->ParentDeleted(*((CParentIntfc*)this)); |
|
33 } |
|
34 } |
|
35 iChildrenList.Close(); |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // GetChildCount |
|
40 // --------------------------------------------------------------------------- |
|
41 TInt CParentIntfc::GetChildCount() |
|
42 { |
|
43 return iChildrenList.Count(); |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // GetChild |
|
48 // --------------------------------------------------------------------------- |
|
49 TInt CParentIntfc::GetChild( TInt aIndex, CChildIntfc*& aChild ) |
|
50 { |
|
51 TInt status(KErrArgument); |
|
52 if ( (0 <= aIndex ) && ( aIndex < iChildrenList.Count() ) ) |
|
53 { |
|
54 aChild = iChildrenList[aIndex]; |
|
55 status = KErrNone; |
|
56 } |
|
57 return status; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // SetChild |
|
62 // --------------------------------------------------------------------------- |
|
63 TInt CParentIntfc::SetChild( CChildIntfc& aChild ) |
|
64 { |
|
65 TInt status(KErrAlreadyExists); |
|
66 if ( iChildrenList.Find(&aChild) == KErrNotFound ) |
|
67 { |
|
68 status = iChildrenList.Append(&aChild); |
|
69 } |
|
70 return status; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // ChildDeleted |
|
75 // --------------------------------------------------------------------------- |
|
76 void CParentIntfc::ChildDeleted( CChildIntfc& aChild ) |
|
77 { |
|
78 TInt index(iChildrenList.Find(&aChild)); |
|
79 if ( index != KErrNotFound ) |
|
80 { |
|
81 iChildrenList.Remove(index); |
|
82 } |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Destructor |
|
87 // --------------------------------------------------------------------------- |
|
88 CChildIntfc::~CChildIntfc() |
|
89 { |
|
90 if ( iParent ) |
|
91 { |
|
92 iParent->ChildDeleted(*((CChildIntfc*)this)); |
|
93 } |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // ParentDeleted |
|
98 // --------------------------------------------------------------------------- |
|
99 void CChildIntfc::ParentDeleted( CParentIntfc& aParent ) |
|
100 { |
|
101 if ( iParent == &aParent ) |
|
102 { |
|
103 iParent = NULL; |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // GetParent |
|
109 // --------------------------------------------------------------------------- |
|
110 TInt CChildIntfc::GetParent( CParentIntfc*& aParent ) |
|
111 { |
|
112 TInt status(KErrNotFound); |
|
113 if ( iParent ) |
|
114 { |
|
115 aParent = iParent; |
|
116 status = KErrNone; |
|
117 } |
|
118 return status; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // SetParent |
|
123 // --------------------------------------------------------------------------- |
|
124 TInt CChildIntfc::SetParent( CParentIntfc& aParent ) |
|
125 { |
|
126 TInt status(KErrAlreadyExists); |
|
127 if ( !iParent ) |
|
128 { |
|
129 iParent = &aParent; |
|
130 status = KErrNone; |
|
131 } |
|
132 return status; |
|
133 } |
|
134 |
|
135 // End of file |