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

CTBtreeList.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 TP, class TC>
00051 inline CTBtreeListLink<TP,TC>::CTBtreeListLink()
00052   : mp_parent(0),
00053     mp_prev(0),
00054     mp_next(0)
00055 {}
00056 
00057 //------------------------------------------+-----------------------------------
00059 
00065 template <class TP, class TC>
00066 inline CTBtreeListLink<TP,TC>::~CTBtreeListLink()
00067 {
00068   assert(!mp_parent && !mp_prev && !mp_next); // !?! must be disconnected
00069 }
00070 
00071 //------------------------------------------+-----------------------------------
00073 
00074 template <class TP, class TC>
00075 inline TP* CTBtreeListLink<TP,TC>::Parent() const
00076 {
00077   return mp_parent;
00078 }
00079 
00080 //------------------------------------------+-----------------------------------
00082 
00083 template <class TP, class TC>
00084 inline TC* CTBtreeListLink<TP,TC>::Prev() const
00085 {
00086   return mp_prev;
00087 }
00088 
00089 //------------------------------------------+-----------------------------------
00091 
00092 template <class TP, class TC>
00093 inline TC* CTBtreeListLink<TP,TC>::Next() const
00094 {
00095   return mp_next;
00096 }
00097 
00098 //------------------------------------------+-----------------------------------
00100 
00116 template <class TP, class TC>
00117 inline void CTBtreeListLink<TP,TC>::InsertHead(TC* p_this,
00118     CTBtreeListLink<TP,TC> TC::* o_link,
00119     TP& parent,
00120     CTBtreeListHead<TP,TC> TP::* o_head)
00121 {
00122   CTBtreeListHead<TP,TC>& head = parent.*o_head;
00123   TC* p_first = head.mp_first;
00124   
00125   assert(!mp_parent && !mp_prev && !mp_next); // !?! must be disconnected
00126   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00127 
00128   if (p_first) {                            // list not empty
00129     assert(!(p_first->*o_link).mp_prev);    // !?! no prev in first element
00130     mp_next = p_first;
00131     (p_first->*o_link).mp_prev = p_this;
00132     head.mp_first = p_this;
00133     
00134   } else {                                  // list was empty
00135     head.mp_first = p_this;
00136     head.mp_last  = p_this;
00137   }
00138   
00139   mp_parent = &parent;
00140   return;
00141 }
00142 
00143 //------------------------------------------+-----------------------------------
00145 
00149 template <class TP, class TC>
00150 inline void CTBtreeListLink<TP,TC>::InsertTail(TC* p_this,
00151     CTBtreeListLink<TP,TC> TC::* o_link,
00152     TP& parent,
00153     CTBtreeListHead<TP,TC> TP::* o_head)
00154 {
00155   CTBtreeListHead<TP,TC>& head = parent.*o_head;
00156   TC* p_last = head.mp_last;
00157   
00158   assert(!mp_parent && !mp_prev && !mp_next); // !?! must be disconnected
00159   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00160 
00161   if (p_last) {                             // list not empty
00162     assert(!(p_last->*o_link).mp_next);     // !?! no prev in last element
00163     mp_prev = p_last;
00164     (p_last->*o_link).mp_next = p_this;
00165     head.mp_last = p_this;
00166     
00167   } else {                                  // list was empty
00168     head.mp_first = p_this;
00169     head.mp_last  = p_this;
00170   }
00171   
00172   mp_parent = &parent;
00173   return;
00174 }
00175 
00176 //------------------------------------------+-----------------------------------
00178 
00189 template <class TP, class TC>
00190 inline void CTBtreeListLink<TP,TC>::InsertBefore(TC* p_this,
00191     CTBtreeListLink<TP,TC> TC::* o_link,
00192     CTBtreeListHead<TP,TC> TP::* o_head,
00193     TC& elem)
00194 {
00195   TC* p_prev   = (elem.*o_link).mp_prev;  
00196   TP* p_parent = (elem.*o_link).mp_parent;
00197 
00198   assert(!mp_parent && !mp_prev && !mp_next); // !?! must be disconnected
00199   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00200 
00201   if (p_prev) {
00202     assert((p_prev->*o_link).mp_next = &elem); // !?! next link in prev o.k.
00203     mp_prev = p_prev;
00204     mp_next = &elem;
00205     (p_prev->*o_link).mp_next = p_this;
00206     (elem.*o_link).mp_prev    = p_this;    
00207 
00208   } else{
00209     assert((p_parent->*o_head).mp_first == &elem); // !?! really first
00210     mp_next = &elem;
00211     (p_parent->*o_head).mp_first = p_this;
00212     (elem.*o_link).mp_prev       = p_this;
00213   }
00214 
00215   mp_parent = p_parent;
00216   return;
00217 }
00218 
00219 //------------------------------------------+-----------------------------------
00221 
00225 template <class TP, class TC>
00226 inline void CTBtreeListLink<TP,TC>::InsertAfter(TC* p_this,
00227     CTBtreeListLink<TP,TC> TC::* o_link,
00228     CTBtreeListHead<TP,TC> TP::* o_head,
00229     TC& elem)
00230 {
00231   TC* p_next   = (elem.*o_link).mp_next;  
00232   TP* p_parent = (elem.*o_link).mp_parent;
00233 
00234   assert(!mp_parent && !mp_prev && !mp_next); // !?! must be disconnected
00235   assert(&(p_this->*o_link) == this);       // !?! Link must be part of this
00236 
00237   if (p_next) {
00238     assert((p_next->*o_link).mp_prev = &elem); // !?! prev link in next o.k.
00239     mp_prev = &elem;
00240     mp_next = p_next;
00241     (elem.*o_link).mp_next    = p_this;
00242     (p_next->*o_link).mp_prev = p_this;
00243     
00244   } else{
00245     assert((p_parent->*o_head).mp_last == &elem); // !?! really last
00246     mp_prev = &elem;
00247     (elem.*o_link).mp_next      = p_this;
00248     (p_parent->*o_head).mp_last = p_this;
00249   }
00250 
00251   mp_parent = p_parent;
00252   return;
00253 }
00254 
00255 //------------------------------------------+-----------------------------------
00257 
00264 template <class TP, class TC>
00265 inline void CTBtreeListLink<TP,TC>::Remove(CTBtreeListLink<TP,TC> TC::* o_link,
00266                                            CTBtreeListHead<TP,TC> TP::* o_head)
00267 {
00268   assert(mp_parent);                        // !?! must be connected
00269   
00270   if (mp_prev) {
00271     assert(&((mp_prev->*o_link).mp_next->*o_link) == this); // !?! prev <-> next
00272     (mp_prev->*o_link).mp_next = mp_next;
00273   } else {
00274     assert(&((mp_parent->*o_head).mp_first->*o_link) == this); // !?! first
00275     (mp_parent->*o_head).mp_first = mp_next;
00276   }
00277   
00278   if (mp_next) {
00279     assert(&((mp_next->*o_link).mp_prev->*o_link) == this); // !?! next <-> prev
00280     (mp_next->*o_link).mp_prev = mp_prev;
00281   } else {
00282     assert(&((mp_parent->*o_head).mp_last->*o_link) == this);  // !?! last
00283     (mp_parent->*o_head).mp_last = mp_prev;
00284   }
00285   
00286   mp_parent = 0;
00287   mp_prev   = 0;
00288   mp_next   = 0;  
00289 
00290   return;
00291 }
00292 
00293 //------------------------------------------+-----------------------------------
00295 
00296 template <class TP, class TC>
00297 inline bool CTBtreeListLink<TP,TC>::operator! () const
00298 {
00299   return !mp_parent;
00300 }
00301 
00302 //------------------------------------------+-----------------------------------
00304 
00305 template <class TP, class TC>
00306 inline CTBtreeListLink<TP,TC>::operator bool() const
00307 {
00308   return mp_parent;
00309 }
00310 
00311 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00320 //------------------------------------------+-----------------------------------
00322 
00323 template <class TP, class TC>
00324 inline CTBtreeListHead<TP,TC>::CTBtreeListHead()
00325   : mp_first(0),
00326     mp_last(0)
00327 {}
00328 
00329 //------------------------------------------+-----------------------------------
00331 
00357 template <class TP, class TC>
00358 inline CTBtreeListHead<TP,TC>::~CTBtreeListHead()
00359 {
00360   assert(!mp_first && !mp_last);            // !?! list must be empty
00361 }
00362 
00363 //------------------------------------------+-----------------------------------
00365 
00372 template <class TP, class TC>
00373 inline TC* CTBtreeListHead<TP,TC>::First() const
00374 {
00375   return mp_first;
00376 }
00377 
00378 //------------------------------------------+-----------------------------------
00380 
00387 template <class TP, class TC>
00388 inline TC* CTBtreeListHead<TP,TC>::Last() const
00389 {
00390   return mp_last;
00391 }
00392 
00393 //------------------------------------------+-----------------------------------
00395 
00396 template <class TP, class TC>
00397 inline bool CTBtreeListHead<TP,TC>::operator! () const
00398 {
00399   return !mp_first;
00400 }
00401 
00402 //------------------------------------------+-----------------------------------
00404 
00405 template <class TP, class TC>
00406 inline CTBtreeListHead<TP,TC>::operator bool() const
00407 {
00408   return mp_first;
00409 }

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