00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef LList_H
00038 #define LList_H
00039
00040 #include "label.H"
00041
00042
00043
00044 namespace Foam
00045 {
00046
00047 class Istream;
00048 class Ostream;
00049
00050
00051
00052 template<class LListBase, class T> class LList;
00053
00054 template<class LListBase, class T>
00055 Istream& operator>>
00056 (
00057 Istream&,
00058 LList<LListBase, T>&
00059 );
00060
00061 template<class LListBase, class T>
00062 Ostream& operator<<
00063 (
00064 Ostream&,
00065 const LList<LListBase, T>&
00066 );
00067
00068
00069
00070
00071
00072
00073 template<class LListBase, class T>
00074 class LList
00075 :
00076 public LListBase
00077 {
00078
00079 public:
00080
00081
00082
00083 class iterator;
00084 friend class iterator;
00085
00086 class const_iterator;
00087 friend class const_iterator;
00088
00089
00090
00091 struct link
00092 :
00093 public LListBase::link
00094 {
00095
00096 T obj_;
00097
00098
00099 link(T a)
00100 :
00101 obj_(a)
00102 {}
00103 };
00104
00105
00106
00107
00108
00109 LList()
00110 {}
00111
00112
00113 LList(T a)
00114 :
00115 LListBase(new link(a))
00116 {}
00117
00118
00119 LList(Istream&);
00120
00121
00122 LList(const LList<LListBase, T>&);
00123
00124
00125
00126
00127 ~LList();
00128
00129
00130
00131
00132
00133
00134
00135 T& first()
00136 {
00137 return static_cast<link*>(LListBase::first())->obj_;
00138 }
00139
00140
00141 const T& first() const
00142 {
00143 return static_cast<const link*>(LListBase::first())->obj_;
00144 }
00145
00146
00147 T& last()
00148 {
00149 return static_cast<link*>(LListBase::last())->obj_;
00150 }
00151
00152
00153 const T& last() const
00154 {
00155 return static_cast<const link*>(LListBase::last())->obj_;
00156 }
00157
00158
00159
00160
00161
00162 void insert(const T& a)
00163 {
00164 LListBase::insert(new link(a));
00165 }
00166
00167
00168 void append(const T& a)
00169 {
00170 LListBase::append(new link(a));
00171 }
00172
00173
00174 T removeHead()
00175 {
00176 link* elmtPtr = static_cast<link*>(LListBase::removeHead());
00177 T data = elmtPtr->obj_;
00178 delete elmtPtr;
00179 return data;
00180 }
00181
00182
00183 T remove(link* l)
00184 {
00185 link* elmtPtr = static_cast<link*>(LListBase::remove(l));
00186 T data = elmtPtr->obj_;
00187 delete elmtPtr;
00188 return data;
00189 }
00190
00191
00192 T remove(iterator& it)
00193 {
00194 link* elmtPtr = static_cast<link*>(LListBase::remove(it));
00195 T data = elmtPtr->obj_;
00196 delete elmtPtr;
00197 return data;
00198 }
00199
00200
00201 void clear();
00202
00203
00204
00205
00206 void operator=(const LList<LListBase, T>&);
00207
00208
00209
00210
00211
00212 typedef T value_type;
00213
00214
00215
00216 typedef T& reference;
00217
00218
00219
00220 typedef const T& const_reference;
00221
00222
00223 typedef label size_type;
00224
00225
00226
00227
00228 typedef typename LListBase::iterator LListBase_iterator;
00229
00230 class iterator
00231 :
00232 public LListBase_iterator
00233 {
00234
00235 public:
00236
00237
00238 iterator
00239 (
00240 LListBase_iterator baseIter
00241 )
00242 :
00243 LListBase_iterator(baseIter)
00244 {}
00245
00246
00247
00248
00249 T& operator*()
00250 {
00251 return
00252 static_cast<link&>
00253 (LListBase_iterator::operator*()).obj_;
00254 }
00255
00256 T& operator()()
00257 {
00258 return operator*();
00259 }
00260
00261 iterator& operator++()
00262 {
00263 LListBase_iterator::operator++();
00264 return *this;
00265 }
00266 };
00267
00268
00269
00270
00271 typedef typename LListBase::const_iterator LListBase_const_iterator;
00272
00273 class const_iterator
00274 :
00275 public LListBase_const_iterator
00276 {
00277
00278 public:
00279
00280
00281 const_iterator
00282 (
00283 LListBase_const_iterator baseIter
00284 )
00285 :
00286 LListBase_const_iterator(baseIter)
00287 {}
00288
00289
00290
00291 const_iterator
00292 (
00293 LListBase_iterator baseIter
00294 )
00295 :
00296 LListBase_const_iterator(baseIter)
00297 {}
00298
00299
00300
00301
00302 const T& operator*()
00303 {
00304 return
00305 static_cast<const link&>
00306 (LListBase_const_iterator::operator*()).obj_;
00307 }
00308
00309 const T& operator()()
00310 {
00311 return operator*();
00312 }
00313
00314 const_iterator& operator++()
00315 {
00316 LListBase_const_iterator::operator++();
00317 return *this;
00318 }
00319 };
00320
00321
00322
00323
00324 friend Istream& operator>> <LListBase, T>
00325 (
00326 Istream&,
00327 LList<LListBase, T>&
00328 );
00329
00330 friend Ostream& operator<< <LListBase, T>
00331 (
00332 Ostream&,
00333 const LList<LListBase, T>&
00334 );
00335 };
00336
00337
00338
00339
00340 }
00341
00342
00343
00344 #ifdef NoRepository
00345 # include "LList.C"
00346 #endif
00347
00348
00349
00350 #endif
00351
00352
Copyright © 2000-2007 OpenCFD Ltd