|
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 // RSqlMap template class declaration. |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef __SQLMAP_H__ |
|
19 #define __SQLMAP_H__ |
|
20 |
|
21 #include "SqlPanic.h" |
|
22 |
|
23 //Forward declaration |
|
24 template <class KEY, class DATA, class REFCNTR, class DESTRUCTOR> class RSqlMap; |
|
25 |
|
26 /** |
|
27 (KEY, DATA, REFCNTR) template pair class used by RSqlMap template class. |
|
28 |
|
29 The class has 3 template arguments: |
|
30 - KEY - the key part of the pair object; |
|
31 - DATA - the data part of the pair object; |
|
32 - REFCNTR - the reference counting part of the pair object; |
|
33 REFCNTR class has to provide "TInt Increment()" and "TInt Decrement()" methods. |
|
34 |
|
35 @see TSqlMapIterator |
|
36 @see RSqlMap |
|
37 |
|
38 @internalComponent |
|
39 */ |
|
40 template <class KEY, class DATA, class REFCNTR> |
|
41 NONSHARABLE_STRUCT(TSqlPair) |
|
42 { |
|
43 TSqlPair(const KEY& aKey, const DATA& aData); |
|
44 TSqlPair(const KEY& aKey); |
|
45 TSqlPair(); |
|
46 |
|
47 KEY iKey; |
|
48 DATA iData; |
|
49 REFCNTR iRefCounter; |
|
50 |
|
51 }; |
|
52 |
|
53 /** |
|
54 TSqlMapIterator class. It describes an object which can be used as a |
|
55 forward, read-only iterator for RSqlMap containers. |
|
56 |
|
57 The class has 4 template arguments: |
|
58 - KEY - the key part of the pair object; |
|
59 - DATA - the data part of the pair object; |
|
60 - REFCNTR - the reference counting part of the pair object; |
|
61 REFCNTR class has to provide "TInt Increment()" and "TInt Decrement()" methods. |
|
62 - DESTRUCTOR - the KEY and DATA objects destroying part of the pair object; |
|
63 DESTRUCTOR class has to provide "void Destroy(KEY& aKey, DATA& aData)" method. |
|
64 |
|
65 @see TSqlPair |
|
66 @see RSqlMap |
|
67 |
|
68 @internalComponent |
|
69 */ |
|
70 template <class KEY, class DATA, class REFCNTR, class DESTRUCTOR> |
|
71 NONSHARABLE_CLASS(TSqlMapIterator) |
|
72 { |
|
73 public: |
|
74 TSqlMapIterator(const RSqlMap<KEY, DATA, REFCNTR, DESTRUCTOR>& aMap); |
|
75 TBool Next(TSqlPair<KEY, DATA, REFCNTR>& aPair) const; |
|
76 |
|
77 private: |
|
78 const RSqlMap<KEY, DATA, REFCNTR, DESTRUCTOR>& iMap; |
|
79 mutable TInt iIndex; |
|
80 |
|
81 }; |
|
82 |
|
83 /** |
|
84 RSqlMap template class describes an object that controls an ordered sequence of reference counted entries. |
|
85 Each entry has a key of type KEY and an associated with it data of type DATA. |
|
86 |
|
87 The class has 4 template arguments: |
|
88 - KEY - the key part of the pair object; |
|
89 - DATA - the data part of the pair object; |
|
90 - REFCNTR - the reference counting part of the pair object; |
|
91 REFCNTR class has to provide "TInt Increment()" and "TInt Decrement()" methods. |
|
92 - DESTRUCTOR - the KEY and DATA objects destroying part of the pair object; |
|
93 DESTRUCTOR class has to provide "void Destroy(KEY& aKey, DATA& aData)" method. |
|
94 |
|
95 The algorithm for determining the order of two entries is provided by a TLinearOrder |
|
96 object, supplied by the client of RSqlMap during RSqlMap instance construction |
|
97 (RSqlMap constructor, aOrder argument). |
|
98 |
|
99 @see TSqlPair |
|
100 @see TSqlMapIterator |
|
101 |
|
102 @internalComponent |
|
103 */ |
|
104 template <class KEY, class DATA, class REFCNTR, class DESTRUCTOR> |
|
105 NONSHARABLE_CLASS(RSqlMap) |
|
106 { |
|
107 friend class TSqlMapIterator<KEY, DATA, REFCNTR, DESTRUCTOR>; |
|
108 |
|
109 public: |
|
110 RSqlMap(const TLinearOrder< TSqlPair<KEY, DATA, REFCNTR> >& aOrder, const DESTRUCTOR& aDestructor); |
|
111 void Close(); |
|
112 TInt Insert(const KEY& aKey, const DATA& aData); |
|
113 void Remove(const KEY& aKey); |
|
114 TSqlPair<KEY, DATA, REFCNTR>* Entry(const KEY& aKey); |
|
115 |
|
116 private: |
|
117 TLinearOrder< TSqlPair<KEY, DATA, REFCNTR> > iOrder; |
|
118 RArray< TSqlPair<KEY, DATA, REFCNTR> > iSet; |
|
119 DESTRUCTOR iDestructor; |
|
120 |
|
121 }; |
|
122 |
|
123 #include "SqlMap.inl" |
|
124 |
|
125 #endif//__SQLMAP_H__ |