aboutsummaryrefslogtreecommitdiff
path: root/src/stable/stack.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/stable/stack.h
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/stack.h')
-rw-r--r--src/stable/stack.h116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/stable/stack.h b/src/stable/stack.h
index f60907d..6b5f65a 100644
--- a/src/stable/stack.h
+++ b/src/stable/stack.h
@@ -13,73 +13,73 @@
13 13
14namespace Bu 14namespace Bu
15{ 15{
16 template<typename value, typename valuealloc=std::allocator<value> > 16 template<typename value, typename valuealloc=std::allocator<value> >
17 class Stack 17 class Stack
18 { 18 {
19 private: 19 private:
20 typedef struct Chunk 20 typedef struct Chunk
21 { 21 {
22 value *pValue; 22 value *pValue;
23 Chunk *pPrev; 23 Chunk *pPrev;
24 } Chunk; 24 } Chunk;
25 public: 25 public:
26 Stack() : 26 Stack() :
27 pTop( NULL ) 27 pTop( NULL )
28 { 28 {
29 } 29 }
30 30
31 virtual ~Stack() 31 virtual ~Stack()
32 { 32 {
33 } 33 }
34 34
35 void push( const value &v ) 35 void push( const value &v )
36 { 36 {
37 Chunk *pChnk = new Chunk; 37 Chunk *pChnk = new Chunk;
38 pChnk->pValue = va.allocate( 1 ); 38 pChnk->pValue = va.allocate( 1 );
39 va.construct( pChnk->pValue, v ); 39 va.construct( pChnk->pValue, v );
40 pChnk->pPrev = pTop; 40 pChnk->pPrev = pTop;
41 pTop = pChnk; 41 pTop = pChnk;
42 } 42 }
43 43
44 value &peek() 44 value &peek()
45 { 45 {
46 return *pTop->pValue; 46 return *pTop->pValue;
47 } 47 }
48 48
49 value &top() 49 value &top()
50 { 50 {
51 return *pTop->pValue; 51 return *pTop->pValue;
52 } 52 }
53 53
54 value pop() 54 value pop()
55 { 55 {
56 value ret( *pTop->pValue ); 56 value ret( *pTop->pValue );
57 57
58 Chunk *pChnk = pTop; 58 Chunk *pChnk = pTop;
59 pTop = pTop->pPrev; 59 pTop = pTop->pPrev;
60 60
61 va.destroy( pChnk->pValue ); 61 va.destroy( pChnk->pValue );
62 va.deallocate( pChnk->pValue, 1 ); 62 va.deallocate( pChnk->pValue, 1 );
63 delete pChnk; 63 delete pChnk;
64 64
65 return ret; 65 return ret;
66 } 66 }
67 67
68 void clear() 68 void clear()
69 { 69 {
70 while( !isEmpty() ) 70 while( !isEmpty() )
71 pop(); 71 pop();
72 } 72 }
73 73
74 bool isEmpty() 74 bool isEmpty()
75 { 75 {
76 return pTop == NULL; 76 return pTop == NULL;
77 } 77 }
78 78
79 private: 79 private:
80 Chunk *pTop; 80 Chunk *pTop;
81 valuealloc va; 81 valuealloc va;
82 }; 82 };
83} 83}
84 84
85#endif 85#endif