]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - include/Stack.h
Import of fix-ranges branch
[thirdparty/squid.git] / include / Stack.h
index 42365e338267bcbbf9f198cb55a0e002d9006253..c03a0f265553339f1fd3681ed65ed79ec1acb438 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: Stack.h,v 1.10 2001/01/12 00:37:12 wessels Exp $
+ * $Id: Stack.h,v 1.14 2003/01/23 00:36:47 robertc Exp $
  *
  * AUTHOR: Alex Rousskov
  *
@@ -31,8 +31,8 @@
  *  
  */
 
-#ifndef _STACK_H_
-#define _STACK_H_
+#ifndef SQUID_STACK_H
+#define SQUID_STACK_H
 
 #include "Array.h"
 
@@ -42,9 +42,27 @@ typedef Array Stack;
 #define stackInit arrayInit
 #define stackClean arrayClean
 #define stackDestroy arrayDestroy
-extern void *stackPop(Stack * s);
 #define stackPush arrayAppend
 #define stackPrePush arrayPreAppend
-extern void *stackTop(Stack * s);
 
-#endif /* ndef _STACK_H_ */
+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 */