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 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #ifndef WIN32
33 #include <strings.h>
34 #else
35 #include "XrdSys/XrdWin32.hh"
36 #endif
37 #include <cstdlib>
38 #include "XrdSys/XrdSysPthread.hh"
39 
41 {
42 public:
43 
44 inline int Flag() {return flags;}
45 inline XrdOucNList *Next() {return next;}
46 
47  int NameKO(const char *pd, const int pl);
48 inline int NameKO(const char *pd)
49  {return NameKO(pd, strlen(pd));}
50 
51  int NameOK(const char *pd, const int pl);
52 inline int NameOK(const char *pd)
53  {return NameOK(pd, strlen(pd));}
54 
55 inline void Set(int fval) {flags = fval;}
56 
57  XrdOucNList(const char *name="", int nvals=0);
58 
60  {if (nameL) free(nameL);}
61 
62 friend class XrdOucNList_Anchor;
63 
64 private:
65 
66 XrdOucNList *next;
67 int namelenL;
68 char *nameL;
69 int namelenR;
70 char *nameR;
71 int flags;
72 };
73 
75 {
76 public:
77 
78 inline void Lock() {mutex.Lock();}
79 inline void UnLock() {mutex.UnLock();}
80 
81 inline void Empty(XrdOucNList *newlist=0)
82  {Lock();
83  XrdOucNList *p = next;
84  while(p) {next = p->next; delete p; p = next;}
85  next = newlist;
86  UnLock();
87  }
88 
89 inline XrdOucNList *Find(const char *name)
90  {int nlen = strlen(name);
91  Lock();
92  XrdOucNList *p = next;
93  while(p) {if (p->NameOK(name, nlen)) break;
94  p=p->next;
95  }
96  UnLock();
97  return p;
98  }
99 
100 inline XrdOucNList *First() {return next;}
101 
102 inline void Insert(XrdOucNList *newitem)
103  {Lock();
104  newitem->next = next; next = newitem;
105  UnLock();
106  }
107 
108 inline int NotEmpty() {return next != 0;}
109 
110 inline XrdOucNList *Pop()
111  {XrdOucNList *np;
112  Lock();
113  if ((np = next)) next = np->next;
114  UnLock();
115  return np;
116  }
117 
118  void Replace(const char *name, int nval);
119 
120  void Replace(XrdOucNList *item);
121 
122  // Warning: You must manually lock the object before swap
123 inline void Swap(XrdOucNList_Anchor &other)
124  {XrdOucNList *savenext = next;
125  next = other.First();
126  other.Zorch(savenext);
127  }
128 
129 inline void Zorch(XrdOucNList *newnext=0) {next = newnext;}
130 
131 private:
132 
133 XrdSysMutex mutex;
134 };
135 #endif
XrdOucNList * First()
Definition: XrdOucNList.hh:100
void Empty(XrdOucNList *newlist=0)
Definition: XrdOucNList.hh:81
void Zorch(XrdOucNList *newnext=0)
Definition: XrdOucNList.hh:129
void Swap(XrdOucNList_Anchor &other)
Definition: XrdOucNList.hh:123
XrdOucNList * Pop()
Definition: XrdOucNList.hh:110
void Insert(XrdOucNList *newitem)
Definition: XrdOucNList.hh:102
XrdOucNList * Find(const char *name)
Definition: XrdOucNList.hh:89
void Replace(const char *name, int nval)
Definition: XrdOucNList.cc:110
int NameKO(const char *pd, const int pl)
Definition: XrdOucNList.cc:64
int NameOK(const char *pd, const int pl)
Definition: XrdOucNList.cc:87
XrdOucNList(const char *name="", int nvals=0)
Definition: XrdOucNList.cc:37
int NameKO(const char *pd)
Definition: XrdOucNList.hh:48
void Set(int fval)
Definition: XrdOucNList.hh:55
XrdOucNList * Next()
Definition: XrdOucNList.hh:45
int NameOK(const char *pd)
Definition: XrdOucNList.hh:52