xrootd
XrdOucPList.hh
Go to the documentation of this file.
1 #ifndef __OUC_PLIST__
2 #define __OUC_PLIST__
3 /******************************************************************************/
4 /* */
5 /* X r d O u c P L i s t . h h */
6 /* */
7 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <strings.h>
34 #include <stdlib.h>
35 
37 {
38 public:
39 
40 inline int Attr() {return attrs;}
41 inline unsigned long long Flag() {return flags;}
42 inline XrdOucPList *Next() {return next;}
43 inline char *Path() {return path;}
44 inline int Plen() {return pathlen;}
45 
46 inline int PathOK(const char *pd, const int pl)
47  {return pl >= pathlen && !strncmp(pd, path, pathlen);}
48 
49 inline void Set(int aval) {attrs = aval;}
50 inline void Set(unsigned long long fval) {flags = fval;}
51 
52  XrdOucPList(const char *pd="", unsigned long long fv=0)
53  : flags(fv), next(0), path(strdup(pd)),
54  pathlen(strlen(pd)), attrs(0) {}
56  {if (path) free(path);}
57 
58 friend class XrdOucPListAnchor;
59 
60 private:
61 
62 unsigned long long flags;
64 char *path;
65 int pathlen;
66 int attrs;
67 };
68 
70 {
71 public:
72 
73 inline XrdOucPList *About(const char *pathname)
74  {int plen = strlen(pathname);
75  XrdOucPList *p = next;
76  while(p) {if (p->PathOK(pathname, plen)) break;
77  p=p->next;
78  }
79  return p;
80  }
81 
82 inline void Default(unsigned long long x) {dflts = x;}
83 
84 inline void Empty(XrdOucPList *newlist=0)
85  {XrdOucPList *p = next;
86  while(p) {next = p->next; delete p; p = next;}
87  next = newlist;
88  }
89 
90 inline unsigned long long Find(const char *pathname)
91  {int plen = strlen(pathname);
92  XrdOucPList *p = next;
93  while(p) {if (p->PathOK(pathname, plen)) break;
94  p=p->next;
95  }
96  return (p ? p->flags : dflts);
97  }
98 
99 inline XrdOucPList *Match(const char *pathname)
100  {int plen = strlen(pathname);
101  XrdOucPList *p = next;
102  while(p) {if (p->pathlen == plen
103  && !strcmp(p->path, pathname)) break;
104  p=p->next;
105  }
106  return p;
107  }
108 
109 inline XrdOucPList *First() {return next;}
110 
111 inline void Insert(XrdOucPList *newitem)
112  {XrdOucPList *pp = 0, *cp = next;
113  while(cp && newitem->pathlen < cp->pathlen) {pp=cp;cp=cp->next;}
114  if (pp) {newitem->next = pp->next; pp->next = newitem;}
115  else {newitem->next = next; next = newitem;}
116  }
117 
118 inline int NotEmpty() {return next != 0;}
119 
120  XrdOucPListAnchor(unsigned long long dfx=0) {dflts = dfx;}
122 
123 private:
124 
125 unsigned long long dflts;
126 };
127 #endif