|
1 /* |
|
2 * Copyright (c) 1999-2002 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 #ifndef RMIDARRAY_H |
|
20 #define RMIDARRAY_H |
|
21 |
|
22 #include <e32std.h> |
|
23 |
|
24 const TInt KRMIDArrayIndexNegative=-1; |
|
25 const TInt KRMIDArrayIndexGreaterThanSize=-2; |
|
26 |
|
27 template <class T> |
|
28 class RMIDArray : public RArrayBase |
|
29 { |
|
30 public: |
|
31 inline RMIDArray(); |
|
32 inline RMIDArray(TInt aGranularity); |
|
33 inline void Close(); |
|
34 inline TInt Count() const; |
|
35 inline const T& operator[](TInt anIndex) const; |
|
36 inline T& operator[](TInt anIndex); |
|
37 inline void Remove(TInt anIndex); |
|
38 inline void Compress(); |
|
39 inline void Reset(); |
|
40 inline TInt Find(const T& anEntry) const; |
|
41 // |
|
42 void Delete(TInt aIndex); |
|
43 void DeleteAll(); |
|
44 void InsertL(const T& anEntry, TInt aPos); |
|
45 void AppendL(const T& anEntry); |
|
46 }; |
|
47 |
|
48 |
|
49 template <class T> |
|
50 inline RMIDArray<T>::RMIDArray() |
|
51 : RArrayBase(sizeof(T)) |
|
52 {} |
|
53 template <class T> |
|
54 inline RMIDArray<T>::RMIDArray(TInt aGranularity) |
|
55 : RArrayBase(sizeof(T),aGranularity) |
|
56 {} |
|
57 template <class T> |
|
58 inline void RMIDArray<T>::Close() |
|
59 { |
|
60 RArrayBase::Close(); |
|
61 } |
|
62 template <class T> |
|
63 inline TInt RMIDArray<T>::Count() const |
|
64 { |
|
65 return RArrayBase::Count(); |
|
66 } |
|
67 template <class T> |
|
68 inline const T& RMIDArray<T>::operator[](TInt anIndex) const |
|
69 { |
|
70 return *(const T*)At(anIndex); |
|
71 } |
|
72 template <class T> |
|
73 inline T& RMIDArray<T>::operator[](TInt anIndex) |
|
74 { |
|
75 return *(T*)At(anIndex); |
|
76 } |
|
77 template <class T> |
|
78 inline void RMIDArray<T>::Remove(TInt anIndex) |
|
79 { |
|
80 RArrayBase::Remove(anIndex); |
|
81 } |
|
82 template <class T> |
|
83 inline void RMIDArray<T>::Compress() |
|
84 { |
|
85 RArrayBase::Compress(); |
|
86 } |
|
87 template <class T> |
|
88 inline void RMIDArray<T>::Reset() |
|
89 { |
|
90 RArrayBase::Reset(); |
|
91 } |
|
92 template <class T> |
|
93 inline TInt RMIDArray<T>::Find(const T& anEntry) const |
|
94 { |
|
95 return RArrayBase::Find(&anEntry); |
|
96 } |
|
97 |
|
98 |
|
99 /** |
|
100 *Delete deletes the actual object and so can only be used if we are |
|
101 *storing pointers in the array |
|
102 */ |
|
103 template <class T> |
|
104 void RMIDArray<T>::Delete(TInt aIndex) |
|
105 { |
|
106 T pointer = *(T*)At(aIndex); |
|
107 Remove(aIndex); |
|
108 delete pointer; |
|
109 } |
|
110 |
|
111 template <class T> |
|
112 void RMIDArray<T>::InsertL(const T& anEntry, TInt aPos) |
|
113 { |
|
114 User::LeaveIfError(RArrayBase::Insert(&anEntry,aPos)); |
|
115 } |
|
116 |
|
117 template <class T> |
|
118 void RMIDArray<T>::AppendL(const T& anEntry) |
|
119 { |
|
120 User::LeaveIfError(RArrayBase::Append(&anEntry)); |
|
121 } |
|
122 |
|
123 /** |
|
124 *Only use this if the RMIDArray stores pointers |
|
125 */ |
|
126 template <class T> |
|
127 void RMIDArray<T>::DeleteAll() |
|
128 { |
|
129 TInt c=Count(); |
|
130 TInt i; |
|
131 for (i=c-1; i>=0; --i) |
|
132 { |
|
133 Delete(i); |
|
134 } |
|
135 Reset(); |
|
136 } |
|
137 |
|
138 #endif // RMIDARRAY_H |