]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ACLStrategised.h
Summary: Merge final stage1 ACL refactoring.
[thirdparty/squid.git] / src / ACLStrategised.h
CommitLineData
5dee515e 1
2/*
62e76326 3 * $Id: ACLStrategised.h,v 1.2 2003/02/21 22:50:04 robertc Exp $
5dee515e 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 "ACLMatchStrategy.h"
41
42template <class M>
62e76326 43
44class ACLStrategised : public ACL
45{
46
47public:
5dee515e 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> *, ACLMatchStrategy<MatchType> *, char const *);
55 ACLStrategised (ACLStrategised const &);
56 ACLStrategised &operator= (ACLStrategised const &);
62e76326 57
5dee515e 58 virtual char const *typeString() const;
59 virtual squid_acl aclType() const { return ACL_DERIVED;}
62e76326 60
5dee515e 61 virtual bool requiresRequest() const {return matcher->requiresRequest();}
62e76326 62
5dee515e 63 virtual void parse();
64 virtual int match(ACLChecklist *checklist);
65 virtual wordlist *dump() const;
66 virtual bool valid () const;
67 virtual ACL *clone()const;
62e76326 68
69private:
5dee515e 70 static MemPool *Pool;
71 ACLData<MatchType> *data;
72 char const *type_;
73 ACLMatchStrategy<MatchType> *matcher;
74};
75
76/* implementation follows */
77
78template <class MatchType>
79MemPool *ACLStrategised<MatchType>::Pool(NULL);
80
81template <class MatchType>
82void *
83ACLStrategised<MatchType>::operator new (size_t byteCount)
84{
85 /* derived classes with different sizes must implement their own new */
86 assert (byteCount == sizeof (ACLStrategised<MatchType>));
62e76326 87
5dee515e 88 if (!Pool)
62e76326 89 Pool = memPoolCreate("ACLStrategised", sizeof (ACLStrategised<MatchType>));
90
5dee515e 91 return memPoolAlloc(Pool);
92}
93
94template <class MatchType>
95void
96ACLStrategised<MatchType>::operator delete (void *address)
97{
98 memPoolFree (Pool, address);
99}
100
101template <class MatchType>
102void
103ACLStrategised<MatchType>::deleteSelf() const
104{
105 delete this;
106}
107
108template <class MatchType>
109ACLStrategised<MatchType>::~ACLStrategised()
110{
111 data->deleteSelf();
112}
113
114template <class MatchType>
115ACLStrategised<MatchType>::ACLStrategised(ACLData<MatchType> *newData, ACLMatchStrategy<MatchType> *theStrategy, char const *theType) : data (newData), type_(theType), matcher(theStrategy) {}
62e76326 116
5dee515e 117template <class MatchType>
118ACLStrategised<MatchType>::ACLStrategised (ACLStrategised const &old) : data (old.data->clone()), type_(old.type_), matcher (old.matcher)
62e76326 119{}
120
5dee515e 121template <class MatchType>
122ACLStrategised<MatchType> &
123ACLStrategised<MatchType>::operator= (ACLStrategised const &rhs)
124{
125 data = rhs.data->clone();
126 type_ = rhs.type_;
127 matcher = rhs.matcher;
128 return *this;
129}
130
131template <class MatchType>
132char const *
133ACLStrategised<MatchType>::typeString() const
134{
135 return type_;
136}
137
138template <class MatchType>
139void
140ACLStrategised<MatchType>::parse()
141{
142 data->parse();
143}
144
145template <class MatchType>
146int
147ACLStrategised<MatchType>::match(ACLChecklist *checklist)
148{
149 return matcher->match(data, checklist);
150}
151
152template <class MatchType>
153wordlist *
154ACLStrategised<MatchType>::dump() const
155{
156 return data->dump();
157}
158
159template <class MatchType>
160bool
161ACLStrategised<MatchType>::valid () const
162{
163 return data != NULL;
164}
165
166template <class MatchType>
167ACL *
168ACLStrategised<MatchType>::clone() const
169{
170 return new ACLStrategised(*this);
171}
172
173#endif /* SQUID_ACLSTRATEGISED_H */