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

CTBbasicList.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 
00050 //------------------------------------------+-----------------------------------
00052 
00053 template <class TC>
00054 inline CTBbasicListLink<TC>::CTBbasicListLink()
00055   : mp_prev(0),
00056     mp_next(0)
00057 {}
00058 
00059 //------------------------------------------+-----------------------------------
00061 
00067 template <class TC>
00068 inline CTBbasicListLink<TC>::~CTBbasicListLink()
00069 {
00070   assert(!mp_prev && !mp_next);             // !?! must be disconnected
00071 }
00072 
00073 //------------------------------------------+-----------------------------------
00075 
00076 template <class TC>
00077 inline TC* CTBbasicListLink<TC>::Prev() const
00078 {
00079   return mp_prev;
00080 }
00081 
00082 //------------------------------------------+-----------------------------------
00084 
00085 template <class TC>
00086 inline TC* CTBbasicListLink<TC>::Next() const
00087 {
00088   return mp_next;
00089 }
00090 
00091 //------------------------------------------+-----------------------------------
00093 
00109 template <class TC>
00110 inline void CTBbasicListLink<TC>::InsertHead(TC* p_this,
00111                                              CTBbasicListLink<TC> TC::* o_link,
00112                                              CTBbasicListHead<TC>& head)
00113 {
00114   TC* p_first = head.mp_first;
00115   
00116   assert(!mp_prev && !mp_next);             // !?! must be disconnected
00117   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00118 
00119   if (p_first) {                            // list not empty
00120     assert(!(p_first->*o_link).mp_prev);    // !?! no prev in first element
00121     mp_next = p_first;
00122     (p_first->*o_link).mp_prev = p_this;
00123     head.mp_first = p_this;
00124     
00125   } else {                                  // list was empty
00126     head.mp_first = p_this;
00127     head.mp_last  = p_this;
00128   }
00129   
00130   return;
00131 }
00132 
00133 //------------------------------------------+-----------------------------------
00135 
00139 template <class TC>
00140 inline void CTBbasicListLink<TC>::InsertTail(TC* p_this,
00141                                              CTBbasicListLink<TC> TC::* o_link,
00142                                              CTBbasicListHead<TC>& head)
00143 {
00144   TC* p_last = head.mp_last;
00145   
00146   assert(!mp_prev && !mp_next);             // !?! must be disconnected
00147   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00148 
00149   if (p_last) {                             // list not empty
00150     assert(!(p_last->*o_link).mp_next);     // !?! no prev in last element
00151     mp_prev = p_last;
00152     (p_last->*o_link).mp_next = p_this;
00153     head.mp_last = p_this;
00154     
00155   } else {                                  // list was empty
00156     head.mp_first = p_this;
00157     head.mp_last  = p_this;
00158   }
00159   
00160   return;
00161 }
00162 
00163 //------------------------------------------+-----------------------------------
00165 
00176 template <class TC>
00177 inline void CTBbasicListLink<TC>::InsertBefore(TC* p_this,
00178     CTBbasicListLink<TC> TC::* o_link,
00179     CTBbasicListHead<TC>& head,
00180     TC& elem)
00181 {
00182   TC* p_prev = (elem.*o_link).mp_prev;  
00183 
00184   assert(!mp_prev && !mp_next);             // !?! must be disconnected
00185   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00186 
00187   if (p_prev) {
00188     assert((p_prev->*o_link).mp_next = &elem); // !?! next link in prev o.k.
00189     mp_prev = p_prev;
00190     mp_next = &elem;
00191     (p_prev->*o_link).mp_next = p_this;
00192     (elem.*o_link).mp_prev      = p_this;    
00193 
00194   } else{
00195     assert(head.mp_first == &elem);         // !?! check if elem really first
00196     mp_next = &elem;
00197     head.mp_first          = p_this;
00198     (elem.*o_link).mp_prev = p_this;
00199   }
00200 
00201   return;
00202 }
00203 
00204 //------------------------------------------+-----------------------------------
00206 
00210 template <class TC>
00211 inline void CTBbasicListLink<TC>::InsertAfter(TC* p_this,
00212     CTBbasicListLink<TC> TC::* o_link,
00213     CTBbasicListHead<TC>& head,
00214     TC& elem)
00215 {
00216   TC* p_next = (elem.*o_link).mp_next;  
00217 
00218   assert(!mp_prev && !mp_next);             // !?! must be disconnected
00219   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00220 
00221   if (p_next) {
00222     assert((p_next->*o_link).mp_prev = &elem); // !?! prev link in next o.k.
00223     mp_prev = &elem;
00224     mp_next = p_next;
00225     (elem.*o_link).mp_next    = p_this;
00226     (p_next->*o_link).mp_prev = p_this;
00227     
00228   } else{
00229     assert(head.mp_last == &elem);          // !?! check if elem really last
00230     mp_prev = &elem;
00231     (elem.*o_link).mp_next = p_this;
00232     head.mp_last           = p_this;
00233   }
00234 
00235   return;
00236 }
00237 
00238 //------------------------------------------+-----------------------------------
00240 
00247 template <class TC>
00248 inline void CTBbasicListLink<TC>::Remove(CTBbasicListLink<TC> TC::* o_link,
00249                                          CTBbasicListHead<TC>& head)
00250 {
00251   if (mp_prev) {
00252     assert(&((mp_prev->*o_link).mp_next->*o_link) == this); // !?! prev <-> next
00253     (mp_prev->*o_link).mp_next = mp_next;
00254   } else {
00255     assert(&(head.mp_first->*o_link) == this); // !?! really first
00256     head.mp_first = mp_next;
00257   }
00258   
00259   if (mp_next) {
00260     assert(&((mp_next->*o_link).mp_prev->*o_link) == this); // !?! next <-> prev
00261     (mp_next->*o_link).mp_prev = mp_prev;
00262   } else {
00263     assert(&(head.mp_last->*o_link) == this);  // !?! really last
00264     head.mp_last = mp_prev;
00265   }
00266   
00267   mp_prev = 0;
00268   mp_next = 0;  
00269 
00270   return;
00271 }
00272 
00273 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00282 //------------------------------------------+-----------------------------------
00284 
00285 template <class TC>
00286 inline CTBbasicListHead<TC>::CTBbasicListHead()
00287   : mp_first(0),
00288     mp_last(0)
00289 {}
00290 
00291 //------------------------------------------+-----------------------------------
00293 
00319 template <class TC>
00320 inline CTBbasicListHead<TC>::~CTBbasicListHead()
00321 {
00322   assert(!mp_first && !mp_last);            // !?! list must be empty
00323 }
00324 
00325 //------------------------------------------+-----------------------------------
00327 
00334 template <class TC>
00335 inline TC* CTBbasicListHead<TC>::First() const
00336 {
00337   return mp_first;
00338 }
00339 
00340 //------------------------------------------+-----------------------------------
00342 
00349 template <class TC>
00350 inline TC* CTBbasicListHead<TC>::Last() const
00351 {
00352   return mp_last;
00353 }
00354 
00355 //------------------------------------------+-----------------------------------
00357 
00358 template <class TC>
00359 inline bool CTBbasicListHead<TC>::operator! () const
00360 {
00361   return !mp_first;
00362 }
00363 
00364 //------------------------------------------+-----------------------------------
00366 
00367 template <class TC>
00368 inline CTBbasicListHead<TC>::operator bool() const
00369 {
00370   return mp_first;
00371 }

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