From: hno <> Date: Mon, 9 May 2005 05:28:44 +0000 (+0000) Subject: Simple ListIterator template class for iterating over a ListContainer X-Git-Tag: SQUID_3_0_PRE4~769 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54687084c3e601fb67ce69cd3c86966d7048b2c0;p=thirdparty%2Fsquid.git Simple ListIterator template class for iterating over a ListContainer --- diff --git a/include/List.h b/include/List.h index bfe9eb6a16..fab93d276d 100644 --- a/include/List.h +++ b/include/List.h @@ -1,6 +1,6 @@ /* - * $Id: List.h,v 1.4 2004/08/30 05:12:29 robertc Exp $ + * $Id: List.h,v 1.5 2005/05/08 23:28:44 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -49,6 +49,7 @@ public: bool findAndTune(C const &); List *next; C element; + bool empty() const { return this == NULL; } private: CBDATA_CLASS(List); @@ -69,6 +70,25 @@ public: List *head; }; +template +class ListIterator +{ +public: + ListIterator(ListContainer const &list) : next_entry(list.head) {} + const C & next() { + List *entry = next_entry; + if (entry) + next_entry = entry->next; + return entry->element; + } + bool end() { + return next_entry != NULL; + } + +private: + List *next_entry; +}; + /* implementation follows */ #if 0 template