|
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: MXIMPRestrictedObjectCollection implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ximprestrictedobjectcollectionimp.h" |
|
19 |
|
20 // ============================ MEMBER FUNCTIONS ============================= |
|
21 |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // CXIMPRestrictedObjectCollectionImp::NewL() |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 EXPORT_C CXIMPRestrictedObjectCollectionImp* |
|
28 CXIMPRestrictedObjectCollectionImp::NewL( TBool aObjectOwning /*= ETrue*/ ) |
|
29 { |
|
30 CXIMPRestrictedObjectCollectionImp* self = NewLC( aObjectOwning ); |
|
31 CleanupStack::Pop( self ); |
|
32 return self; |
|
33 } |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CXIMPRestrictedObjectCollectionImp::NewLC() |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CXIMPRestrictedObjectCollectionImp* |
|
41 CXIMPRestrictedObjectCollectionImp::NewLC( TBool aObjectOwning /*= ETrue*/ ) |
|
42 { |
|
43 CXIMPRestrictedObjectCollectionImp* self = |
|
44 new (ELeave) CXIMPRestrictedObjectCollectionImp( aObjectOwning ); |
|
45 |
|
46 CleanupStack::PushL( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CXIMPRestrictedObjectCollectionImp::~CXIMPRestrictedObjectCollectionImp() |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CXIMPRestrictedObjectCollectionImp::~CXIMPRestrictedObjectCollectionImp() |
|
56 { |
|
57 if( iOwnObjects ) |
|
58 { |
|
59 iApiObjects.ResetAndDestroy(); |
|
60 } |
|
61 else |
|
62 { |
|
63 iApiObjects.Reset(); |
|
64 } |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CXIMPRestrictedObjectCollectionImp::CXIMPRestrictedObjectCollectionImp() |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CXIMPRestrictedObjectCollectionImp::CXIMPRestrictedObjectCollectionImp( TBool aObjectOwning ) |
|
73 : iOwnObjects( aObjectOwning ) |
|
74 { |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Implement supported interface access. |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CXIMPRestrictedObjectCollectionImp, |
|
83 MXIMPRestrictedObjectCollection ) |
|
84 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
85 |
|
86 |
|
87 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CXIMPRestrictedObjectCollectionImp, |
|
88 MXIMPRestrictedObjectCollection ) |
|
89 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
90 |
|
91 |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CXIMPRestrictedObjectCollectionImp::LookupByType() |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CXIMPRestrictedObjectCollectionImp::LookupByType( |
|
98 const MXIMPBase*& aObject, |
|
99 TInt32 aInterfaceId ) const |
|
100 { |
|
101 aObject = NULL; |
|
102 |
|
103 TInt index = iApiObjects.FindInOrder( aInterfaceId, |
|
104 OrderIfIdAndApiObject ); |
|
105 if( index != KErrNotFound ) |
|
106 { |
|
107 const CXIMPApiObjBase* theObject = iApiObjects[ index ]; |
|
108 aObject = &theObject->Base(); |
|
109 } |
|
110 } |
|
111 |
|
112 |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CXIMPRestrictedObjectCollectionImp::AddOrReplaceTypeL() |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CXIMPRestrictedObjectCollectionImp::AddOrReplaceTypeL( |
|
119 MXIMPBase* aObject ) |
|
120 { |
|
121 CXIMPApiObjBase* theObject = TXIMPGetImpClassOrPanic< CXIMPApiObjBase >::From( *aObject ); |
|
122 |
|
123 |
|
124 TInt index = KErrNotFound; |
|
125 TInt entryExists = iApiObjects.FindInOrder( theObject, |
|
126 index, |
|
127 OrderApiObjects ); |
|
128 |
|
129 if( entryExists == KErrNotFound ) |
|
130 { |
|
131 iApiObjects.InsertL( theObject, index ); |
|
132 } |
|
133 else |
|
134 { |
|
135 CXIMPApiObjBase* oldObject = iApiObjects[ index ]; |
|
136 if( iOwnObjects ) |
|
137 { |
|
138 delete oldObject; |
|
139 } |
|
140 iApiObjects[ index ] = theObject; |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CXIMPRestrictedObjectCollectionImp::GetByType() |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CXIMPRestrictedObjectCollectionImp::GetByType( |
|
151 MXIMPBase*& aObject, |
|
152 TInt32 aInterfaceId ) |
|
153 { |
|
154 aObject = NULL; |
|
155 |
|
156 TInt index = iApiObjects.FindInOrder( aInterfaceId, |
|
157 OrderIfIdAndApiObject ); |
|
158 if( index != KErrNotFound ) |
|
159 { |
|
160 CXIMPApiObjBase* theObject = iApiObjects[ index ]; |
|
161 aObject = &theObject->Base(); |
|
162 iApiObjects.Remove( index ); |
|
163 } |
|
164 } |
|
165 |
|
166 |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CXIMPRestrictedObjectCollectionImp::OrderIfIdAndApiObject() |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CXIMPRestrictedObjectCollectionImp::OrderIfIdAndApiObject( |
|
173 const TInt32* aIfId, |
|
174 const CXIMPApiObjBase& aRhs ) |
|
175 { |
|
176 return (*aIfId) - aRhs.Base().GetInterfaceId(); |
|
177 } |
|
178 |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CXIMPRestrictedObjectCollectionImp::OrderApiObjects() |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 TInt CXIMPRestrictedObjectCollectionImp::OrderApiObjects( |
|
185 const CXIMPApiObjBase& aLhs, |
|
186 const CXIMPApiObjBase& aRhs ) |
|
187 { |
|
188 const TInt32 interfaceId = aLhs.Base().GetInterfaceId(); |
|
189 return OrderIfIdAndApiObject( &interfaceId, aRhs ); |
|
190 } |
|
191 |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CXIMPRestrictedObjectCollectionImp::SetObjectOwnership() |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 EXPORT_C void CXIMPRestrictedObjectCollectionImp::SetObjectOwnership( TBool aObjectOwning /*= ETrue*/ ) |
|
198 { |
|
199 iOwnObjects = aObjectOwning; |
|
200 } |
|
201 // End of file |