author | sl |
Tue, 10 Jun 2014 14:32:02 +0200 | |
changeset 1 | 260cb5ec6c19 |
permissions | -rw-r--r-- |
sl@0 | 1 |
/* |
sl@0 | 2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 3 |
* All rights reserved. |
sl@0 | 4 |
* This component and the accompanying materials are made available |
sl@0 | 5 |
* under the terms of "Eclipse Public License v1.0" |
sl@0 | 6 |
* which accompanies this distribution, and is available |
sl@0 | 7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 8 |
* |
sl@0 | 9 |
* Initial Contributors: |
sl@0 | 10 |
* Nokia Corporation - initial contribution. |
sl@0 | 11 |
* |
sl@0 | 12 |
* Contributors: |
sl@0 | 13 |
* |
sl@0 | 14 |
* Description: |
sl@0 | 15 |
* Header LST.H |
sl@0 | 16 |
* |
sl@0 | 17 |
*/ |
sl@0 | 18 |
|
sl@0 | 19 |
|
sl@0 | 20 |
#ifndef __LST_H__ |
sl@0 | 21 |
#define __LST_H__ |
sl@0 | 22 |
|
sl@0 | 23 |
template <class T> |
sl@0 | 24 |
class Link |
sl@0 | 25 |
/** |
sl@0 | 26 |
@publishedAll |
sl@0 | 27 |
WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases. |
sl@0 | 28 |
*/ |
sl@0 | 29 |
{ |
sl@0 | 30 |
public: |
sl@0 | 31 |
inline Link(); |
sl@0 | 32 |
inline Link(T aT); |
sl@0 | 33 |
public: |
sl@0 | 34 |
Link* iNext; |
sl@0 | 35 |
T iT; |
sl@0 | 36 |
}; |
sl@0 | 37 |
|
sl@0 | 38 |
template <class T> |
sl@0 | 39 |
class List |
sl@0 | 40 |
/** |
sl@0 | 41 |
@publishedAll |
sl@0 | 42 |
WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases. |
sl@0 | 43 |
*/ |
sl@0 | 44 |
{ |
sl@0 | 45 |
public: |
sl@0 | 46 |
inline List(); |
sl@0 | 47 |
inline int Size() const; |
sl@0 | 48 |
inline T& operator [] (const int aNum) const; |
sl@0 | 49 |
inline void Add(T aT); |
sl@0 | 50 |
virtual void Externalize(ostream& out) = 0; |
sl@0 | 51 |
inline void Destroy(); |
sl@0 | 52 |
inline ~List(); |
sl@0 | 53 |
private: |
sl@0 | 54 |
Link<T> *iFirst; |
sl@0 | 55 |
}; |
sl@0 | 56 |
|
sl@0 | 57 |
template <class T> |
sl@0 | 58 |
class ObjectList : public List<T> |
sl@0 | 59 |
/** |
sl@0 | 60 |
List of object pointers |
sl@0 | 61 |
@publishedAll |
sl@0 | 62 |
WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases. |
sl@0 | 63 |
*/ |
sl@0 | 64 |
{ |
sl@0 | 65 |
public: |
sl@0 | 66 |
inline virtual void Externalize(ostream& out); |
sl@0 | 67 |
inline void Destroy(); |
sl@0 | 68 |
}; |
sl@0 | 69 |
|
sl@0 | 70 |
template <class T> inline Link<T>::Link() |
sl@0 | 71 |
{ |
sl@0 | 72 |
iNext = NULL; |
sl@0 | 73 |
} |
sl@0 | 74 |
|
sl@0 | 75 |
template <class T> inline Link<T>::Link(T aT) |
sl@0 | 76 |
{ |
sl@0 | 77 |
iT = aT; |
sl@0 | 78 |
iNext = NULL; |
sl@0 | 79 |
} |
sl@0 | 80 |
|
sl@0 | 81 |
template <class T> inline List<T>::List() |
sl@0 | 82 |
{ |
sl@0 | 83 |
iFirst = NULL; |
sl@0 | 84 |
} |
sl@0 | 85 |
|
sl@0 | 86 |
template <class T> inline int List<T>::Size() const |
sl@0 | 87 |
{ |
sl@0 | 88 |
int size = 0; |
sl@0 | 89 |
Link<T>* link = iFirst; |
sl@0 | 90 |
while (link != NULL) |
sl@0 | 91 |
{ |
sl@0 | 92 |
link = link->iNext; |
sl@0 | 93 |
size++; |
sl@0 | 94 |
} |
sl@0 | 95 |
return size; |
sl@0 | 96 |
} |
sl@0 | 97 |
|
sl@0 | 98 |
template <class T> inline T& List<T>::operator [] (const int aNum) const |
sl@0 | 99 |
{ |
sl@0 | 100 |
int num = 0; |
sl@0 | 101 |
Link<T>* link = iFirst; |
sl@0 | 102 |
while (num != aNum) |
sl@0 | 103 |
{ |
sl@0 | 104 |
link = link->iNext; |
sl@0 | 105 |
num++; |
sl@0 | 106 |
} |
sl@0 | 107 |
return link->iT; |
sl@0 | 108 |
} |
sl@0 | 109 |
|
sl@0 | 110 |
template <class T> inline void List<T>::Add(T aT) |
sl@0 | 111 |
{ |
sl@0 | 112 |
Link<T>* link; |
sl@0 | 113 |
if (iFirst == NULL) |
sl@0 | 114 |
iFirst = new Link<T>(aT); |
sl@0 | 115 |
else |
sl@0 | 116 |
{ |
sl@0 | 117 |
link = iFirst; |
sl@0 | 118 |
while (link->iNext != NULL) |
sl@0 | 119 |
link = link->iNext; |
sl@0 | 120 |
link->iNext = new Link<T>(aT); |
sl@0 | 121 |
} |
sl@0 | 122 |
} |
sl@0 | 123 |
|
sl@0 | 124 |
template <class T> inline void List<T>::Destroy() |
sl@0 | 125 |
{ |
sl@0 | 126 |
Link<T>* link = iFirst; |
sl@0 | 127 |
Link<T>* next; |
sl@0 | 128 |
while (link != NULL) |
sl@0 | 129 |
{ |
sl@0 | 130 |
next = link->iNext; |
sl@0 | 131 |
delete link; |
sl@0 | 132 |
link = next; |
sl@0 | 133 |
} |
sl@0 | 134 |
iFirst = NULL; |
sl@0 | 135 |
} |
sl@0 | 136 |
|
sl@0 | 137 |
template <class T> inline List<T>::~List (void) |
sl@0 | 138 |
{ |
sl@0 | 139 |
Destroy(); |
sl@0 | 140 |
} |
sl@0 | 141 |
|
sl@0 | 142 |
template <class T> inline void ObjectList<T>::Externalize(ostream& out) |
sl@0 | 143 |
{ |
sl@0 | 144 |
int32 size = List<T>::Size(); |
sl@0 | 145 |
int32 i; |
sl@0 | 146 |
out.write ((char*) &size, sizeof(size)); |
sl@0 | 147 |
for (i = 0; i < size; i++) |
sl@0 | 148 |
(*this)[i]->Externalize(out); |
sl@0 | 149 |
} |
sl@0 | 150 |
|
sl@0 | 151 |
template <class T> inline void ObjectList<T>::Destroy() |
sl@0 | 152 |
{ |
sl@0 | 153 |
int size = List<T>::Size(); |
sl@0 | 154 |
int i; |
sl@0 | 155 |
for (i = 0; i < size; i++) |
sl@0 | 156 |
delete (*this)[i]; |
sl@0 | 157 |
List<T>::Destroy(); |
sl@0 | 158 |
} |
sl@0 | 159 |
|
sl@0 | 160 |
#endif |