|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CMCEDICTIONARY_H |
|
22 #define CMCEDICTIONARY_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include "mcesrv.h" |
|
27 |
|
28 /** |
|
29 * Abstract base class for key - value pairs |
|
30 * |
|
31 * @lib |
|
32 * @since |
|
33 */ |
|
34 class CMceDictionaryItem : public CBase |
|
35 { |
|
36 public: // New functions |
|
37 |
|
38 /** |
|
39 * Returns the key |
|
40 * @return the key |
|
41 */ |
|
42 TInt Key(); |
|
43 |
|
44 protected: |
|
45 |
|
46 /** |
|
47 * Constructor |
|
48 * @param aKey the key |
|
49 */ |
|
50 CMceDictionaryItem( TInt aKey ); |
|
51 |
|
52 private: // Data |
|
53 |
|
54 // the key |
|
55 TInt iKey; |
|
56 }; |
|
57 |
|
58 /** |
|
59 * Template class for key-value pairs, where |
|
60 * the value is a T-class object. |
|
61 * |
|
62 * @lib |
|
63 * @since |
|
64 */ |
|
65 template <class T> |
|
66 class CMceKeyTValuePair : public CMceDictionaryItem |
|
67 { |
|
68 public: // Constructors and destructors |
|
69 |
|
70 /** |
|
71 * Constructor |
|
72 * @param aKey the key |
|
73 * @param aValue the value |
|
74 */ |
|
75 CMceKeyTValuePair( TInt aKey, T aValue ); |
|
76 |
|
77 public: // Functions from base classes |
|
78 |
|
79 // From CMceKeyValuePairBase |
|
80 /** |
|
81 * Returns the value. |
|
82 * @return the value |
|
83 */ |
|
84 T& Value(); |
|
85 |
|
86 public: // New functions |
|
87 |
|
88 /** |
|
89 * Sets the value |
|
90 * @param aValue |
|
91 */ |
|
92 void SetValue( T aValue ); |
|
93 |
|
94 private: // Data |
|
95 |
|
96 // the value |
|
97 T iValue; |
|
98 MCESRV_UT_DEFINITIONS |
|
99 }; |
|
100 |
|
101 /** |
|
102 * Template class for key-value pairs, where |
|
103 * the value is a C-class object. |
|
104 * |
|
105 * @lib |
|
106 * @since |
|
107 */ |
|
108 template <class C> |
|
109 class CMceKeyCValuePair : public CMceDictionaryItem |
|
110 { |
|
111 |
|
112 public: // Constructors and destructor |
|
113 |
|
114 /** |
|
115 * Constructor |
|
116 * @param aKey the key |
|
117 * @param aValue the value, ownership is transfered |
|
118 */ |
|
119 CMceKeyCValuePair( TInt aKey, C* aValue ); |
|
120 |
|
121 /** |
|
122 * Destructor |
|
123 */ |
|
124 ~CMceKeyCValuePair(); |
|
125 |
|
126 public: // Functions from base classes |
|
127 |
|
128 // From CMceKeyValuePairBase |
|
129 /** |
|
130 * Returns the value. |
|
131 * @return the value, ownership is not transfered |
|
132 */ |
|
133 C* Value(); |
|
134 |
|
135 public: // New functions |
|
136 /** |
|
137 * Sets the value |
|
138 * @param aValue |
|
139 */ |
|
140 void SetValue( C* aValue ); |
|
141 |
|
142 private: // data |
|
143 |
|
144 // the value, owned |
|
145 C* iValue; |
|
146 |
|
147 MCESRV_UT_DEFINITIONS |
|
148 }; |
|
149 |
|
150 |
|
151 /** |
|
152 * Cictionary that holds key-value pairs and allows modification of them. |
|
153 */ |
|
154 class CMceDictionary : public CBase |
|
155 { |
|
156 |
|
157 public: // Constructors and destructor |
|
158 |
|
159 /** |
|
160 * Destructor |
|
161 */ |
|
162 ~CMceDictionary(); |
|
163 |
|
164 public: // New functions |
|
165 |
|
166 /** |
|
167 * Returns the dictionary item with given key. |
|
168 * Returns NULL, if the item is not found. |
|
169 * @param aKey |
|
170 * @return the item, ownership is not transfered. |
|
171 */ |
|
172 CMceDictionaryItem* Pair( TInt aKey ) const; |
|
173 |
|
174 /** |
|
175 * Adds a key-value pair to the dictionary. |
|
176 * aPair the pair, ownership is transfered. |
|
177 * The pair |
|
178 */ |
|
179 void AddL( CMceDictionaryItem* aPair ); |
|
180 |
|
181 /** |
|
182 * Deletes a pair that has given key from the dictionary. |
|
183 * @param aKey the key |
|
184 */ |
|
185 void Delete( TInt aKey ); |
|
186 |
|
187 private: |
|
188 |
|
189 // data |
|
190 RPointerArray< CMceDictionaryItem > iPairs; |
|
191 |
|
192 MCESRV_UT_DEFINITIONS |
|
193 }; |
|
194 |
|
195 #include "mcedictionary.inl" |
|
196 #endif // CMCEDICTIONARY_H |
|
197 |
|
198 // End of File |