00001
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <assert.h>
00015
00047
00049
00050 template <class TC>
00051 inline CTBsimpleListLink<TC>::CTBsimpleListLink()
00052 : mp_head(0),
00053 mp_prev(0),
00054 mp_next(0)
00055 {}
00056
00057
00059
00065 template <class TC>
00066 inline CTBsimpleListLink<TC>::~CTBsimpleListLink()
00067 {
00068 assert(!mp_head && !mp_prev && !mp_next);
00069 }
00070
00071
00073
00074 template <class TC>
00075 inline CTBsimpleListHead<TC>* CTBsimpleListLink<TC>::Head() const
00076 {
00077 return mp_head;
00078 }
00079
00080
00082
00083 template <class TC>
00084 inline TC* CTBsimpleListLink<TC>::Prev() const
00085 {
00086 return mp_prev;
00087 }
00088
00089
00091
00092 template <class TC>
00093 inline TC* CTBsimpleListLink<TC>::Next() const
00094 {
00095 return mp_next;
00096 }
00097
00098
00100
00116 template <class TC>
00117 inline void CTBsimpleListLink<TC>::InsertHead(TC* p_this,
00118 CTBsimpleListLink<TC> TC::* o_link,
00119 CTBsimpleListHead<TC>& head)
00120 {
00121 TC* p_first = head.mp_first;
00122
00123 assert(!mp_head && !mp_prev && !mp_next);
00124 assert(&(p_this->*o_link) == this);
00125
00126 if (p_first) {
00127 assert(!(p_first->*o_link).mp_prev);
00128 mp_next = p_first;
00129 (p_first->*o_link).mp_prev = p_this;
00130 head.mp_first = p_this;
00131
00132 } else {
00133 head.mp_first = p_this;
00134 head.mp_last = p_this;
00135 }
00136
00137 mp_head = &head;
00138 return;
00139 }
00140
00141
00143
00147 template <class TC>
00148 inline void CTBsimpleListLink<TC>::InsertTail(TC* p_this,
00149 CTBsimpleListLink<TC> TC::* o_link,
00150 CTBsimpleListHead<TC>& head)
00151 {
00152 TC* p_last = head.mp_last;
00153
00154 assert(!mp_head && !mp_prev && !mp_next);
00155 assert(&(p_this->*o_link) == this);
00156
00157 if (p_last) {
00158 assert(!(p_last->*o_link).mp_next);
00159 mp_prev = p_last;
00160 (p_last->*o_link).mp_next = p_this;
00161 head.mp_last = p_this;
00162
00163 } else {
00164 head.mp_first = p_this;
00165 head.mp_last = p_this;
00166 }
00167
00168 mp_head = &head;
00169 return;
00170 }
00171
00172
00174
00183 template <class TC>
00184 inline void CTBsimpleListLink<TC>::InsertBefore(TC* p_this,
00185 CTBsimpleListLink<TC> TC::* o_link,
00186 TC& elem)
00187 {
00188 TC* p_prev = (elem.*o_link).mp_prev;
00189
00190 assert(!mp_head && !mp_prev && !mp_next);
00191 assert(&(p_this->*o_link) == this);
00192 assert((elem.*o_link).mp_head);
00193
00194 if (p_prev) {
00195 assert((p_prev->*o_link).mp_next = &elem);
00196 mp_prev = p_prev;
00197 mp_next = &elem;
00198 (p_prev->*o_link).mp_next = p_this;
00199 (elem.*o_link).mp_prev = p_this;
00200
00201 } else{
00202 assert((elem.*o_link).mp_head->mp_first == &elem);
00203 mp_next = &elem;
00204 (elem.*o_link).mp_head->mp_first = p_this;
00205 (elem.*o_link).mp_prev = p_this;
00206 }
00207
00208 mp_head = (elem.*o_link).mp_head;
00209 return;
00210 }
00211
00212
00214
00218 template <class TC>
00219 inline void CTBsimpleListLink<TC>::InsertAfter(TC* p_this,
00220 CTBsimpleListLink<TC> TC::* o_link,
00221 TC& elem)
00222 {
00223 TC* p_next = (elem.*o_link).mp_next;
00224
00225 assert(!mp_head && !mp_prev && !mp_next);
00226 assert(&(p_this->*o_link) == this);
00227 assert((elem.*o_link).mp_head);
00228
00229 if (p_next) {
00230 assert((p_next->*o_link).mp_prev = &elem);
00231 mp_prev = &elem;
00232 mp_next = p_next;
00233 (elem.*o_link).mp_next = p_this;
00234 (p_next->*o_link).mp_prev = p_this;
00235
00236 } else{
00237 assert((elem.*o_link).mp_head->mp_last == &elem);
00238 mp_prev = &elem;
00239 (elem.*o_link).mp_next = p_this;
00240 (elem.*o_link).mp_head->mp_last = p_this;
00241 }
00242
00243 mp_head = (elem.*o_link).mp_head;
00244 return;
00245 }
00246
00247
00249
00250 template <class TC>
00251 inline bool CTBsimpleListLink<TC>::operator! () const
00252 {
00253 return !mp_head;
00254 }
00255
00256
00258
00259 template <class TC>
00260 inline CTBsimpleListLink<TC>::operator bool() const
00261 {
00262 return mp_head;
00263 }
00264
00265
00267
00274 template <class TC>
00275 inline void CTBsimpleListLink<TC>::Remove(CTBsimpleListLink<TC> TC::* o_link)
00276 {
00277 assert(mp_head);
00278
00279 if (mp_prev) {
00280 assert(&((mp_prev->*o_link).mp_next->*o_link) == this);
00281 (mp_prev->*o_link).mp_next = mp_next;
00282 } else {
00283 assert(&(mp_head->mp_first->*o_link) == this);
00284 mp_head->mp_first = mp_next;
00285 }
00286
00287 if (mp_next) {
00288 assert(&((mp_next->*o_link).mp_prev->*o_link) == this);
00289 (mp_next->*o_link).mp_prev = mp_prev;
00290 } else {
00291 assert(&(mp_head->mp_last->*o_link) == this);
00292 mp_head->mp_last = mp_prev;
00293 }
00294
00295 mp_head = 0;
00296 mp_prev = 0;
00297 mp_next = 0;
00298
00299 return;
00300 }
00301
00302
00311
00313
00314 template <class TC>
00315 inline CTBsimpleListHead<TC>::CTBsimpleListHead()
00316 : mp_first(0),
00317 mp_last(0)
00318 {}
00319
00320
00322
00348 template <class TC>
00349 inline CTBsimpleListHead<TC>::~CTBsimpleListHead()
00350 {
00351 assert(!mp_first && !mp_last);
00352 }
00353
00354
00356
00363 template <class TC>
00364 inline TC* CTBsimpleListHead<TC>::First() const
00365 {
00366 return mp_first;
00367 }
00368
00369
00371
00378 template <class TC>
00379 inline TC* CTBsimpleListHead<TC>::Last() const
00380 {
00381 return mp_last;
00382 }
00383
00384
00386
00387 template <class TC>
00388 inline bool CTBsimpleListHead<TC>::operator! () const
00389 {
00390 return !mp_first;
00391 }
00392
00393
00395
00396 template <class TC>
00397 inline CTBsimpleListHead<TC>::operator bool() const
00398 {
00399 return mp_first;
00400 }