ARB
Main Page
Namespaces
Classes
Files
File List
File Members
NALIGNER
ali_tstack.hxx
Go to the documentation of this file.
1
// =============================================================== //
2
// //
3
// File : ali_tstack.hxx //
4
// Purpose : //
5
// //
6
// Institute of Microbiology (Technical University Munich) //
7
// http://www.arb-home.de/ //
8
// //
9
// =============================================================== //
10
11
#ifndef ALI_TSTACK_HXX
12
#define ALI_TSTACK_HXX
13
14
template
<
class
T>
15
class
ALI_TSTACK
:
virtual
Noncopyable
{
16
T
**array;
17
unsigned
long
size_of_array;
18
unsigned
long
next_elem;
19
20
public
:
21
ALI_TSTACK
(
unsigned
long
size) {
22
size_of_array = size;
23
next_elem = 0;
24
array = (
T
**) calloc((
unsigned
int
) size,
sizeof
(
T
));
25
}
26
~ALI_TSTACK
() {
27
if
(array)
28
free((
char
*) array);
29
}
30
unsigned
long
max_size
() {
31
return
size_of_array;
32
}
33
unsigned
long
akt_size
() {
34
return
next_elem;
35
}
36
void
push
(
T
value,
unsigned
long
count = 1) {
37
if
(next_elem + count - 1 >= size_of_array)
38
ali_fatal_error
(
"Access out of array"
,
"ALI_TSTACK::push()"
);
39
for
(; count > 0; count--)
40
(*array)[next_elem++] = value;
41
}
42
T
pop
(
unsigned
long
count = 1) {
43
if
(count == 0)
44
ali_fatal_error
(
"Nothing poped"
,
"ALI_TSTACK::pop()"
);
45
if
(next_elem - count + 1 <= 0)
46
ali_fatal_error
(
"Access out of array"
,
"ALI_TSTACK::pop()"
);
47
next_elem -= count;
48
return
(*array)[next_elem];
49
}
50
T
top
() {
51
if
(next_elem <= 0)
52
ali_fatal_error
(
"Access out of array"
,
"ALI_TSTACK::top()"
);
53
return
(*array)[next_elem - 1];
54
}
55
T
get
(
unsigned
long
position) {
56
if
(position >= next_elem) {
57
ali_fatal_error
(
"Access out of array"
,
"ALI_TSTACK::get()"
);
58
}
59
return
(*array)[position];
60
}
61
void
clear
() {
62
next_elem = 0;
63
}
64
};
65
66
#else
67
#error ali_tstack.hxx included twice
68
#endif // ALI_TSTACK_HXX
ALI_TSTACK::max_size
unsigned long max_size()
Definition:
ali_tstack.hxx:30
ALI_TSTACK::~ALI_TSTACK
~ALI_TSTACK()
Definition:
ali_tstack.hxx:26
ALI_TSTACK
Definition:
ali_tstack.hxx:15
ALI_TSTACK::push
void push(T value, unsigned long count=1)
Definition:
ali_tstack.hxx:36
ALI_TSTACK::clear
void clear()
Definition:
ali_tstack.hxx:61
ALI_TSTACK::akt_size
unsigned long akt_size()
Definition:
ali_tstack.hxx:33
ALI_TSTACK::top
T top()
Definition:
ali_tstack.hxx:50
ali_fatal_error
void ali_fatal_error(const char *message, const char *func)
Definition:
ali_main.cxx:85
ALI_TSTACK::ALI_TSTACK
ALI_TSTACK(unsigned long size)
Definition:
ali_tstack.hxx:21
ALI_TSTACK::pop
T pop(unsigned long count=1)
Definition:
ali_tstack.hxx:42
T
Definition:
trnsprob.h:20
Noncopyable
Definition:
arbtools.h:39
Generated by
1.8.8