Last change
on this file since 17 was
2,
checked in by Sam Hocevar, 17 years ago
|
- imported original 0.7.0 tarball
|
File size:
702 bytes
|
Rev | Line | |
---|
[2] | 1 | #ifndef __STACK_HPP_ |
---|
| 2 | #define __STACK_HPP_ |
---|
| 3 | #ifndef NO_LIBS |
---|
| 4 | #include "jmalloc.hpp" |
---|
| 5 | #else |
---|
| 6 | #include "fakelib.hpp" |
---|
| 7 | #endif |
---|
| 8 | |
---|
| 9 | #include <stdio.h> |
---|
| 10 | struct cons_cell; |
---|
| 11 | |
---|
| 12 | template<class T> class grow_stack // stack does not shrink |
---|
| 13 | { |
---|
| 14 | public : |
---|
| 15 | T **sdata; |
---|
| 16 | long son; |
---|
| 17 | |
---|
| 18 | grow_stack(int max_size) { sdata=(T **)jmalloc(max_size,"pointer stack"); son=0; } |
---|
| 19 | void push(T *data) |
---|
| 20 | { |
---|
| 21 | sdata[son]=data; |
---|
| 22 | son++; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | T *pop(long total) |
---|
| 26 | { if (total>son) { lbreak("stack underflow\n"); exit(0); } |
---|
| 27 | son-=total; |
---|
| 28 | return sdata[son]; |
---|
| 29 | } |
---|
| 30 | void clean_up() |
---|
| 31 | { |
---|
| 32 | if (son!=0) fprintf(stderr,"Warning cleaning up stack and not empty\n"); |
---|
| 33 | jfree(sdata); |
---|
| 34 | sdata=NULL; son=0; |
---|
| 35 | } |
---|
| 36 | } ; |
---|
| 37 | |
---|
| 38 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.