aboutsummaryrefslogtreecommitdiff
path: root/src/stack.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-10-20 20:51:59 +0000
committerMike Buland <eichlan@xagasoft.com>2007-10-20 20:51:59 +0000
commit6e106a2cc52e3857cbd55d67d54b4589f3425c51 (patch)
tree370dbdcd1f4c2b047b183387c052a339c25e8591 /src/stack.h
parentaddca63bba3ddaf212e44cdf16e95038b0a5bf3e (diff)
downloadlibbu++-6e106a2cc52e3857cbd55d67d54b4589f3425c51.tar.gz
libbu++-6e106a2cc52e3857cbd55d67d54b4589f3425c51.tar.bz2
libbu++-6e106a2cc52e3857cbd55d67d54b4589f3425c51.tar.xz
libbu++-6e106a2cc52e3857cbd55d67d54b4589f3425c51.zip
Made the logger use a uint32_t for it's mask, no more negative confusion. Also
brought back the formula class with some cool twists, and added a basic stack class, very cute, fast, and little.
Diffstat (limited to '')
-rw-r--r--src/stack.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/stack.h b/src/stack.h
new file mode 100644
index 0000000..955332d
--- /dev/null
+++ b/src/stack.h
@@ -0,0 +1,71 @@
1#ifndef BU_STACK_H
2#define BU_STACK_H
3
4#include <memory>
5
6namespace Bu
7{
8 template<typename value, typename valuealloc=std::allocator<value> >
9 class Stack
10 {
11 private:
12 typedef struct Chunk
13 {
14 value *pValue;
15 Chunk *pPrev;
16 } Chunk;
17 public:
18 Stack() :
19 pTop( NULL )
20 {
21 }
22
23 virtual ~Stack()
24 {
25 }
26
27 void push( const value &v )
28 {
29 Chunk *pChnk = new Chunk;
30 pChnk->pValue = va.allocate( 1 );
31 va.construct( pChnk->pValue, v );
32 pChnk->pPrev = pTop;
33 pTop = pChnk;
34 }
35
36 value &peek()
37 {
38 return *pTop->pValue;
39 }
40
41 value &top()
42 {
43 return *pTop->pValue;
44 }
45
46 value pop()
47 {
48 value ret( *pTop->pValue );
49
50 Chunk *pChnk = pTop;
51 pTop = pTop->pPrev;
52
53 va.destroy( pChnk->pValue );
54 va.deallocate( pChnk->pValue, 1 );
55 delete pChnk;
56
57 return ret;
58 }
59
60 bool isEmpty()
61 {
62 return pTop == NULL;
63 }
64
65 private:
66 Chunk *pTop;
67 valuealloc va;
68 };
69}
70
71#endif