XrdOucChain.hh

Go to the documentation of this file.
00001 #ifndef __OUC_CHAIN__
00002 #define __OUC_CHAIN__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d O u c C h a i n . h h                         */
00006 /*                                                                            */
00007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 template<class T>
00034 class XrdOucQSItem
00035 {
00036 public:
00037 XrdOucQSItem<T>  *nextelem;
00038 T                *dataitem;
00039                   XrdOucQSItem(T *item) {dataitem = item; nextelem = 0;}
00040                  ~XrdOucQSItem()        {}
00041 };
00042   
00043 template<class T>
00044 class XrdOucStack
00045 {
00046 public:
00047 
00048 int    isEmpty() {return anchor == 0;}
00049 
00050 T     *Pop() {XrdOucQSItem<T> *cp;
00051               if (!(cp = anchor)) return (T *)0;
00052               anchor = anchor->nextelem;
00053               cp->nextelem = 0;
00054               return cp->dataitem;
00055              }
00056 
00057 void   Push(XrdOucQSItem<T> *item) {item->nextelem = anchor; anchor = item;}
00058 
00059        XrdOucStack() {anchor = 0;}
00060       ~XrdOucStack() {}
00061 
00062 private:
00063 XrdOucQSItem<T>    *anchor;
00064 };
00065 
00066 template<class T>
00067 class XrdOucQueue
00068 {
00069 public:
00070 
00071 void   Add(XrdOucQSItem<T> *item) 
00072              {item->nextelem = 0;
00073               if (lastelem) {lastelem->nextelem = item;
00074                              lastelem = item;
00075                             }
00076                  else        anchor = lastelem  = item;
00077              }
00078 
00079 int    isEmpty() {return anchor == 0;}
00080 
00081 T     *Remove() {XrdOucQSItem<T> *qp;
00082                  if (!(qp = anchor)) return (T *)0;
00083                  if (!(anchor = anchor->nextelem)) lastelem = 0;
00084                  return qp->dataitem;
00085                 }
00086 
00087        XrdOucQueue() {anchor = lastelem = 0;}
00088       ~XrdOucQueue() {}
00089 
00090 private:
00091 XrdOucQSItem<T> *anchor;
00092 XrdOucQSItem<T> *lastelem;
00093 };
00094 #endif

Generated on 16 Jan 2014 for xrootd by  doxygen 1.4.7