5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 #ifndef SQUID_GENERIC_H
33 #define SQUID_GENERIC_H
35 /** \todo CLEANUP: checks towrap this header properly */
40 template <class _Arg
, class _Result
>
41 struct unary_function
{
42 typedef _Arg argument_type
;
43 typedef _Result result_type
;
46 template <class L
, class T
>
47 T
& for_each(L
const &head
, T
& visitor
)
49 for (L
const *node
= &head
; node
; node
=node
->next
)
56 T
& for_each(dlink_list
const &collection
, T
& visitor
)
58 for (dlink_node
const *node
= collection
.head
; node
; node
=node
->next
)
59 visitor(*(typename
T::argument_type
const *)node
->data
);
67 template <class E
, class T
>
68 T
& for_each(Stack
<E
> const &collection
, T
& visitor
)
70 for (size_t index
= 0; index
< collection
.count
; ++index
)
71 visitor(*(typename
T::argument_type
const *)collection
.items
[index
]);
76 /* RBC 20030718 - use this to provide instance expecting classes a pointer to a
81 class InstanceToSingletonAdapter
: public C
85 void *operator new (size_t byteCount
) { return ::operator new (byteCount
);}
87 void operator delete (void *address
) { ::operator delete (address
);}
89 InstanceToSingletonAdapter(C
const *instance
) : theInstance (instance
) {}
91 C
const * operator-> () const {return theInstance
; }
93 C
* operator-> () {return const_cast<C
*>(theInstance
); }
95 C
const & operator * () const {return *theInstance
; }
97 C
& operator * () {return *const_cast<C
*>(theInstance
); }
99 operator C
const * () const {return theInstance
;}
101 operator C
*() {return const_cast<C
*>(theInstance
);}
104 C
const *theInstance
;
107 template <class InputIterator
, class Visitor
>
108 Visitor
& for_each(InputIterator from
, InputIterator to
, Visitor
& visitor
)
110 while (!(from
== to
)) {
111 typename
InputIterator::value_type
&value
= *from
;
119 /* generic ostream printer */
120 template <class Pointer
>
121 struct PointerPrinter
{
122 PointerPrinter(std::ostream
&astream
, std::string aDelimiter
) : os(astream
), delimiter (aDelimiter
) {}
124 void operator () (Pointer aNode
) {
125 os
<< *aNode
<< delimiter
;
129 std::string delimiter
;
132 #endif /* SQUID_GENERIC_H */