]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ACLStrategised.h
Summary: MSVC Compatability.
[thirdparty/squid.git] / src / ACLStrategised.h
1
2 /*
3 * $Id: ACLStrategised.h,v 1.4 2003/07/14 08:21:56 robertc Exp $
4 *
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 *
33 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
34 */
35
36 #ifndef SQUID_ACLSTRATEGISED_H
37 #define SQUID_ACLSTRATEGISED_H
38 #include "ACL.h"
39 #include "ACLData.h"
40 #include "ACLStrategy.h"
41
42 template <class M>
43
44 class ACLStrategised : public ACL
45 {
46
47 public:
48 typedef M MatchType;
49 void *operator new(size_t);
50 void operator delete(void *);
51 virtual void deleteSelf() const;
52
53 ~ACLStrategised();
54 ACLStrategised(ACLData<MatchType> *, ACLStrategy<MatchType> *, char const *);
55 ACLStrategised (ACLStrategised const &);
56 ACLStrategised &operator= (ACLStrategised const &);
57
58 virtual char const *typeString() const;
59 virtual bool requiresRequest() const {return matcher->requiresRequest();}
60
61 virtual void prepareForUse() { data->prepareForUse();}
62
63 virtual void parse();
64 virtual int match(ACLChecklist *checklist);
65 virtual int match (M const &);
66 virtual wordlist *dump() const;
67 virtual bool valid () const;
68 virtual ACL *clone()const;
69
70 private:
71 static MemPool *Pool;
72 ACLData<MatchType> *data;
73 char const *type_;
74 ACLStrategy<MatchType> *matcher;
75 };
76
77 /* implementation follows */
78
79 template <class MatchType>
80 MemPool (*ACLStrategised<MatchType>::Pool)(NULL);
81
82 template <class MatchType>
83 void *
84 ACLStrategised<MatchType>::operator new (size_t byteCount)
85 {
86 /* derived classes with different sizes must implement their own new */
87 assert (byteCount == sizeof (ACLStrategised<MatchType>));
88
89 if (!Pool)
90 Pool = memPoolCreate("ACLStrategised", sizeof (ACLStrategised<MatchType>));
91
92 return memPoolAlloc(Pool);
93 }
94
95 template <class MatchType>
96 void
97 ACLStrategised<MatchType>::operator delete (void *address)
98 {
99 memPoolFree (Pool, address);
100 }
101
102 template <class MatchType>
103 void
104 ACLStrategised<MatchType>::deleteSelf() const
105 {
106 delete this;
107 }
108
109 template <class MatchType>
110 ACLStrategised<MatchType>::~ACLStrategised()
111 {
112 data->deleteSelf();
113 }
114
115 template <class MatchType>
116 ACLStrategised<MatchType>::ACLStrategised(ACLData<MatchType> *newData, ACLStrategy<MatchType> *theStrategy, char const *theType) : data (newData), type_(theType), matcher(theStrategy) {}
117
118 template <class MatchType>
119 ACLStrategised<MatchType>::ACLStrategised (ACLStrategised const &old) : data (old.data->clone()), type_(old.type_), matcher (old.matcher)
120 {}
121
122 template <class MatchType>
123 ACLStrategised<MatchType> &
124 ACLStrategised<MatchType>::operator= (ACLStrategised const &rhs)
125 {
126 data = rhs.data->clone();
127 type_ = rhs.type_;
128 matcher = rhs.matcher;
129 return *this;
130 }
131
132 template <class MatchType>
133 char const *
134 ACLStrategised<MatchType>::typeString() const
135 {
136 return type_;
137 }
138
139 template <class MatchType>
140 void
141 ACLStrategised<MatchType>::parse()
142 {
143 data->parse();
144 }
145
146 template <class MatchType>
147 int
148 ACLStrategised<MatchType>::match(ACLChecklist *checklist)
149 {
150 return matcher->match(data, checklist);
151 }
152
153 template <class MatchType>
154 int
155 ACLStrategised<MatchType>::match(MatchType const &toFind)
156 {
157 return data->match(toFind);
158 }
159
160 template <class MatchType>
161 wordlist *
162 ACLStrategised<MatchType>::dump() const
163 {
164 return data->dump();
165 }
166
167 template <class MatchType>
168 bool
169 ACLStrategised<MatchType>::valid () const
170 {
171 return data != NULL;
172 }
173
174 template <class MatchType>
175 ACL *
176 ACLStrategised<MatchType>::clone() const
177 {
178 return new ACLStrategised(*this);
179 }
180
181 #endif /* SQUID_ACLSTRATEGISED_H */