|
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: Object collection implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef XIMPOBJECTCOLLECTIONIMP_H |
|
19 #define XIMPOBJECTCOLLECTIONIMP_H |
|
20 |
|
21 #include "ximpapiobjbase.h" |
|
22 #include <e32std.h> |
|
23 #include <ximpobjectcollection.h> |
|
24 |
|
25 |
|
26 /** |
|
27 * Object collection implementation. |
|
28 * |
|
29 * @see MXIMPObjectCollection |
|
30 * @ingroup ximpdatamodelapi |
|
31 * @since S60 v3.2 |
|
32 */ |
|
33 class CXIMPObjectCollectionImp : public CXIMPApiObjBase, |
|
34 public MXIMPObjectCollection |
|
35 { |
|
36 |
|
37 private: // helper class |
|
38 |
|
39 class CXIMPCollectionElement : public CBase |
|
40 { |
|
41 public: |
|
42 |
|
43 static CXIMPCollectionElement* NewL( CXIMPApiObjBase* aObject, const TDesC8& aName ); |
|
44 ~CXIMPCollectionElement(); |
|
45 |
|
46 /** |
|
47 * Get the stored object. Ownership transferred |
|
48 * to the caller. |
|
49 * @param The stored object |
|
50 */ |
|
51 CXIMPApiObjBase* GetObject(); |
|
52 |
|
53 private: |
|
54 |
|
55 CXIMPCollectionElement(); |
|
56 void ConstructL( CXIMPApiObjBase* aObject, const TDesC8& aName ); |
|
57 |
|
58 public: |
|
59 // owns: the object |
|
60 CXIMPApiObjBase* iObject; |
|
61 |
|
62 // owns: the name (always valid, but can be empty) |
|
63 HBufC8* iName; |
|
64 }; |
|
65 |
|
66 public: |
|
67 |
|
68 /** The class ID. */ |
|
69 enum { KClassId = XIMPIMP_CLSID_CXIMPOBJECTCOLLECTIONIMP }; |
|
70 |
|
71 public: |
|
72 |
|
73 IMPORT_C static CXIMPObjectCollectionImp* NewLC(); |
|
74 IMPORT_C static CXIMPObjectCollectionImp* NewL(); |
|
75 |
|
76 public: |
|
77 |
|
78 /** |
|
79 * Destruction |
|
80 */ |
|
81 ~CXIMPObjectCollectionImp(); |
|
82 |
|
83 |
|
84 private: |
|
85 |
|
86 CXIMPObjectCollectionImp(); |
|
87 |
|
88 |
|
89 public: // From MXIMPBase |
|
90 |
|
91 /** |
|
92 * Implementation of MXIMPBase interface methods |
|
93 * @see MXIMPBase |
|
94 */ |
|
95 XIMPIMP_DECLARE_IF_BASE_METHODS |
|
96 |
|
97 public: // from MXIMPObjectCollection |
|
98 |
|
99 // object lookup |
|
100 |
|
101 /** |
|
102 * @see MXIMPObjectCollection |
|
103 */ |
|
104 void LookupByType( |
|
105 const MXIMPBase*& aObject, |
|
106 TInt32 aInterfaceId ) const; |
|
107 |
|
108 /** |
|
109 * @see MXIMPObjectCollection |
|
110 */ |
|
111 void LookupByTypeAndName( |
|
112 const MXIMPBase*& aObject, |
|
113 TInt32 aInterfaceId, |
|
114 const TDesC8& aMatch ) const; |
|
115 |
|
116 // set management |
|
117 |
|
118 /** |
|
119 * @see MXIMPObjectCollection |
|
120 */ |
|
121 void AddObjectL( |
|
122 MXIMPBase* aObject ); |
|
123 |
|
124 /** |
|
125 * @see MXIMPObjectCollection |
|
126 */ |
|
127 void AddObjectWithNameL( |
|
128 MXIMPBase* aObject, |
|
129 const TDesC8& aName ); |
|
130 |
|
131 |
|
132 /** |
|
133 * @see MXIMPObjectCollection |
|
134 */ |
|
135 TBool GetByType( |
|
136 MXIMPBase*& aObject, |
|
137 TInt32 aInterfaceId ); |
|
138 |
|
139 /** |
|
140 * @see MXIMPObjectCollection |
|
141 */ |
|
142 TBool GetByTypeAndName( |
|
143 MXIMPBase*& aObject, |
|
144 TInt32 aInterfaceId, |
|
145 const TDesC8& aMatch ); |
|
146 |
|
147 private: // helpers |
|
148 |
|
149 /** |
|
150 * Find the index of the least recently used |
|
151 * object. Since the internal array is LIFO, |
|
152 * we walk the array forwards to find the index of |
|
153 * least recently used object. |
|
154 * @param aObject The object from which to start |
|
155 * @return The index |
|
156 */ |
|
157 TInt FindLRUIndex( const MXIMPBase*& aObject ) const; |
|
158 |
|
159 /** |
|
160 * Validate a given name. Checks that wildcard characters do not exist. |
|
161 * @return KErrNone if the name is OK, KErrBadName otherwise |
|
162 */ |
|
163 TInt ValidateName( const TDesC8& aName ) const; |
|
164 |
|
165 private: // data |
|
166 |
|
167 /** |
|
168 * OWN: Objects |
|
169 */ |
|
170 RXIMPObjOwningPtrArray< CXIMPCollectionElement > iCollection; |
|
171 |
|
172 }; |
|
173 |
|
174 |
|
175 #endif // XIMPOBJECTCOLLECTIONIMP_H |
|
176 |