File: ali_tarray.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 (65 lines) | stat: -rw-r--r-- 2,230 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
// =============================================================== //
//                                                                 //
//   File      : ali_tarray.hxx                                    //
//   Purpose   :                                                   //
//                                                                 //
//   Institute of Microbiology (Technical University Munich)       //
//   http://www.arb-home.de/                                       //
//                                                                 //
// =============================================================== //

#ifndef ALI_TARRAY_HXX
#define ALI_TARRAY_HXX

#ifndef ALI_TLIST_HXX
#include "ali_tlist.hxx"
#endif

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

public:
    ALI_TARRAY(unsigned long Size) {
        size_of_array = Size;
        array = (T **) calloc((unsigned int) Size, sizeof(T));
        if (array == 0)
            ali_fatal_error("Out of memory");
    }
    ALI_TARRAY(ALI_TLIST<T>* list) {
        size_of_array = list->cardinality();
        array = (T (*) []) calloc((unsigned int) size_of_array, sizeof(T));
        if (array == 0)
            ali_fatal_error("Out of memory");
        if (!list->is_empty()) {
            unsigned long l = 0;
            (*array)[l++] = list->first();
            while (list->is_next() && l < size_of_array)
                (*array)[l++] = list->next();
            if (list->is_next())
                ali_fatal_error("List inconsitent", "ALI_TARRAY::ALI_TARRAY()");
        }
    }
    ~ALI_TARRAY() {
        if (array)
            free((char *) array);
    }
    unsigned long size() {
        return size_of_array;
    }
    void set(unsigned long position, T value) {
        if (position >= size_of_array)
            ali_fatal_error("Access out of array", "ALI_TARRAY::set()");
        (*array)[position] = value;
    }
    T get(unsigned long position) {
        if (position >= size_of_array)
            ali_fatal_error("Access out of array", "ALI_TARRAY::get()");
        return (*array)[position];
    }
};

#else
#error ali_tarray.hxx included twice
#endif // ALI_TARRAY_HXX