|
1 /* |
|
2 * Copyright (c) 1997-2009 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 * Header LST.H |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __LST_H__ |
|
21 #define __LST_H__ |
|
22 |
|
23 template <class T> |
|
24 class Link |
|
25 /** |
|
26 @publishedAll |
|
27 WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases. |
|
28 */ |
|
29 { |
|
30 public: |
|
31 inline Link(); |
|
32 inline Link(T aT); |
|
33 public: |
|
34 Link* iNext; |
|
35 T iT; |
|
36 }; |
|
37 |
|
38 template <class T> |
|
39 class List |
|
40 /** |
|
41 @publishedAll |
|
42 WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases. |
|
43 */ |
|
44 { |
|
45 public: |
|
46 inline List(); |
|
47 inline int Size() const; |
|
48 inline T& operator [] (const int aNum) const; |
|
49 inline void Add(T aT); |
|
50 virtual void Externalize(ostream& out) = 0; |
|
51 inline void Destroy(); |
|
52 inline ~List(); |
|
53 private: |
|
54 Link<T> *iFirst; |
|
55 }; |
|
56 |
|
57 template <class T> |
|
58 class ObjectList : public List<T> |
|
59 /** |
|
60 List of object pointers |
|
61 @publishedAll |
|
62 WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases. |
|
63 */ |
|
64 { |
|
65 public: |
|
66 inline virtual void Externalize(ostream& out); |
|
67 inline void Destroy(); |
|
68 }; |
|
69 |
|
70 template <class T> inline Link<T>::Link() |
|
71 { |
|
72 iNext = NULL; |
|
73 } |
|
74 |
|
75 template <class T> inline Link<T>::Link(T aT) |
|
76 { |
|
77 iT = aT; |
|
78 iNext = NULL; |
|
79 } |
|
80 |
|
81 template <class T> inline List<T>::List() |
|
82 { |
|
83 iFirst = NULL; |
|
84 } |
|
85 |
|
86 template <class T> inline int List<T>::Size() const |
|
87 { |
|
88 int size = 0; |
|
89 Link<T>* link = iFirst; |
|
90 while (link != NULL) |
|
91 { |
|
92 link = link->iNext; |
|
93 size++; |
|
94 } |
|
95 return size; |
|
96 } |
|
97 |
|
98 template <class T> inline T& List<T>::operator [] (const int aNum) const |
|
99 { |
|
100 int num = 0; |
|
101 Link<T>* link = iFirst; |
|
102 while (num != aNum) |
|
103 { |
|
104 link = link->iNext; |
|
105 num++; |
|
106 } |
|
107 return link->iT; |
|
108 } |
|
109 |
|
110 template <class T> inline void List<T>::Add(T aT) |
|
111 { |
|
112 Link<T>* link; |
|
113 if (iFirst == NULL) |
|
114 iFirst = new Link<T>(aT); |
|
115 else |
|
116 { |
|
117 link = iFirst; |
|
118 while (link->iNext != NULL) |
|
119 link = link->iNext; |
|
120 link->iNext = new Link<T>(aT); |
|
121 } |
|
122 } |
|
123 |
|
124 template <class T> inline void List<T>::Destroy() |
|
125 { |
|
126 Link<T>* link = iFirst; |
|
127 Link<T>* next; |
|
128 while (link != NULL) |
|
129 { |
|
130 next = link->iNext; |
|
131 delete link; |
|
132 link = next; |
|
133 } |
|
134 iFirst = NULL; |
|
135 } |
|
136 |
|
137 template <class T> inline List<T>::~List (void) |
|
138 { |
|
139 Destroy(); |
|
140 } |
|
141 |
|
142 template <class T> inline void ObjectList<T>::Externalize(ostream& out) |
|
143 { |
|
144 int32 size = List<T>::Size(); |
|
145 int32 i; |
|
146 out.write ((char*) &size, sizeof(size)); |
|
147 for (i = 0; i < size; i++) |
|
148 (*this)[i]->Externalize(out); |
|
149 } |
|
150 |
|
151 template <class T> inline void ObjectList<T>::Destroy() |
|
152 { |
|
153 int size = List<T>::Size(); |
|
154 int i; |
|
155 for (i = 0; i < size; i++) |
|
156 delete (*this)[i]; |
|
157 List<T>::Destroy(); |
|
158 } |
|
159 |
|
160 #endif |