xrootd
XrdOucNList.hh
Go to the documentation of this file.
1 #ifndef __OOUC_NLIST__
2 #define __OOUC_NLIST__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c N L i s t . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // $Id$
14 
15 #ifndef WIN32
16 #include <strings.h>
17 #else
18 #include "XrdSys/XrdWin32.hh"
19 #endif
20 #include <stdlib.h>
21 #include "XrdSys/XrdSysPthread.hh"
22 
24 {
25 public:
26 
27 inline int Flag() {return flags;}
28 inline XrdOucNList *Next() {return next;}
29 
30  int NameOK(const char *pd, const int pl);
31 inline int NameOK(const char *pd)
32  {return NameOK(pd, strlen(pd));}
33 
34 inline void Set(int fval) {flags = fval;}
35 
36  XrdOucNList(const char *name="", int nvals=0);
37 
39  {if (nameL) free(nameL);}
40 
41 friend class XrdOucNList_Anchor;
42 
43 private:
44 
47 char *nameL;
49 char *nameR;
50 int flags;
51 };
52 
54 {
55 public:
56 
57 inline void Lock() {mutex.Lock();}
58 inline void UnLock() {mutex.UnLock();}
59 
60 inline void Empty(XrdOucNList *newlist=0)
61  {Lock();
62  XrdOucNList *p = next;
63  while(p) {next = p->next; delete p; p = next;}
64  next = newlist;
65  UnLock();
66  }
67 
68 inline XrdOucNList *Find(const char *name)
69  {int nlen = strlen(name);
70  Lock();
71  XrdOucNList *p = next;
72  while(p) {if (p->NameOK(name, nlen)) break;
73  p=p->next;
74  }
75  UnLock();
76  return p;
77  }
78 
79 inline XrdOucNList *First() {return next;}
80 
81 inline void Insert(XrdOucNList *newitem)
82  {Lock();
83  newitem->next = next; next = newitem;
84  UnLock();
85  }
86 
87 inline int NotEmpty() {return next != 0;}
88 
89 inline XrdOucNList *Pop()
90  {XrdOucNList *np;
91  Lock();
92  if ((np = next)) next = np->next;
93  UnLock();
94  return np;
95  }
96 
97  void Replace(const char *name, int nval);
98 
99  void Replace(XrdOucNList *item);
100 
101  // Warning: You must manually lock the object before swap
102 inline void Swap(XrdOucNList_Anchor &other)
103  {XrdOucNList *savenext = next;
104  next = other.First();
105  other.Zorch(savenext);
106  }
107 
108 inline void Zorch(XrdOucNList *newnext=0) {next = newnext;}
109 
110 private:
111 
113 };
114 #endif