ARB
Main Page
Namespaces
Classes
Files
File List
File Members
NALIGNER
ali_tarray.hxx
Go to the documentation of this file.
1
// =============================================================== //
2
// //
3
// File : ali_tarray.hxx //
4
// Purpose : //
5
// //
6
// Institute of Microbiology (Technical University Munich) //
7
// http://www.arb-home.de/ //
8
// //
9
// =============================================================== //
10
11
#ifndef ALI_TARRAY_HXX
12
#define ALI_TARRAY_HXX
13
14
#ifndef ALI_TLIST_HXX
15
#include "
ali_tlist.hxx
"
16
#endif
17
18
template
<
class
T>
19
class
ALI_TARRAY
:
virtual
Noncopyable
{
20
T
**array;
21
unsigned
long
size_of_array;
22
23
public
:
24
ALI_TARRAY
(
unsigned
long
Size) {
25
size_of_array = Size;
26
array = (
T
**) calloc((
unsigned
int
) Size,
sizeof
(
T
));
27
ali_out_of_memory_if
(!array);
28
}
29
ALI_TARRAY
(
ALI_TLIST<T>
* list) {
30
size_of_array = list->
cardinality
();
31
array = (
T
(*) []) calloc((
unsigned
int
) size_of_array,
sizeof
(
T
));
32
ali_out_of_memory_if
(!array);
33
if
(!list->
is_empty
()) {
34
unsigned
long
l = 0;
35
(*array)[l++] = list->
first
();
36
while
(list->
has_next
() && l < size_of_array)
37
(*array)[l++] = list->
next
();
38
if
(list->
has_next
())
39
ali_fatal_error
(
"List inconsitent"
,
"ALI_TARRAY::ALI_TARRAY()"
);
40
}
41
}
42
~ALI_TARRAY
() {
43
if
(array)
44
free((
char
*) array);
45
}
46
unsigned
long
size
() {
47
return
size_of_array;
48
}
49
void
set
(
unsigned
long
position,
T
value) {
50
if
(position >= size_of_array)
51
ali_fatal_error
(
"Access out of array"
,
"ALI_TARRAY::set()"
);
52
(*array)[position] = value;
53
}
54
T
get
(
unsigned
long
position) {
55
if
(position >= size_of_array)
56
ali_fatal_error
(
"Access out of array"
,
"ALI_TARRAY::get()"
);
57
return
(*array)[position];
58
}
59
};
60
61
#else
62
#error ali_tarray.hxx included twice
63
#endif // ALI_TARRAY_HXX
ALI_TLIST::first
T first()
Definition:
ali_tlist.hxx:177
ali_out_of_memory_if
void ali_out_of_memory_if(bool cond)
Definition:
ali_misc.hxx:52
ALI_TARRAY::ALI_TARRAY
ALI_TARRAY(unsigned long Size)
Definition:
ali_tarray.hxx:24
ALI_TLIST::has_next
int has_next()
Definition:
ali_tlist.hxx:168
ALI_TLIST::cardinality
int cardinality()
Definition:
ali_tlist.hxx:162
ALI_TARRAY::set
void set(unsigned long position, T value)
Definition:
ali_tarray.hxx:49
ali_tlist.hxx
ALI_TARRAY::ALI_TARRAY
ALI_TARRAY(ALI_TLIST< T > *list)
Definition:
ali_tarray.hxx:29
ALI_TARRAY::~ALI_TARRAY
~ALI_TARRAY()
Definition:
ali_tarray.hxx:42
ALI_TLIST::is_empty
int is_empty()
Definition:
ali_tlist.hxx:165
ALI_TLIST::next
T next()
Definition:
ali_tlist.hxx:185
ali_fatal_error
void ali_fatal_error(const char *message, const char *func)
Definition:
ali_main.cxx:85
ALI_TLIST
Definition:
ali_tlist.hxx:32
ALI_TARRAY
Definition:
ali_tarray.hxx:19
T
Definition:
trnsprob.h:20
ALI_TARRAY::size
unsigned long size()
Definition:
ali_tarray.hxx:46
Noncopyable
Definition:
arbtools.h:39
Generated by
1.8.8