File: ali_tstack.hxx

package info (click to toggle)
arb 6.0.6-8
  • links: PTS, VCS
  • area: non-free
  • in suites: sid, trixie
  • size: 66,204 kB
  • sloc: ansic: 394,911; cpp: 250,290; makefile: 19,644; sh: 15,879; perl: 10,473; fortran: 6,019; ruby: 683; xml: 503; python: 53; awk: 32
file content (68 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// =============================================================== //
//                                                                 //
//   File      : ali_tstack.hxx                                    //
//   Purpose   :                                                   //
//                                                                 //
//   Institute of Microbiology (Technical University Munich)       //
//   http://www.arb-home.de/                                       //
//                                                                 //
// =============================================================== //

#ifndef ALI_TSTACK_HXX
#define ALI_TSTACK_HXX

template<class T>
class ALI_TSTACK : virtual Noncopyable {
    T **array;
    unsigned long size_of_array;
    unsigned long next_elem;

public:
    ALI_TSTACK(unsigned long size) {
        size_of_array = size;
        next_elem = 0;
        array = (T **) calloc((unsigned int) size, sizeof(T));
    }
    ~ALI_TSTACK() {
        if (array)
            free((char *) array);
    }
    unsigned long max_size() {
        return size_of_array;
    }
    unsigned long akt_size() {
        return next_elem;
    }
    void push(T value, unsigned long count = 1) {
        if (next_elem + count - 1 >= size_of_array)
            ali_fatal_error("Access out of array", "ALI_TSTACK::push()");
        for (; count > 0; count--)
            (*array)[next_elem++] = value;
    }
    T pop(unsigned long count = 1) {
        if (count == 0)
            ali_fatal_error("Nothing poped", "ALI_TSTACK::pop()");
        if (next_elem - count + 1 <= 0)
            ali_fatal_error("Access out of array", "ALI_TSTACK::pop()");
        next_elem -= count;
        return (*array)[next_elem];
    }
    T top() {
        if (next_elem <= 0)
            ali_fatal_error("Access out of array", "ALI_TSTACK::top()");
        return (*array)[next_elem - 1];
    }
    T get(unsigned long position) {
        if (position >= next_elem) {
            ali_fatal_error("Access out of array", "ALI_TSTACK::get()");
        }
        return (*array)[position];
    }
    void clear() {
        next_elem = 0;
    }
};

#else
#error ali_tstack.hxx included twice
#endif // ALI_TSTACK_HXX