Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBsimpleList.icc

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Planckstrasse 1, D-64291 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
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); // !?! must be disconnected
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); // !?! must be disconnected
00124   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00125 
00126   if (p_first) {                            // list not empty
00127     assert(!(p_first->*o_link).mp_prev);    // !?! no prev in first element
00128     mp_next = p_first;
00129     (p_first->*o_link).mp_prev = p_this;
00130     head.mp_first = p_this;
00131     
00132   } else {                                  // list was empty
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); // !?! must be disconnected
00155   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00156 
00157   if (p_last) {                             // list not empty
00158     assert(!(p_last->*o_link).mp_next);     // !?! no prev in last element
00159     mp_prev = p_last;
00160     (p_last->*o_link).mp_next = p_this;
00161     head.mp_last = p_this;
00162     
00163   } else {                                  // list was empty
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); // !?! must be disconnected
00191   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00192   assert((elem.*o_link).mp_head);           // !?! elem must be connected
00193 
00194   if (p_prev) {
00195     assert((p_prev->*o_link).mp_next = &elem); // !?! next link in prev o.k.
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); // !?! really first
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); // !?! must be disconnected
00226   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00227   assert((elem.*o_link).mp_head);           // !?! elem must be connected
00228 
00229   if (p_next) {
00230     assert((p_next->*o_link).mp_prev = &elem); // !?! prev link in next o.k.
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); // !?! really last
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);                          // !?! must be connected
00278  
00279   if (mp_prev) {
00280     assert(&((mp_prev->*o_link).mp_next->*o_link) == this); // !?! prev <-> next
00281     (mp_prev->*o_link).mp_next = mp_next;
00282   } else {
00283     assert(&(mp_head->mp_first->*o_link) == this); // !?! really first
00284     mp_head->mp_first = mp_next;
00285   }
00286   
00287   if (mp_next) {
00288     assert(&((mp_next->*o_link).mp_prev->*o_link) == this); // !?! next <-> prev
00289     (mp_next->*o_link).mp_prev = mp_prev;
00290   } else {
00291     assert(&(mp_head->mp_last->*o_link) == this);  // !?! really last
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);            // !?! list must be empty
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 }

Generated at Fri Oct 24 18:11:30 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001