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 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 //         $Id: XrdOucNList.hh 22437 2008-03-04 14:35:16Z rdm $
00014 
00015 #ifndef WIN32
00016 #include <strings.h>
00017 #else
00018 #include "XrdSys/XrdWin32.hh"
00019 #endif
00020 #include <stdlib.h>
00021 #include "XrdSys/XrdSysPthread.hh"
00022   
00023 class XrdOucNList
00024 {
00025 public:
00026 
00027 inline int         Flag() {return flags;}
00028 inline XrdOucNList *Next() {return next;}
00029 
00030        int         NameOK(const char *pd, const int pl);
00031 inline int         NameOK(const char *pd)
00032                          {return NameOK(pd, strlen(pd));}
00033 
00034 inline void        Set(int fval) {flags = fval;}
00035 
00036              XrdOucNList(const char *name="", int nvals=0);
00037 
00038             ~XrdOucNList()
00039                   {if (nameL) free(nameL);}
00040 
00041 friend class XrdOucNList_Anchor;
00042 
00043 private:
00044 
00045 XrdOucNList        *next;
00046 int                namelenL;
00047 char              *nameL;
00048 int                namelenR;
00049 char              *nameR;
00050 int                flags;
00051 };
00052 
00053 class XrdOucNList_Anchor : public XrdOucNList
00054 {
00055 public:
00056 
00057 inline void        Lock() {mutex.Lock();}
00058 inline void      UnLock() {mutex.UnLock();}
00059 
00060 inline void        Empty(XrdOucNList *newlist=0)
00061                    {Lock();
00062                     XrdOucNList *p = next;
00063                     while(p) {next = p->next; delete p; p = next;}
00064                     next = newlist;
00065                     UnLock();
00066                    }
00067 
00068 inline XrdOucNList *Find(const char *name)
00069                    {int nlen = strlen(name);
00070                     Lock();
00071                     XrdOucNList *p = next;
00072                     while(p) {if (p->NameOK(name, nlen)) break;
00073                               p=p->next;
00074                              }
00075                     UnLock();
00076                     return p;
00077                    }
00078 
00079 inline XrdOucNList *First() {return next;}
00080 
00081 inline void        Insert(XrdOucNList *newitem)
00082                    {Lock();
00083                     newitem->next = next; next = newitem; 
00084                     UnLock();
00085                    }
00086 
00087 inline int         NotEmpty() {return next != 0;}
00088 
00089 inline XrdOucNList *Pop()
00090                    {XrdOucNList *np;
00091                     Lock();
00092                     if ((np = next)) next = np->next;
00093                     UnLock();
00094                     return np;
00095                    }
00096 
00097        void        Replace(const char *name, int nval);
00098 
00099        void        Replace(XrdOucNList *item);
00100 
00101                    // Warning: You must manually lock the object before swap
00102 inline void        Swap(XrdOucNList_Anchor &other)
00103                        {XrdOucNList *savenext = next;
00104                         next = other.First();
00105                         other.Zorch(savenext);
00106                        }
00107 
00108 inline void        Zorch(XrdOucNList *newnext=0) {next = newnext;}
00109 
00110 private:
00111 
00112 XrdSysMutex         mutex;
00113 };
00114 #endif

Generated on Tue Jul 5 14:46:50 2011 for ROOT_528-00b_version by  doxygen 1.5.1