|
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: Utility class for impementing Parent/Child class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ParentChildIntfc.h" |
|
19 |
|
20 CParentIntfc::~CParentIntfc() |
|
21 { |
|
22 TInt count = iChildrenList.Count(); |
|
23 CChildIntfc* childPtr(NULL); |
|
24 for (TInt index(0); index < count; index++) |
|
25 { |
|
26 if (GetChild(index, childPtr) == KErrNone) |
|
27 { |
|
28 childPtr->ParentDeleted(*((CParentIntfc*)this)); |
|
29 } |
|
30 } |
|
31 iChildrenList.Close(); |
|
32 } |
|
33 |
|
34 TInt CParentIntfc::GetChildCount() |
|
35 { |
|
36 return iChildrenList.Count(); |
|
37 } |
|
38 |
|
39 TInt CParentIntfc::GetChild( TInt aIndex, CChildIntfc*& aChild ) |
|
40 { |
|
41 TInt status(KErrArgument); |
|
42 if ( (0 <= aIndex ) && ( aIndex < iChildrenList.Count() ) ) |
|
43 { |
|
44 aChild = iChildrenList[aIndex]; |
|
45 status = KErrNone; |
|
46 } |
|
47 return status; |
|
48 } |
|
49 |
|
50 TInt CParentIntfc::SetChild( CChildIntfc& aChild ) |
|
51 { |
|
52 TInt status(KErrAlreadyExists); |
|
53 if ( iChildrenList.Find(&aChild) == KErrNotFound ) |
|
54 { |
|
55 status = iChildrenList.Append(&aChild); |
|
56 } |
|
57 return status; |
|
58 } |
|
59 |
|
60 void CParentIntfc::ChildDeleted( CChildIntfc& aChild ) |
|
61 { |
|
62 TInt index(iChildrenList.Find(&aChild)); |
|
63 if ( index != KErrNotFound ) |
|
64 { |
|
65 iChildrenList.Remove(index); |
|
66 } |
|
67 } |
|
68 |
|
69 CChildIntfc::~CChildIntfc() |
|
70 { |
|
71 if ( iParent ) |
|
72 { |
|
73 iParent->ChildDeleted(*((CChildIntfc*)this)); |
|
74 } |
|
75 } |
|
76 |
|
77 void CChildIntfc::ParentDeleted( CParentIntfc& aParent ) |
|
78 { |
|
79 if ( iParent == &aParent ) |
|
80 { |
|
81 iParent = NULL; |
|
82 } |
|
83 } |
|
84 |
|
85 TInt CChildIntfc::GetParent( CParentIntfc*& aParent ) |
|
86 { |
|
87 TInt status(KErrNotFound); |
|
88 if ( iParent ) |
|
89 { |
|
90 aParent = iParent; |
|
91 status = KErrNone; |
|
92 } |
|
93 return status; |
|
94 } |
|
95 |
|
96 TInt CChildIntfc::SetParent( CParentIntfc& aParent ) |
|
97 { |
|
98 TInt status(KErrAlreadyExists); |
|
99 if ( !iParent ) |
|
100 { |
|
101 iParent = &aParent; |
|
102 status = KErrNone; |
|
103 } |
|
104 return status; |
|
105 } |
|
106 |
|
107 // End of file |