BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
GmsList.cxx
Go to the documentation of this file.
1// File: GmsList.cc
2// Authors: Alan Breakstone, Gary Word
3
4/* This class is derived from a similar class in "A C++ Toolkit",
5 which is Copyright 1991 by Jonathan S. Shapiro, and is used
6 with permission. "A C++ Toolkit" is published by Prentice Hall, Inc. */
7
8// Contents ----------------------------------------------------------
9//
10// GmsList::append( GmsListLink *l )
11// GmsList::prepend( GmsListLink *l )
12// GmsList::remove( GmsListLink *l )
13//
14// End ---------------------------------------------------------------
15
16#include "MdcTrkRecon/GmsList.h"
17
19
20GmsList& GmsList::append( GmsListLink* l ) { // add an item to the end of a list
21 if ( _last )
22 {
23 _last->_next = l;
24 l->_prev = _last;
25 }
26 else _first = l;
27
28 _last = l;
29
30 _count++;
31
32 return *this;
33}
34
35GmsList& GmsList::prepend( GmsListLink* l ) { // add an item to the beginning of a list
36 if ( _first )
37 {
38 _first->_prev = l;
39 l->_next = _first;
40 }
41 else _last = l;
42
43 _first = l;
44
45 _count++;
46
47 return *this;
48}
50 GmsListLink* here ) { // add an item to the middle of a list
51 GmsListLink* after = 0;
52 if ( here != 0 )
53 {
54 after = here->_next;
55 here->_next = l;
56 l->_prev = here;
57 }
58 else
59 {
60 after = _first;
61 l->_prev = 0;
62 _first = l;
63 }
64 l->_next = after;
65
66 if ( after == 0 ) { _last = l; }
67 else { after->_prev = l; }
68
69 _count++;
70
71 return *this;
72}
73GmsList& GmsList::moveAfter( GmsListLink* l, GmsListLink* here ) { // add an item from one
74 // place in list to another
75
76 // First remove it from its current position
77 if ( l == _first ) _first = _first->_next;
78 if ( l == _last ) _last = _last->_prev;
79
80 if ( l->_next ) { l->_next->_prev = l->_prev; }
81 if ( l->_prev ) { l->_prev->_next = l->_next; }
82
83 GmsListLink* after = 0;
84 if ( here != 0 )
85 {
86 after = here->_next;
87 here->_next = l;
88 l->_prev = here;
89 }
90 else
91 {
92 after = _first;
93 l->_prev = 0;
94 _first = l;
95 }
96 l->_next = after;
97
98 if ( after == 0 ) { _last = l; }
99 else { after->_prev = l; }
100
101 return *this;
102}
103
104GmsList& GmsList::remove( GmsListLink* l ) { // remove an item from the list
105 if ( l == _first ) _first = _first->_next;
106 if ( l == _last ) _last = _last->_prev;
107
108 if ( l->_next ) { l->_next->_prev = l->_prev; }
109 if ( l->_prev ) { l->_prev->_next = l->_next; }
110 l->_next = 0;
111 l->_prev = 0;
112
113 _count--;
114
115 return *this;
116}
virtual ~GmsList()
Definition GmsList.cxx:18
GmsList & moveAfter(GmsListLink *link, GmsListLink *insertHere)
Definition GmsList.cxx:73
GmsList & prepend(GmsListLink *)
Definition GmsList.cxx:35
GmsList & append(GmsListLink *)
Definition GmsList.cxx:20
GmsList & insertAfter(GmsListLink *link, GmsListLink *insertHere)
Definition GmsList.cxx:49
GmsList & remove(GmsListLink *)
Definition GmsList.cxx:104