source: branches/port5/NALIGNER/ali_tstack.hxx

Last change on this file was 4912, checked in by westram, 18 years ago
  • untabified + indented
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1
2
3#ifndef _ALI_TSTACK_INC_
4#define _ALI_TSTACK_INC_
5
6// #include <malloc.h>
7#include "ali_misc.hxx"
8
9template<class T>
10class ALI_TSTACK {
11    T **array;
12    unsigned long size_of_array;
13    unsigned long next_elem;
14
15public:
16    ALI_TSTACK(unsigned long size) {
17        size_of_array = size;
18        next_elem = 0;
19        array = (T **) calloc((unsigned int) size, sizeof(T));
20        //array = (T (*) [1]) calloc((unsigned int) size, sizeof(T));
21    }
22    ~ALI_TSTACK(void) {
23        if (array)
24            free((char *) array);
25    }
26    unsigned long max_size(void) {
27        return size_of_array;
28    }
29    unsigned long akt_size(void) {
30        return next_elem;
31    }
32    void push(T value, unsigned long count = 1) {
33        if (next_elem + count - 1 >= size_of_array)
34            ali_fatal_error("Access out of array","ALI_TSTACK::push()");
35        for (; count > 0; count--)
36            (*array)[next_elem++] = value;
37    }
38    T pop(unsigned long count = 1) {
39        if (count == 0)
40            ali_fatal_error("Nothing poped","ALI_TSTACK::pop()");
41        if (next_elem - count + 1 <= 0)
42            ali_fatal_error("Access out of array","ALI_TSTACK::pop()");
43        next_elem -= count;
44        return (*array)[next_elem];
45    }
46    T top(void) {
47        if (next_elem <= 0)
48            ali_fatal_error("Access out of array","ALI_TSTACK::top()");
49        return (*array)[next_elem - 1];
50    }
51    T get(unsigned long position) {
52        if (position >= next_elem) {
53            ali_fatal_error("Access out of array","ALI_TSTACK::get()");
54        }
55        return (*array)[position];
56    }
57    void clear(void) {
58        next_elem = 0;
59    }
60};
61
62#endif
63
Note: See TracBrowser for help on using the repository browser.