/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcTrkRecon/MdcTrkRecon-00-03-45/src/GmsList.cxx

Go to the documentation of this file.
00001 //  File:  GmsList.cc
00002 //  Authors:  Alan Breakstone, Gary Word
00003 
00004 /* This class is derived from a similar class in "A C++ Toolkit",
00005    which is Copyright 1991 by Jonathan S. Shapiro, and is used
00006    with permission.  "A C++ Toolkit" is published by Prentice Hall, Inc. */
00007 
00008 //  Contents ----------------------------------------------------------
00009 //
00010 //      GmsList::append(  GmsListLink *l )
00011 //      GmsList::prepend( GmsListLink *l )
00012 //      GmsList::remove(  GmsListLink *l )
00013 //
00014 //  End ---------------------------------------------------------------
00015 
00016 #include "MdcTrkRecon/GmsList.h"
00017 
00018 GmsList::~GmsList() {}
00019 
00020 GmsList& GmsList::append( GmsListLink *l )
00021 {  // add an item to the end of a list
00022         if ( _last ) {
00023                 _last->_next = l;
00024                 l->_prev = _last;
00025         }
00026         else
00027                 _first = l;
00028         
00029         _last = l;
00030 
00031         _count++;
00032 
00033         return *this;
00034 }
00035 
00036 GmsList& GmsList::prepend( GmsListLink *l )
00037 {  // add an item to the beginning of a list
00038         if ( _first ) {
00039                 _first->_prev = l;
00040                 l->_next = _first;
00041         }
00042         else
00043                 _last = l;
00044 
00045         _first = l;
00046 
00047         _count++;
00048 
00049         return *this;
00050 }
00051 GmsList& GmsList::insertAfter( GmsListLink *l, GmsListLink *here )
00052 {  // add an item to the middle of a list
00053         GmsListLink *after = 0;
00054         if ( here != 0 ) {
00055           after = here->_next;
00056           here->_next = l;
00057           l->_prev = here;
00058         }
00059         else {
00060           after = _first;
00061           l->_prev = 0;
00062           _first = l;
00063         }
00064         l->_next = after;
00065 
00066         if (after == 0) {
00067           _last = l;
00068         }
00069         else {
00070           after->_prev = l;
00071         }
00072 
00073         _count++;
00074 
00075         return *this;
00076 }
00077 GmsList& GmsList::moveAfter( GmsListLink *l, GmsListLink *here )
00078 {  // add an item from one place in list to another
00079 
00080         // First remove it from its current position
00081         if ( l == _first )
00082                 _first = _first->_next;
00083         if ( l == _last )
00084                 _last = _last->_prev;
00085         
00086         if ( l->_next ) {
00087                 l->_next->_prev = l->_prev;
00088         }
00089         if ( l->_prev ) {
00090                 l->_prev->_next = l->_next;
00091         }
00092 
00093 
00094         GmsListLink *after = 0;
00095         if ( here != 0 ) {
00096           after = here->_next;
00097           here->_next = l;
00098           l->_prev = here;
00099         }
00100         else {
00101           after = _first;
00102           l->_prev = 0;
00103           _first = l;
00104         }
00105         l->_next = after;
00106 
00107         if (after == 0) {
00108           _last = l;
00109         }
00110         else {
00111           after->_prev = l;
00112         }
00113 
00114 
00115         return *this;
00116 }
00117 
00118 GmsList& GmsList::remove( GmsListLink *l )
00119 {  // remove an item from the list
00120         if ( l == _first )
00121                 _first = _first->_next;
00122         if ( l == _last )
00123                 _last = _last->_prev;
00124         
00125         if ( l->_next ) {
00126                 l->_next->_prev = l->_prev;
00127         }
00128         if ( l->_prev ) {
00129                 l->_prev->_next = l->_next;
00130         }
00131         l->_next = 0;
00132         l->_prev = 0;
00133 
00134         _count--;
00135 
00136         return *this;
00137 }

Generated on Tue Nov 29 23:13:33 2016 for BOSS_7.0.2 by  doxygen 1.4.7