Last change
on this file since 56 was
56,
checked in by Sam Hocevar, 14 years ago
|
- Add licensing terms to most C / C++ files (Ref #5).
|
File size:
1.1 KB
|
Rev | Line | |
---|
[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
| 4 | * |
---|
| 5 | * This software was released into the Public Domain. As with most public |
---|
| 6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
| 7 | * Jonathan Clark. |
---|
| 8 | */ |
---|
| 9 | |
---|
[2] | 10 | #ifndef __STACK_HPP_ |
---|
| 11 | #define __STACK_HPP_ |
---|
| 12 | #ifndef NO_LIBS |
---|
| 13 | #include "jmalloc.hpp" |
---|
| 14 | #else |
---|
| 15 | #include "fakelib.hpp" |
---|
| 16 | #endif |
---|
| 17 | |
---|
| 18 | #include <stdio.h> |
---|
| 19 | struct cons_cell; |
---|
| 20 | |
---|
| 21 | template<class T> class grow_stack // stack does not shrink |
---|
| 22 | { |
---|
| 23 | public : |
---|
| 24 | T **sdata; |
---|
| 25 | long son; |
---|
[30] | 26 | long smax; |
---|
[2] | 27 | |
---|
[30] | 28 | grow_stack(int max_size) { |
---|
| 29 | smax=max_size; |
---|
| 30 | son=0; |
---|
| 31 | sdata=(T **)jmalloc(sizeof(T *)*smax,"pointer stack"); |
---|
| 32 | } |
---|
[2] | 33 | void push(T *data) |
---|
| 34 | { |
---|
[30] | 35 | if (son>=smax) { lbreak("stack overflow (%ld)\n",smax); exit(1); } |
---|
[2] | 36 | sdata[son]=data; |
---|
| 37 | son++; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | T *pop(long total) |
---|
[30] | 41 | { if (total>son) { lbreak("stack underflow\n"); exit(1); } |
---|
[2] | 42 | son-=total; |
---|
| 43 | return sdata[son]; |
---|
| 44 | } |
---|
| 45 | void clean_up() |
---|
| 46 | { |
---|
| 47 | if (son!=0) fprintf(stderr,"Warning cleaning up stack and not empty\n"); |
---|
| 48 | jfree(sdata); |
---|
| 49 | sdata=NULL; son=0; |
---|
| 50 | } |
---|
| 51 | } ; |
---|
| 52 | |
---|
| 53 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.