xrootd
XrdOucNList.hh
Go to the documentation of this file.
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         NameOK(const char *pd, const int pl);
00048 inline int         NameOK(const char *pd)
00049                          {return NameOK(pd, strlen(pd));}
00050 
00051 inline void        Set(int fval) {flags = fval;}
00052 
00053              XrdOucNList(const char *name="", int nvals=0);
00054 
00055             ~XrdOucNList()
00056                   {if (nameL) free(nameL);}
00057 
00058 friend class XrdOucNList_Anchor;
00059 
00060 private:
00061 
00062 XrdOucNList        *next;
00063 int                namelenL;
00064 char              *nameL;
00065 int                namelenR;
00066 char              *nameR;
00067 int                flags;
00068 };
00069 
00070 class XrdOucNList_Anchor : public XrdOucNList
00071 {
00072 public:
00073 
00074 inline void        Lock() {mutex.Lock();}
00075 inline void      UnLock() {mutex.UnLock();}
00076 
00077 inline void        Empty(XrdOucNList *newlist=0)
00078                    {Lock();
00079                     XrdOucNList *p = next;
00080                     while(p) {next = p->next; delete p; p = next;}
00081                     next = newlist;
00082                     UnLock();
00083                    }
00084 
00085 inline XrdOucNList *Find(const char *name)
00086                    {int nlen = strlen(name);
00087                     Lock();
00088                     XrdOucNList *p = next;
00089                     while(p) {if (p->NameOK(name, nlen)) break;
00090                               p=p->next;
00091                              }
00092                     UnLock();
00093                     return p;
00094                    }
00095 
00096 inline XrdOucNList *First() {return next;}
00097 
00098 inline void        Insert(XrdOucNList *newitem)
00099                    {Lock();
00100                     newitem->next = next; next = newitem; 
00101                     UnLock();
00102                    }
00103 
00104 inline int         NotEmpty() {return next != 0;}
00105 
00106 inline XrdOucNList *Pop()
00107                    {XrdOucNList *np;
00108                     Lock();
00109                     if ((np = next)) next = np->next;
00110                     UnLock();
00111                     return np;
00112                    }
00113 
00114        void        Replace(const char *name, int nval);
00115 
00116        void        Replace(XrdOucNList *item);
00117 
00118                    // Warning: You must manually lock the object before swap
00119 inline void        Swap(XrdOucNList_Anchor &other)
00120                        {XrdOucNList *savenext = next;
00121                         next = other.First();
00122                         other.Zorch(savenext);
00123                        }
00124 
00125 inline void        Zorch(XrdOucNList *newnext=0) {next = newnext;}
00126 
00127 private:
00128 
00129 XrdSysMutex         mutex;
00130 };
00131 #endif