|
xrootd
|
00001 #ifndef __OUC_PLIST__ 00002 #define __OUC_PLIST__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c P L i s t . h h */ 00006 /* */ 00007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /******************************************************************************/ 00032 00033 #include <strings.h> 00034 #include <stdlib.h> 00035 00036 class XrdOucPList 00037 { 00038 public: 00039 00040 inline int Attr() {return attrs;} 00041 inline unsigned long long Flag() {return flags;} 00042 inline XrdOucPList *Next() {return next;} 00043 inline char *Path() {return path;} 00044 inline int Plen() {return pathlen;} 00045 00046 inline int PathOK(const char *pd, const int pl) 00047 {return pl >= pathlen && !strncmp(pd, path, pathlen);} 00048 00049 inline void Set(int aval) {attrs = aval;} 00050 inline void Set(unsigned long long fval) {flags = fval;} 00051 00052 XrdOucPList(const char *pd="", unsigned long long fv=0) 00053 : flags(fv), next(0), path(strdup(pd)), 00054 pathlen(strlen(pd)), attrs(0) {} 00055 ~XrdOucPList() 00056 {if (path) free(path);} 00057 00058 friend class XrdOucPListAnchor; 00059 00060 private: 00061 00062 unsigned long long flags; 00063 XrdOucPList *next; 00064 char *path; 00065 int pathlen; 00066 int attrs; 00067 }; 00068 00069 class XrdOucPListAnchor : public XrdOucPList 00070 { 00071 public: 00072 00073 inline XrdOucPList *About(const char *pathname) 00074 {int plen = strlen(pathname); 00075 XrdOucPList *p = next; 00076 while(p) {if (p->PathOK(pathname, plen)) break; 00077 p=p->next; 00078 } 00079 return p; 00080 } 00081 00082 inline void Default(unsigned long long x) {dflts = x;} 00083 00084 inline void Empty(XrdOucPList *newlist=0) 00085 {XrdOucPList *p = next; 00086 while(p) {next = p->next; delete p; p = next;} 00087 next = newlist; 00088 } 00089 00090 inline unsigned long long Find(const char *pathname) 00091 {int plen = strlen(pathname); 00092 XrdOucPList *p = next; 00093 while(p) {if (p->PathOK(pathname, plen)) break; 00094 p=p->next; 00095 } 00096 return (p ? p->flags : dflts); 00097 } 00098 00099 inline XrdOucPList *Match(const char *pathname) 00100 {int plen = strlen(pathname); 00101 XrdOucPList *p = next; 00102 while(p) {if (p->pathlen == plen 00103 && !strcmp(p->path, pathname)) break; 00104 p=p->next; 00105 } 00106 return p; 00107 } 00108 00109 inline XrdOucPList *First() {return next;} 00110 00111 inline void Insert(XrdOucPList *newitem) 00112 {XrdOucPList *pp = 0, *cp = next; 00113 while(cp && newitem->pathlen < cp->pathlen) {pp=cp;cp=cp->next;} 00114 if (pp) {newitem->next = pp->next; pp->next = newitem;} 00115 else {newitem->next = next; next = newitem;} 00116 } 00117 00118 inline int NotEmpty() {return next != 0;} 00119 00120 XrdOucPListAnchor(unsigned long long dfx=0) {dflts = dfx;} 00121 ~XrdOucPListAnchor() {} 00122 00123 private: 00124 00125 unsigned long long dflts; 00126 }; 00127 #endif
1.7.6.1