|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // RMap template class declaration. |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef __D32MAP_H__ |
|
19 #define __D32MAP_H__ |
|
20 |
|
21 #include "D32Assert.h" |
|
22 |
|
23 /** |
|
24 (KEY, DATA) template pair class used by RMap template class. |
|
25 @internalComponent |
|
26 */ |
|
27 template <class KEY, class DATA> |
|
28 struct TPair |
|
29 { |
|
30 TPair(const KEY& aKey, const DATA& aData); |
|
31 TPair(const KEY& aKey); |
|
32 TPair(); |
|
33 KEY iKey; |
|
34 DATA iData; |
|
35 }; |
|
36 |
|
37 //Forward declaration |
|
38 template <class KEY, class DATA> class RMap; |
|
39 |
|
40 /** |
|
41 TMapIterator class. It describes an object which can be used as a |
|
42 forward read-only iterator for sequence of type RMap. |
|
43 @internalComponent |
|
44 */ |
|
45 template <class KEY, class DATA> |
|
46 class TMapIterator |
|
47 { |
|
48 public: |
|
49 TMapIterator(const RMap<KEY, DATA>& aMap); |
|
50 void Reset(); |
|
51 TBool Next(TPair<KEY, DATA>& aPair) const; |
|
52 private: |
|
53 const RMap<KEY, DATA>& iMap; |
|
54 mutable TInt iIndex; |
|
55 }; |
|
56 |
|
57 /** |
|
58 RMap template class describes an object that controls an ordered sequence of entries. |
|
59 Each entry has a key of type KEY and an associated with it data of type DATA. |
|
60 No entries with duplicated keys are allowed. |
|
61 The algorithm for determining the order of two entries is provided by a TLinearOrder |
|
62 object, supplied by the client of RMap during RMap instance construction. |
|
63 @internalComponent |
|
64 */ |
|
65 template <class KEY, class DATA> |
|
66 class RMap |
|
67 { |
|
68 friend class TMapIterator<KEY, DATA>; |
|
69 public: |
|
70 RMap(const TLinearOrder< TPair<KEY, DATA> >& aOrder); |
|
71 void Close(); |
|
72 TInt Insert(const KEY& aKey, const DATA& aData); |
|
73 void Remove(const KEY& aKey); |
|
74 const DATA& operator[](const KEY& aKey) const; |
|
75 TInt Find(const KEY& aKey, DATA& aData) const; |
|
76 TInt Count() const; |
|
77 |
|
78 private: |
|
79 TLinearOrder< TPair<KEY, DATA> > iOrder; |
|
80 RArray< TPair<KEY, DATA> > iCol; |
|
81 |
|
82 }; |
|
83 |
|
84 #include "D32Map.inl" |
|
85 |
|
86 #endif//__D32MAP_H__ |