00001 #ifndef __OOUC_NLIST__ 00002 #define __OOUC_NLIST__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c N L i s t . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #ifndef WIN32 00033 #include <strings.h> 00034 #else 00035 #include "XrdSys/XrdWin32.hh" 00036 #endif 00037 #include <stdlib.h> 00038 #include "XrdSys/XrdSysPthread.hh" 00039 00040 class XrdOucNList 00041 { 00042 public: 00043 00044 inline int Flag() {return flags;} 00045 inline XrdOucNList *Next() {return next;} 00046 00047 int NameKO(const char *pd, const int pl); 00048 inline int NameKO(const char *pd) 00049 {return NameKO(pd, strlen(pd));} 00050 00051 int NameOK(const char *pd, const int pl); 00052 inline int NameOK(const char *pd) 00053 {return NameOK(pd, strlen(pd));} 00054 00055 inline void Set(int fval) {flags = fval;} 00056 00057 XrdOucNList(const char *name="", int nvals=0); 00058 00059 ~XrdOucNList() 00060 {if (nameL) free(nameL);} 00061 00062 friend class XrdOucNList_Anchor; 00063 00064 private: 00065 00066 XrdOucNList *next; 00067 int namelenL; 00068 char *nameL; 00069 int namelenR; 00070 char *nameR; 00071 int flags; 00072 }; 00073 00074 class XrdOucNList_Anchor : public XrdOucNList 00075 { 00076 public: 00077 00078 inline void Lock() {mutex.Lock();} 00079 inline void UnLock() {mutex.UnLock();} 00080 00081 inline void Empty(XrdOucNList *newlist=0) 00082 {Lock(); 00083 XrdOucNList *p = next; 00084 while(p) {next = p->next; delete p; p = next;} 00085 next = newlist; 00086 UnLock(); 00087 } 00088 00089 inline XrdOucNList *Find(const char *name) 00090 {int nlen = strlen(name); 00091 Lock(); 00092 XrdOucNList *p = next; 00093 while(p) {if (p->NameOK(name, nlen)) break; 00094 p=p->next; 00095 } 00096 UnLock(); 00097 return p; 00098 } 00099 00100 inline XrdOucNList *First() {return next;} 00101 00102 inline void Insert(XrdOucNList *newitem) 00103 {Lock(); 00104 newitem->next = next; next = newitem; 00105 UnLock(); 00106 } 00107 00108 inline int NotEmpty() {return next != 0;} 00109 00110 inline XrdOucNList *Pop() 00111 {XrdOucNList *np; 00112 Lock(); 00113 if ((np = next)) next = np->next; 00114 UnLock(); 00115 return np; 00116 } 00117 00118 void Replace(const char *name, int nval); 00119 00120 void Replace(XrdOucNList *item); 00121 00122 // Warning: You must manually lock the object before swap 00123 inline void Swap(XrdOucNList_Anchor &other) 00124 {XrdOucNList *savenext = next; 00125 next = other.First(); 00126 other.Zorch(savenext); 00127 } 00128 00129 inline void Zorch(XrdOucNList *newnext=0) {next = newnext;} 00130 00131 private: 00132 00133 XrdSysMutex mutex; 00134 }; 00135 #endif