]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Convert Stack to template based code, to allow typesafe composing on Vectors
authorrobertc <>
Wed, 22 Jan 2003 17:05:41 +0000 (17:05 +0000)
committerrobertc <>
Wed, 22 Jan 2003 17:05:41 +0000 (17:05 +0000)
include/Stack.h
lib/Makefile.am
lib/Stack.c [deleted file]
src/HttpHdrRange.cc
src/HttpHeader.cc
src/cbdata.cc
src/errorpage.cc

index 7248f1d6003fbd64cf225bb8e7d36955ad52baf3..c044cbced1225930e6b858335d082219905137ca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: Stack.h,v 1.12 2002/10/13 20:34:51 robertc Exp $
+ * $Id: Stack.h,v 1.13 2003/01/22 10:05:42 robertc Exp $
  *
  * AUTHOR: Alex Rousskov
  *
@@ -42,9 +42,27 @@ typedef Array Stack;
 #define stackInit arrayInit
 #define stackClean arrayClean
 #define stackDestroy arrayDestroy
-SQUIDCEXTERN void *stackPop(Stack * s);
 #define stackPush arrayAppend
 #define stackPrePush arrayPreAppend
-SQUIDCEXTERN void *stackTop(Stack * s);
 
+template <class S>
+typename S::value_type
+stackPop(S * s)
+{
+    assert(s);
+    if (!s->count)
+       return typename S::value_type();
+    typename S::value_type result = s->items[--s->count];
+    s->items[s->count] = typename S::value_type();
+    return result;
+}
+
+/* todo, fatal on empty Top call */
+template <class S>
+typename S::value_type
+stackTop(S * s)
+{
+    assert(s);
+    return s->count ? s->items[s->count - 1] : typename S::value_type();
+}
 #endif /* SQUID_STACK_H */
index 418e85dc7882e979579129605ef0fa1cce377f22..ea39f86fc5e553cab66d98c03be0e340d65fc98f 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 #
-#  $Id: Makefile.am,v 1.6 2003/01/18 14:06:32 robertc Exp $
+#  $Id: Makefile.am,v 1.7 2003/01/22 10:05:41 robertc Exp $
 #
 
 if ENABLE_XPROF_STATS
@@ -50,7 +50,6 @@ libmiscutil_a_SOURCES = \
        safe_inet_addr.c \
        $(SNPRINTFSOURCE) \
        splay.c \
-       Stack.c \
        stub_memaccount.c \
        util.c \
        uudecode.c \
diff --git a/lib/Stack.c b/lib/Stack.c
deleted file mode 100644 (file)
index a8e0703..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * $Id: Stack.c,v 1.11 2001/01/12 00:37:12 wessels Exp $
- *
- * AUTHOR: Alex Rousskov
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *  
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *  
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- */
-
-/*
- * Stack is a (void*) stack with unlimited capacity; based on Array
- */
-
-
-#include "config.h"
-#if HAVE_ASSERT_H
-#include <assert.h>
-#endif
-#if HAVE_STRING_H
-#include <string.h>
-#endif
-#include "util.h"
-#include "Stack.h"
-
-
-void *
-stackPop(Stack * s)
-{
-    assert(s);
-    return s->count ? s->items[--s->count] : NULL;
-}
-
-void *
-stackTop(Stack * s)
-{
-    assert(s);
-    return s->count ? s->items[s->count - 1] : NULL;
-}
index d68f65f80f58ca74077a42060667e9b343eb4de1..7abe5eecac04845b3c5bf5638fdcdb1c1d198d84 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHdrRange.cc,v 1.28 2002/10/15 08:03:29 robertc Exp $
+ * $Id: HttpHdrRange.cc,v 1.29 2003/01/22 10:05:43 robertc Exp $
  *
  * DEBUG: section 64    HTTP Range Header
  * AUTHOR: Alex Rousskov
