Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:54

0001 #ifndef __OUC_DLIST__
0002 #define __OUC_DLIST__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                       X r d O u c D L l i s t . h h                        */
0006 /*                                                                            */
0007 /*(c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University   */
0008 /*                         All Rights Reserved                                */
0009 /*Produced by Andrew Hanushevsky for Stanford University under contract       */
0010 /*           DE-AC02-76-SFO0515 with the Deprtment of Energy                  */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032   
0033 
0034 template<class T>
0035 class XrdOucDLlist
0036 {
0037 public:
0038 
0039          XrdOucDLlist(T *itemval=0) {prev=this; next=this; item=itemval;}
0040         ~XrdOucDLlist() {if (prev != next) Remove();}
0041 
0042 // Apply() applies the specified function to every item in the list. Apply()
0043 //         is pointer-safe in that the current node pointers may be changed
0044 //         without affecting the traversal of the list. An argument may be
0045 //         passed to the function. A null pointer is returned if the list
0046 //         was completely traversed. Otherwise, the pointer to the node on
0047 //         which the applied function returned a non-zero value is returned.
0048 //         An optional starting point may be passed.
0049 //
0050 T       *Apply(int (*func)(T *, void *), void *Arg, XrdOucDLlist *Start=0)
0051          {XrdOucDLlist *nextnode, *node;
0052           if (Start) node = Start;   // Set correct starting point
0053              else    node = this;
0054 
0055           // Iterate through the list until we hit ourselves again. We do the 
0056           // loop once on the current node to allow for anchorless lists.
0057           //
0058              do {nextnode = node->next;
0059                  if (node->item && (*func)(node->item, Arg)) return node->item;
0060                  node = nextnode;
0061                 } while (node != this);
0062 
0063          // All done, indicate we went through the whole list
0064          //
0065          return (T *)0;
0066         }
0067 
0068 // Insert() inserts the specified node immediately off itself. If an item value
0069 //          is not given, it is not changed.
0070 //
0071 void Insert(XrdOucDLlist *Node, T *Item=0)
0072                   {Node->next  = next;        // Chain in the item;
0073                    next->prev  = Node;
0074                    next        = Node;
0075                    Node->prev  = this;
0076                    if (Item) Node->item = Item;
0077                   }
0078 
0079 // Item() supplies the item value associated with itself (used with Next()).
0080 //
0081 T  *Item() {return item;}
0082 
0083 // Remove() removes itself from whatever list it happens to be in.
0084 //
0085 void Remove()
0086                   {prev->next = next;                // Unchain the item
0087                    next->prev = prev;
0088                    next       = this;
0089                    prev       = this;
0090                   }
0091 
0092 // Next() supplies the next list node.
0093 //
0094 XrdOucDLlist *Next() {return next;}
0095 
0096 // Prev() supplies the prev list node.
0097 //
0098 XrdOucDLlist *Prev() {return prev;}
0099 
0100 // Set the item pointer
0101 //
0102 void setItem(T *ival) {item = ival;}
0103 
0104 // Singleton() indicates whether or not the node points to something
0105 //
0106 int          Singleton() {return next == this;}
0107 
0108 private:
0109 XrdOucDLlist *next;
0110 XrdOucDLlist *prev;
0111 T            *item;
0112 };
0113 #endif