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
41 template <class _Arg
, class _Result
>
42 struct unary_function
{
43 typedef _Arg argument_type
;
44 typedef _Result result_type
;
47 template <class L
, class T
>
48 T
& for_each(L
const &head
, T
& visitor
)
50 for (L
const *node
= &head
; node
; node
=node
->next
)
57 T
& for_each(dlink_list
const &collection
, T
& visitor
)
59 for (dlink_node
const *node
= collection
.head
; node
; node
=node
->next
)
60 visitor(*(typename
T::argument_type
const *)node
->data
);
68 template <class E
, class T
>
69 T
& for_each(Stack
<E
> const &collection
, T
& visitor
)
71 for (size_t index
= 0; index
< collection
.count
; ++index
)
72 visitor(*(typename
T::argument_type
const *)collection
.items
[index
]);
77 /* RBC 20030718 - use this to provide instance expecting classes a pointer to a
82 class InstanceToSingletonAdapter
: public C
86 void *operator new (size_t byteCount
) { return ::operator new (byteCount
);}
88 void operator delete (void *address
) { ::operator delete (address
);}
90 InstanceToSingletonAdapter(C
const *instance
) : theInstance (instance
) {}
92 C
const * operator-> () const {return theInstance
; }
94 C
* operator-> () {return const_cast<C
*>(theInstance
); }
96 C
const & operator * () const {return *theInstance
; }
98 C
& operator * () {return *const_cast<C
*>(theInstance
); }
100 operator C
const * () const {return theInstance
;}
102 operator C
*() {return const_cast<C
*>(theInstance
);}
105 C
const *theInstance
;
108 template <class InputIterator
, class Visitor
>
109 Visitor
& for_each(InputIterator from
, InputIterator to
, Visitor
& visitor
)
111 while (!(from
== to
)) {
112 typename
InputIterator::value_type
&value
= *from
;
120 /* generic ostream printer */
121 template <class Pointer
>
122 struct PointerPrinter
{
123 PointerPrinter(std::ostream
&astream
, std::string aDelimiter
) : os(astream
), delimiter (aDelimiter
) {}
125 void operator () (Pointer aNode
) {
126 os
<< *aNode
<< delimiter
;
130 std::string delimiter
;
133 #endif /* SQUID_GENERIC_H */