@@ -276,7 +276,7 @@ HttpHdrRange *
 httpHdrRangeDup(const HttpHdrRange * range)
 {
     HttpHdrRange *dup;
-    int i;
+    size_t i;
     assert(range);
     dup = httpHdrRangeCreate();
     stackPrePush(&dup->specs, range->specs.count);
@@ -309,7 +309,7 @@ httpHdrRangePackInto(const HttpHdrRange * range, Packer * p)
 int
 httpHdrRangeCanonize(HttpHdrRange * range, ssize_t clen)
 {
-    int i;
+    size_t i;
     HttpHdrRangeSpec *spec;
     HttpHdrRangePos pos = HttpHdrRangeInitPos;
     Stack goods;
@@ -364,9 +364,9 @@ HttpHdrRangeSpec *
 httpHdrRangeGetSpec(const HttpHdrRange * range, HttpHdrRangePos * pos)
 {
     assert(range);
-    assert(pos && *pos >= -1 && *pos < range->specs.count);
+    assert(pos && *pos >= -1 && *pos < (ssize_t)range->specs.count);
     (*pos)++;
-    if (*pos < range->specs.count)
+    if (*pos < (ssize_t)range->specs.count)
        return (HttpHdrRangeSpec *) range->specs.items[*pos];
     else
        return NULL;
index 6736de823ce3d92f02effa9d8622b1d3243fad70..3f4f937f7ebc93192775809a7f7d7b53c72ac52b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeader.cc,v 1.82 2002/12/06 23:19:13 hno Exp $
+ * $Id: HttpHeader.cc,v 1.83 2003/01/22 10:05:43 robertc Exp $
  *
  * DEBUG: section 55    HTTP Header
  * AUTHOR: Alex Rousskov
@@ -457,8 +457,8 @@ HttpHeaderEntry *
 httpHeaderGetEntry(const HttpHeader * hdr, HttpHeaderPos * pos)
 {
     assert(hdr && pos);
-    assert(*pos >= HttpHeaderInitPos && *pos < hdr->entries.count);
-    for ((*pos)++; *pos < hdr->entries.count; (*pos)++) {
+    assert(*pos >= HttpHeaderInitPos && *pos < (ssize_t)hdr->entries.count);
+    for ((*pos)++; *pos < (ssize_t)hdr->entries.count; (*pos)++) {
        if (hdr->entries.items[*pos])
            return (HttpHeaderEntry*)hdr->entries.items[*pos];
     }
@@ -570,7 +570,7 @@ void
 httpHeaderDelAt(HttpHeader * hdr, HttpHeaderPos pos)
 {
     HttpHeaderEntry *e;
-    assert(pos >= HttpHeaderInitPos && pos < hdr->entries.count);
+    assert(pos >= HttpHeaderInitPos && pos < (ssize_t)hdr->entries.count);
     e = (HttpHeaderEntry*)hdr->entries.items[pos];
     hdr->entries.items[pos] = NULL;
     /* decrement header length, allow for ": " and crlf */
index 6c59c608bd7f1a58608ad72dbf3ae6a37eaa4c71..7daa9584a398f0e72e2dd720396af52ecd220e43 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cbdata.cc,v 1.49 2002/10/25 03:13:51 robertc Exp $
+ * $Id: cbdata.cc,v 1.50 2003/01/22 10:05:43 robertc Exp $
  *
  * DEBUG: section 45    Callback Data Registry
  * ORIGINAL AUTHOR: Duane Wessels
@@ -384,7 +384,7 @@ cbdataDump(StoreEntry * sentry)
 template <class T>
 T& for_each(Stack const &collection, T& visitor)
 {
-    for (int index = 0; index < collection.count; ++index)
+    for (size_t index = 0; index < collection.count; ++index)
        visitor(*(typename T::argument_type const *)collection.items[index]);
     return visitor;
 };
index 5b5423935e78962e649ba18a75ef1b97f19afe85..f61315d76468f19d884981b76204a430ca52d656 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: errorpage.cc,v 1.180 2002/10/25 07:36:32 robertc Exp $
+ * $Id: errorpage.cc,v 1.181 2003/01/22 10:05:43 robertc Exp $
  *
  * DEBUG: section 4     Error Generation
  * AUTHOR: Duane Wessels
@@ -230,9 +230,9 @@ errorPageId(const char *page_name)
        if (strcmp(err_type_str[i], page_name) == 0)
            return i;
     }
-    for (i = 0; i < ErrorDynamicPages.count; i++) {
-       if (strcmp(((ErrorDynamicPageInfo *) ErrorDynamicPages.items[i])->page_name, page_name) == 0)
-           return i + ERR_MAX;
+    for (size_t in = 0; in < ErrorDynamicPages.count; in++) {
+       if (strcmp(((ErrorDynamicPageInfo *) ErrorDynamicPages.items[in])->page_name, page_name) == 0)
+           return in + ERR_MAX;
     }
     return ERR_NONE;
 }
@@ -255,7 +255,7 @@ errorPageName(int pageId)
 {
     if (pageId >= ERR_NONE && pageId < ERR_MAX)                /* common case */
        return err_type_str[pageId];
-    if (pageId >= ERR_MAX && pageId - ERR_MAX < ErrorDynamicPages.count)
+    if (pageId >= ERR_MAX && pageId - ERR_MAX < (ssize_t)ErrorDynamicPages.count)
        return ((ErrorDynamicPageInfo *) ErrorDynamicPages.
            items[pageId - ERR_MAX])->page_name;
     return "ERR_UNKNOWN";      /* should not happen */