]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Simple ListIterator template class for iterating over a ListContainer
authorhno <>
Mon, 9 May 2005 05:28:44 +0000 (05:28 +0000)
committerhno <>
Mon, 9 May 2005 05:28:44 +0000 (05:28 +0000)
include/List.h

index bfe9eb6a16f002a26a9f9c04236addce09702bbe..fab93d276d29553b4aff51476bee3266a46ef6fb 100644 (file)
@@ -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<C> *head;
 };
 
+template<class C>
+class ListIterator
+{
+public:
+    ListIterator(ListContainer<C> const &list) : next_entry(list.head) {}
+    const C & next() {
+       List<C> *entry = next_entry;
+       if (entry)
+           next_entry = entry->next;
+       return entry->element;
+    }
+    bool end() {
+       return next_entry != NULL;
+    }
+
+private:
+    List<C> *next_entry;
+};
+
 /* implementation follows */
 #if 0
 template <class C>