xrootd
Loading...
Searching...
No Matches
XrdOucDLlist.hh
Go to the documentation of this file.
1#ifndef __OUC_DLIST__
2#define __OUC_DLIST__
3/******************************************************************************/
4/* */
5/* X r d O u c D L l i s t . h h */
6/* */
7/*(c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* All Rights Reserved */
9/*Produced by Andrew Hanushevsky for Stanford University under contract */
10/* DE-AC02-76-SFO0515 with the Deprtment of Energy */
11/* */
12/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
31/******************************************************************************/
32
33
34template<class T>
36{
37public:
38
39 XrdOucDLlist(T *itemval=0) {prev=this; next=this; item=itemval;}
41
42// Apply() applies the specified function to every item in the list. Apply()
43// is pointer-safe in that the current node pointers may be changed
44// without affecting the traversal of the list. An argument may be
45// passed to the function. A null pointer is returned if the list
46// was completely traversed. Otherwise, the pointer to the node on
47// which the applied function returned a non-zero value is returned.
48// An optional starting point may be passed.
49//
50T *Apply(int (*func)(T *, void *), void *Arg, XrdOucDLlist *Start=0)
51 {XrdOucDLlist *nextnode, *node;
52 if (Start) node = Start; // Set correct starting point
53 else node = this;
54
55 // Iterate through the list until we hit ourselves again. We do the
56 // loop once on the current node to allow for anchorless lists.
57 //
58 do {nextnode = node->next;
59 if (node->item && (*func)(node->item, Arg)) return node->item;
60 node = nextnode;
61 } while (node != this);
62
63 // All done, indicate we went through the whole list
64 //
65 return (T *)0;
66 }
67
68// Insert() inserts the specified node immediately off itself. If an item value
69// is not given, it is not changed.
70//
71void Insert(XrdOucDLlist *Node, T *Item=0)
72 {Node->next = next; // Chain in the item;
73 next->prev = Node;
74 next = Node;
75 Node->prev = this;
76 if (Item) Node->item = Item;
77 }
78
79// Item() supplies the item value associated with itself (used with Next()).
80//
81T *Item() {return item;}
82
83// Remove() removes itself from whatever list it happens to be in.
84//
85void Remove()
86 {prev->next = next; // Unchain the item
87 next->prev = prev;
88 next = this;
89 prev = this;
90 }
91
92// Next() supplies the next list node.
93//
95
96// Prev() supplies the prev list node.
97//
99
100// Set the item pointer
101//
102void setItem(T *ival) {item = ival;}
103
104// Singleton() indicates whether or not the node points to something
105//
106int Singleton() {return next == this;}
107
108private:
112};
113#endif
Definition XrdOucDLlist.hh:36
int Singleton()
Definition XrdOucDLlist.hh:106
XrdOucDLlist(T *itemval=0)
Definition XrdOucDLlist.hh:39
void setItem(T *ival)
Definition XrdOucDLlist.hh:102
T * item
Definition XrdOucDLlist.hh:111
~XrdOucDLlist()
Definition XrdOucDLlist.hh:40
XrdOucDLlist * prev
Definition XrdOucDLlist.hh:110
T * Apply(int(*func)(T *, void *), void *Arg, XrdOucDLlist *Start=0)
Definition XrdOucDLlist.hh:50
void Insert(XrdOucDLlist *Node, T *Item=0)
Definition XrdOucDLlist.hh:71
XrdOucDLlist * Next()
Definition XrdOucDLlist.hh:94
void Remove()
Definition XrdOucDLlist.hh:85
XrdOucDLlist * next
Definition XrdOucDLlist.hh:109
T * Item()
Definition XrdOucDLlist.hh:81
XrdOucDLlist * Prev()
Definition XrdOucDLlist.hh:98