|
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: Map implementation header. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __MAP_H__ |
|
20 #define __MAP_H__ |
|
21 |
|
22 /**************************************************************** |
|
23 This template class represent a hash map |
|
24 USE ONLY POINTERS TO CLASSES!!! |
|
25 INSERTION TRANSFERS THE OWNERSHIP OF THE INSERTED POINTER!!! |
|
26 |
|
27 For example the correct interger key and value insertion is: |
|
28 static void InsertEntryL(RMap<TInt64, TInt64>& aMap, const TInt aKey,const TInt aValue) |
|
29 { |
|
30 TInt64* k64 = new TInt64; |
|
31 *k64 = aKey; |
|
32 TInt64* v64 = new TInt64; |
|
33 *v64 = aValue; |
|
34 |
|
35 aMap.InsertL(k64, v64); |
|
36 } |
|
37 ****************************************************************/ |
|
38 |
|
39 #include "SafePointerArray.h" |
|
40 |
|
41 template <class Tkey, class Tvalue> |
|
42 class RMap |
|
43 { |
|
44 public: |
|
45 inline RMap(const TLinearOrder<Tkey>& anOrder); |
|
46 inline void ResetAndDestroy(); |
|
47 inline void Close(); |
|
48 |
|
49 //insert related functions |
|
50 inline void InsertL(const Tkey* aKey, const Tvalue* aValue); |
|
51 inline const Tvalue* InsertReplaceL(const Tkey* aKey, const Tvalue* aValue); |
|
52 |
|
53 //check if there is an element with this key |
|
54 inline TBool ContainsKey(const Tkey& aKey) const; |
|
55 inline TBool ContainsValue(const Tvalue& aValue) const; |
|
56 inline TInt Find(const Tkey& aKey) const; |
|
57 |
|
58 //value by key |
|
59 inline Tvalue& GetValueL(const Tkey& aKey) const; |
|
60 //key by value |
|
61 inline Tkey& GetKeyL(const Tvalue& aValue) const; |
|
62 |
|
63 //remove the element with this key |
|
64 inline void RemoveL(const Tkey& aKey); |
|
65 inline void RemoveAtL(TInt anIndex, Tkey*& aKey, Tvalue*& aValue); |
|
66 |
|
67 RSafePointerArray<Tkey>& Keys(); |
|
68 RSafePointerArray<Tvalue>& Values(); |
|
69 |
|
70 //key by index |
|
71 inline Tkey& KeyAt(TInt anIndex); |
|
72 inline const Tkey& KeyAt(TInt anIndex) const; |
|
73 //value by index |
|
74 inline Tvalue& ValueAt(TInt anIndex); |
|
75 inline const Tvalue& ValueAt(TInt anIndex) const; |
|
76 |
|
77 //length |
|
78 inline TInt Count() const; |
|
79 |
|
80 static TInt CompareAlphabetDes(const TDesC& aFirst,const TDesC& aSecond) |
|
81 { |
|
82 if (aFirst < aSecond) |
|
83 { |
|
84 return -1; |
|
85 } |
|
86 |
|
87 if (aFirst > aSecond) |
|
88 { |
|
89 return 1; |
|
90 } |
|
91 |
|
92 return 0; |
|
93 } |
|
94 |
|
95 static TInt CompareAlphabetDes8(const TDesC8& aFirst,const TDesC8& aSecond) |
|
96 { |
|
97 if (aFirst < aSecond) |
|
98 { |
|
99 return -1; |
|
100 } |
|
101 |
|
102 if (aFirst > aSecond) |
|
103 { |
|
104 return 1; |
|
105 } |
|
106 |
|
107 return 0; |
|
108 } |
|
109 |
|
110 static TInt CompareInt(const TInt64& aFirst,const TInt64& aSecond) |
|
111 { |
|
112 if (aFirst < aSecond) |
|
113 { |
|
114 return -1; |
|
115 } |
|
116 |
|
117 if (aFirst > aSecond) |
|
118 { |
|
119 return 1; |
|
120 } |
|
121 |
|
122 return 0; |
|
123 } |
|
124 protected: |
|
125 TLinearOrder<Tkey> iOrder; |
|
126 RSafePointerArray<Tkey> iKeys; |
|
127 RSafePointerArray<Tvalue> iValues; |
|
128 }; |
|
129 /* |
|
130 template <class T> |
|
131 class CMap: public CArrayFixFlat<T> |
|
132 { |
|
133 public: |
|
134 CMap(const TKeyArrayFix& aKey); |
|
135 inline void Reset(); |
|
136 |
|
137 //insert related functions |
|
138 inline void InsertL(const T& anEntry); |
|
139 inline Tvalue InsertReplaceL(const T& anEntry); |
|
140 |
|
141 //check if there is an element with this key |
|
142 TBool ContainsKey(const Tkey& aKey); |
|
143 |
|
144 //value by key |
|
145 Tvalue& GetValueL(const Tkey& aKey); |
|
146 //key by value |
|
147 Tkey& GetKeyL(const Tvalue& aValue); |
|
148 |
|
149 //remove the element with this key |
|
150 void RemoveL(const Tkey& aKey); |
|
151 |
|
152 RArray<Tkey>& Keys(); |
|
153 RArray<Tvalue>& Values(); |
|
154 |
|
155 //key by index |
|
156 Tkey& KeyAt(TInt anIndex); |
|
157 const Tkey& KeyAt(TInt anIndex) const; |
|
158 //value by index |
|
159 Tvalue& ValueAt(TInt anIndex); |
|
160 const Tvalue& ValueAt(TInt anIndex) const; |
|
161 |
|
162 //length |
|
163 inline TInt Count() const; |
|
164 |
|
165 protected: |
|
166 TKeyArrayFix& iKey; |
|
167 }; |
|
168 |
|
169 */ |
|
170 |
|
171 #include "Map.inl" |
|
172 |
|
173 #endif //__MAP_H__ |