source: abuse/trunk/src/stack.cpp @ 57

Last change on this file since 57 was 56, checked in by Sam Hocevar, 14 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 783 bytes
RevLine 
[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
10#include "config.h"
11
[2]12#ifndef __STACK_HPP_
13#define __STACK_HPP_
14
15template <class T> grow_stack        // stack does not shrink
16{
17  public :
18  T **sdata;
19  long ssize,son;
20
21  grow_stack() { sdata=NULL; ssize=0; son=0; }
22  void *push(T *data)
23  { if (son>=ssize)
24    { ssize+=0x100;
25      sdata=(T **)jrealloc(sdata,sizeof(T *)*ssize,"stack");
26    }
27    sdata[son++]=data;
28  }
29   
30  T *pop(long total)
31  { if (son>total) { lbreak("stack underflow\n"); exit(0); }
32    son-=total;
33    return sdata[son];
34  }
35} ;
36
37#endif
Note: See TracBrowser for help on using the repository browser.