XRootD
Loading...
Searching...
No Matches
XrdSutBuckList.cc
Go to the documentation of this file.
1
2/******************************************************************************/
3/* */
4/* X r d S u t B u c k L i s t . c c */
5/* */
6/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
7/* Produced by Gerri Ganis for CERN */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19/* License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24/* */
25/* The copyright holder's institutional names and contributor's names may not */
26/* be used to endorse or promote products derived from this software without */
27/* specific prior written permission of the institution or contributor. */
28/******************************************************************************/
29
31
32/******************************************************************************/
33/* */
34/* Light single-linked list for managing buckets inside the exchanged */
35/* buffer */
36/* */
37/******************************************************************************/
38
39//___________________________________________________________________________
41{
42 // Constructor
43
44 previous = current = begin = end = 0;
45 size = 0;
46
47 if (b) {
49 current = begin = end = f;
50 size++;
51 }
52}
53
54//___________________________________________________________________________
56{
57 // Destructor
58
59 XrdSutBuckListNode *n = 0;
60 XrdSutBuckListNode *b = begin;
61 while (b) {
62 n = b->Next();
63 delete (b);
64 b = n;
65 }
66}
67
68//___________________________________________________________________________
69XrdSutBuckListNode *XrdSutBuckList::Find(XrdSutBucket *b)
70{
71 // Find node containing bucket b
72
73 XrdSutBuckListNode *nd = begin;
74 for (; nd; nd = nd->Next()) {
75 if (nd->Buck() == b)
76 return nd;
77 }
78 return (XrdSutBuckListNode *)0;
79}
80
81//___________________________________________________________________________
83{
84 // Add at the beginning of the list
85 // Check to avoid duplicates
86
87 if (!Find(b)) {
88 XrdSutBuckListNode *nb = new XrdSutBuckListNode(b,begin);
89 begin = nb;
90 if (!end)
91 end = nb;
92 size++;
93 }
94}
95
96//___________________________________________________________________________
98{
99 // Add at the end of the list
100 // Check to avoid duplicates
101
102 if (!Find(b)) {
104 if (!begin)
105 begin = nb;
106 if (end)
107 end->SetNext(nb);
108 end = nb;
109 size++;
110 }
111}
112
113//___________________________________________________________________________
115{
116 // Remove node containing bucket b
117
118 XrdSutBuckListNode *curr = current;
119 XrdSutBuckListNode *prev = previous;
120
121 if (!curr || curr->Buck() != b || (prev && curr != prev->Next())) {
122 // We need first to find the address
123 curr = begin;
124 prev = 0;
125 for (; curr; curr = curr->Next()) {
126 if (curr->Buck() == b)
127 break;
128 prev = curr;
129 }
130 }
131
132 // The bucket is not in the list
133 if (!curr)
134 return;
135
136 // Now we have all the information to remove
137 if (prev) {
138 current = curr->Next();
139 prev->SetNext(current);
140 previous = curr;
141 } else if (curr == begin) {
142 // First buffer
143 current = curr->Next();
144 begin = current;
145 previous = 0;
146 }
147
148 // Cleanup and update size
149 delete curr;
150 size--;
151}
152
153//___________________________________________________________________________
155{
156 // Iterator functionality: init
157
158 previous = 0;
159 current = begin;
160 if (current)
161 return current->Buck();
162 return (XrdSutBucket *)0;
163}
164
165//___________________________________________________________________________
167{
168 // Iterator functionality: get next
169
170 previous = current;
171 if (current) {
172 current = current->Next();
173 if (current)
174 return current->Buck();
175 }
176 return (XrdSutBucket *)0;
177}
void SetNext(XrdSutBuckListNode *n)
XrdSutBucket * Buck() const
XrdSutBuckListNode * Next() const
void Remove(XrdSutBucket *b)
void PushBack(XrdSutBucket *b)
XrdSutBuckList(XrdSutBucket *b=0)
virtual ~XrdSutBuckList()
XrdSutBucket * Next()
XrdSutBucket * Begin()
void PutInFront(XrdSutBucket *b)