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-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <strings.h>
14 #include <stdlib.h>
15 
17 {
18 public:
19 
20 inline int Attr() {return attrs;}
21 inline unsigned long long Flag() {return flags;}
22 inline XrdOucPList *Next() {return next;}
23 inline char *Path() {return path;}
24 inline int Plen() {return pathlen;}
25 
26 inline int PathOK(const char *pd, const int pl)
27  {return pl >= pathlen && !strncmp(pd, path, pathlen);}
28 
29 inline void Set(int aval) {attrs = aval;}
30 inline void Set(unsigned long long fval) {flags = fval;}
31 
32  XrdOucPList(const char *pd="", unsigned long long fv=0)
33  : flags(fv), next(0), path(strdup(pd)),
34  pathlen(strlen(pd)), attrs(0) {}
36  {if (path) free(path);}
37 
38 friend class XrdOucPListAnchor;
39 
40 private:
41 
42 unsigned long long flags;
44 char *path;
45 int pathlen;
46 int attrs;
47 };
48 
50 {
51 public:
52 
53 inline XrdOucPList *About(const char *pathname)
54  {int plen = strlen(pathname);
55  XrdOucPList *p = next;
56  while(p) {if (p->PathOK(pathname, plen)) break;
57  p=p->next;
58  }
59  return p;
60  }
61 
62 inline void Default(unsigned long long x) {dflts = x;}
63 
64 inline void Empty(XrdOucPList *newlist=0)
65  {XrdOucPList *p = next;
66  while(p) {next = p->next; delete p; p = next;}
67  next = newlist;
68  }
69 
70 inline unsigned long long Find(const char *pathname)
71  {int plen = strlen(pathname);
72  XrdOucPList *p = next;
73  while(p) {if (p->PathOK(pathname, plen)) break;
74  p=p->next;
75  }
76  return (p ? p->flags : dflts);
77  }
78 
79 inline XrdOucPList *Match(const char *pathname)
80  {int plen = strlen(pathname);
81  XrdOucPList *p = next;
82  while(p) {if (p->pathlen == plen
83  && !strcmp(p->path, pathname)) break;
84  p=p->next;
85  }
86  return p;
87  }
88 
89 inline XrdOucPList *First() {return next;}
90 
91 inline void Insert(XrdOucPList *newitem)
92  {XrdOucPList *pp = 0, *cp = next;
93  while(cp && newitem->pathlen < cp->pathlen) {pp=cp;cp=cp->next;}
94  if (pp) {newitem->next = pp->next; pp->next = newitem;}
95  else {newitem->next = next; next = newitem;}
96  }
97 
98 inline int NotEmpty() {return next != 0;}
99 
100  XrdOucPListAnchor(unsigned long long dfx=0) {dflts = dfx;}
102 
103 private:
104 
105 unsigned long long dflts;
106 };
107 #endif