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-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id: XrdOucChain.hh 22437 2008-03-04 14:35:16Z rdm $ 00014 00015 template<class T> 00016 class XrdOucQSItem 00017 { 00018 public: 00019 XrdOucQSItem<T> *nextelem; 00020 T *dataitem; 00021 XrdOucQSItem(T *item) {dataitem = item; nextelem = 0;} 00022 ~XrdOucQSItem() {} 00023 }; 00024 00025 template<class T> 00026 class XrdOucStack 00027 { 00028 public: 00029 00030 int isEmpty() {return anchor == 0;} 00031 00032 T *Pop() {XrdOucQSItem<T> *cp; 00033 if (!(cp = anchor)) return (T *)0; 00034 anchor = anchor->nextelem; 00035 cp->nextelem = 0; 00036 return cp->dataitem; 00037 } 00038 00039 void Push(XrdOucQSItem<T> *item) {item->nextelem = anchor; anchor = item;} 00040 00041 XrdOucStack() {anchor = 0;} 00042 ~XrdOucStack() {} 00043 00044 private: 00045 XrdOucQSItem<T> *anchor; 00046 }; 00047 00048 template<class T> 00049 class XrdOucQueue 00050 { 00051 public: 00052 00053 void Add(XrdOucQSItem<T> *item) 00054 {item->nextelem = 0; 00055 if (lastelem) {lastelem->nextelem = item; 00056 lastelem = item; 00057 } 00058 else anchor = lastelem = item; 00059 } 00060 00061 int isEmpty() {return anchor == 0;} 00062 00063 T *Remove() {XrdOucQSItem<T> *qp; 00064 if (!(qp = anchor)) return (T *)0; 00065 if (!(anchor = anchor->nextelem)) lastelem = 0; 00066 return qp->dataitem; 00067 } 00068 00069 XrdOucQueue() {anchor = lastelem = 0;} 00070 ~XrdOucQueue() {} 00071 00072 private: 00073 XrdOucQSItem<T> *anchor; 00074 XrdOucQSItem<T> *lastelem; 00075 }; 00076 #endif