/*
- * $Id: Stack.h,v 1.14 2003/01/23 00:36:47 robertc Exp $
+ * $Id: Stack.h,v 1.15 2003/07/14 10:36:41 robertc Exp $
*
* AUTHOR: Alex Rousskov
*
#include "Array.h"
-typedef Array Stack;
+/* RBC: 20030714 Composition might be better long-term, but for now,
+ * there's no reason to do so.
+ */
-#define stackCreate arrayCreate
-#define stackInit arrayInit
-#define stackClean arrayClean
-#define stackDestroy arrayDestroy
-#define stackPush arrayAppend
-#define stackPrePush arrayPreAppend
+template <class S = void *>
-template <class S>
-typename S::value_type
-stackPop(S * s)
+class Stack : public Vector<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();
-}
+public:
+ typedef typename Vector<S>::value_type value_type;
+ typedef typename Vector<S>::pointer pointer;
+ value_type pop()
+ {
+ if (!count)
+ return value_type();
+
+ value_type result = items[--count];
+
+ items[count] = value_type();
+
+ return result;
+ }
+
+ /* todo, fatal on empty Top call */
+ value_type top() const
+ {
+ return count ? items[count - 1] : value_type();
+ }
+};
+
#endif /* SQUID_STACK_H */
/*
- * $Id: Generic.h,v 1.4 2003/02/21 22:50:05 robertc Exp $
+ * $Id: Generic.h,v 1.5 2003/07/14 10:36:41 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
return visitor;
}
-
template <class T>
T& for_each(dlink_list const &collection, T& visitor)
{
return visitor;
}
+template <class S>
+
+class Stack;
+
+template <class E, class T>
+T& for_each(Stack<E> const &collection, T& visitor)
+{
+ for (size_t index = 0; index < collection.count; ++index)
+ visitor(*(typename T::argument_type const *)collection.items[index]);
+
+ return visitor;
+};
+
#endif /* SQUID_GENERIC_H */
/*
- * $Id: cbdata.cc,v 1.57 2003/07/14 08:21:56 robertc Exp $
+ * $Id: cbdata.cc,v 1.58 2003/07/14 10:36:42 robertc Exp $
*
* DEBUG: section 45 Callback Data Registry
* ORIGINAL AUTHOR: Duane Wessels
int type;
#if CBDATA_DEBUG
- void addHistory(char const *label, char const *file, int line) const
+ void addHistory(char const *label, char const *file, int line)
{
- if (calls->count > 1000)
+ if (calls.size() > 1000)
return;
- stackPush (calls, new CBDataCall(label, file, line));
+ calls.push_back(new CBDataCall(label, file, line));
}
dlink_node link;
const char *file;
int line;
- Stack *calls;
+ Stack<CBDataCall*> calls;
#endif
/* cookie used while debugging */
#if CBDATA_DEBUG
CBDataCall *aCall;
- while ((aCall = (CBDataCall *)stackPop(calls)))
+ while ((aCall = calls.pop()))
delete aCall;
- stackDestroy(calls);
-
#endif
FREE *free_func = cbdata_index[type].free_func;
p->file = file;
p->line = line;
- p->calls = stackCreate();
+ p->calls = Stack<CBDataCall *> ();
p->addHistory("Alloc", file, line);
dlinkAdd(p, &p->link, &cbdataEntries);
debug(45, 3) ("cbdataAlloc: %p %s:%d\n", &p->data, file, line);
#if CBDATA_DEBUG
-template <class T>
-T& for_each(Stack const &collection, T& visitor)
-{
- for (size_t index = 0; index < collection.count; ++index)
- visitor(*(typename T::argument_type const *)collection.items[index]);
-
- return visitor;
-};
-
struct CBDataCallDumper : public unary_function<CBDataCall, void>
{
CBDataCallDumper (StoreEntry *anEntry):where(anEntry){}
CBDataDumper::operator()(x);
storeAppendPrintf(where, "\n");
storeAppendPrintf(where, "Action\tFile\tLine\n");
- for_each (*x.calls,callDumper);
+ for_each (x.calls,callDumper);
storeAppendPrintf(where, "\n");
}
/*
- * $Id: squid.h,v 1.235 2003/04/25 21:45:29 robertc Exp $
+ * $Id: squid.h,v 1.236 2003/07/14 10:36:42 robertc Exp $
*
* AUTHOR: Duane Wessels
*
#include "ssl_support.h"
#endif
-#include "Stack.h"
-
/* Needed for poll() on Linux at least */
#if HAVE_POLL
#ifndef POLLRDNORM
/*
- * $Id: store.cc,v 1.570 2003/06/26 12:51:58 robertc Exp $
+ * $Id: store.cc,v 1.571 2003/07/14 10:36:42 robertc Exp $
*
* DEBUG: section 20 Storage Manager
* AUTHOR: Harvest Derived
#if DELAY_POOLS
#include "DelayPools.h"
#endif
+#include "Stack.h"
static STMCB storeWriteComplete;
/*
* local variables
*/
-static Stack LateReleaseStack;
+static Stack<StoreEntry*> LateReleaseStack;
MemPool *StoreEntry::pool = NULL;
void *
*/
e->lock_count++;
e->setReleaseFlag();
- stackPush(&LateReleaseStack, e);
+ LateReleaseStack.push_back(e);
PROF_stop(storeRelease);
return;
} else {
}
for (i = 0; i < 10; i++) {
- e = static_cast<StoreEntry*>(stackPop(&LateReleaseStack));
+ e = LateReleaseStack.pop();
if (e == NULL) {
/* done! */
mem_policy = createRemovalPolicy(Config.memPolicy);
storeDigestInit();
storeLogOpen();
- stackInit(&LateReleaseStack);
eventAdd("storeLateRelease", storeLateRelease, NULL, 1.0, 1);
storeDirInit();
storeRebuildStart();
#
# Makefile for the Squid Object Cache server
#
-# $Id: Makefile.am,v 1.12 2003/07/10 01:31:51 robertc Exp $
+# $Id: Makefile.am,v 1.13 2003/07/14 10:36:44 robertc Exp $
#
AUTOMAKE_OPTIONS = subdir-objects
## Sort by dependencies - test lowest layers first
TESTS = debug \
syntheticoperators \
+ StackTest \
rfc1738 \
refcount\
splay\
refcount\
rfc1738\
splay \
+ StackTest \
syntheticoperators
LDADD = -L$(top_builddir)/lib -lmiscutil
splay_SOURCES = splay.cc
+StackTest_SOURCES = StackTest.cc test_tools.cc
+
syntheticoperators_SOURCES = syntheticoperators.cc test_tools.cc
rfc1738_SOURCES = rfc1738.cc
--- /dev/null
+
+/*
+ * $Id: StackTest.cc,v 1.1 2003/07/14 10:36:44 robertc Exp $
+ *
+ * DEBUG: section 19 Store Memory Primitives
+ * AUTHOR: Robert Collins
+ *
+ * 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.
+ *
+ * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
+ */
+
+#include "squid.h"
+#include "Stack.h"
+
+int
+main (int argc, char *argv)
+{
+ Stack<int> aStack;
+ assert (aStack.size() == 0);
+ aStack.push_back(2);
+ assert (aStack.size() == 1);
+ assert (aStack.top() == 2);
+ assert (aStack.pop() == 2);
+ assert (aStack.size() == 0);
+ Stack<> oldStack;
+ assert (oldStack.size() == 0);
+ oldStack.push_back(&aStack);
+ assert (oldStack.size() == 1);
+ assert (oldStack.top() == &aStack);
+ assert (oldStack.pop() == &aStack);
+ assert (oldStack.size() == 0);
+ return 0;
+}