XRootD
Loading...
Searching...
No Matches
XrdOucMapP2X.hh
Go to the documentation of this file.
1#ifndef __XrdOucMAPP2X__
2#define __XrdOucMAPP2X__
3/******************************************************************************/
4/* */
5/* X r d O u c M a p P 2 X . h h */
6/* */
7/* (c) 2021 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 <cstdlib>
35
36template<class T>
38{
39public:
40
41XrdOucMapP2X<T> *Find(const char *path)
42 {XrdOucMapP2X<T> *p = Next;
43 int plen = strlen(path);
44 while(p && plen <= p->PLen)
45 {if (plen == p->PLen && !strcmp(p->Path, path))
46 return p;
47 p = p->Next;
48 }
49 return 0;
50 }
51
53 {XrdOucMapP2X<T> *pp = 0, *p = Next;
54 while(p && newp->PLen < p->PLen)
55 {pp = p; p = p->Next;}
56 newp->Next = p;
57 if (pp) pp->Next = newp;
58 else Next = newp;
59 }
60
61 bool isEmpty() {return Next == 0;}
62
63 const char *theName() {return Name;}
64
65XrdOucMapP2X<T> *theNext() {return Next;}
66
67 const char *thePath() {return Path;}
68
69 T theValu() {return Valu;}
70
71 void RepName(const char *newname)
72 {if (Path) {free(Name); Name = strdup(newname);}}
73
74 void RepValu(T arg) {Valu = arg;}
75
76XrdOucMapP2X<T> *Match(const char *pd, const int pl=0)
77 {int plen = (pl ? pl : strlen(pd));
78 XrdOucMapP2X<T> *p = Next;
79 while(p && plen >= p->PLen)
80 {if (!strncmp(pd, p->Path, p->PLen)) return p;
81 p=p->Next;
82 }
83 return 0;
84 }
85
86 XrdOucMapP2X() : Next(0), Name(0), Path(0), PLen(0), Valu(0) {}
87
88 XrdOucMapP2X(const char *path, const char *name, T arg=0)
89 : Next(0), Name(strdup(name)), Path(strdup(path)),
90 PLen(strlen(path)), Valu(arg) {}
91
92 ~XrdOucMapP2X() {if (Path) free(Path); if (Name) free(Name);}
93
94private:
95 XrdOucMapP2X<T> *Next;
96 char *Name;
97 char *Path;
98 int PLen;
99 T Valu;
100};
101#endif
const char * thePath()
void RepName(const char *newname)
void Insert(XrdOucMapP2X< T > *newp)
XrdOucMapP2X< T > * Match(const char *pd, const int pl=0)
XrdOucMapP2X< T > * Find(const char *path)
XrdOucMapP2X< T > * theNext()
XrdOucMapP2X(const char *path, const char *name, T arg=0)
const char * theName()
void RepValu(T arg)