source: tags/svn.1.5.4/NALIGNER/ali_tarray.hxx

Last change on this file was 7623, checked in by westram, 14 years ago
  • merge from dev [7450] [7452] [7456] [7457] [7458] [7459] [7460] [7461] [7464] [7465] [7466] [7467] [7468] [7469] [7482]
    • tweaked compiler options
      • activated -Weffc++
        • postfilter warnings where Scott Meyers' advices are too general.
          • base classes should not always have virtual destructors, since that renders tiny classes useless and
          • members should not always be initialized via initialization list, since that often violates the DRY principle
        • fix gcc's inability to detect that Noncopyable implements a private copy-ctor and op=
        • this slows down complete ARB recompilation by ~5%
    • added -Wold-style-cast (inactive)
    • removed -Wno-non-template-friend added in [7447]
  • postcompile.pl
    • added option —original to show unmodified compiler output
  • declared op= for classes which had a copy-ctor
  • moved op= macros to arbtools.h
  • derived classes containing pointers from Noncopyable (use Noncopyable virtually) or
  • made them copyable if needed (awt_mask_item, KnownDB, Code, AWT_registered_itemtype, GEN_gene, PosGene, PartialSequence, PlugIn, Range, Convaln_exception)
  • other related changes
    • user mask destruction working now
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
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
18template<class T>
19class ALI_TARRAY : virtual Noncopyable {
20    T **array;
21    unsigned long size_of_array;
22
23public:
24    ALI_TARRAY(unsigned long Size) {
25        size_of_array = Size;
26        array = (T **) calloc((unsigned int) Size, sizeof(T));
27        if (array == 0)
28            ali_fatal_error("Out of memory");
29    }
30    ALI_TARRAY(ALI_TLIST<T>* list) {
31        unsigned long l = 0;
32        size_of_array = list->cardinality();
33        array = (T (*) []) calloc((unsigned int) size_of_array, sizeof(T));
34        if (array == 0)
35            ali_fatal_error("Out of memory");
36        if (!list->is_empty()) {
37            (*array)[l++] = list->first();
38            while (list->is_next() && l < size_of_array)
39                (*array)[l++] = list->next();
40            if (list->is_next())
41                ali_fatal_error("List inconsitent", "ALI_TARRAY::ALI_TARRAY()");
42        }
43    }
44    ~ALI_TARRAY() {
45        if (array)
46            free((char *) array);
47    }
48    unsigned long size() {
49        return size_of_array;
50    }
51    void set(unsigned long position, T value) {
52        if (position >= size_of_array)
53            ali_fatal_error("Access out of array", "ALI_TARRAY::set()");
54        (*array)[position] = value;
55    }
56    T get(unsigned long position) {
57        if (position >= size_of_array)
58            ali_fatal_error("Access out of array", "ALI_TARRAY::get()");
59        return (*array)[position];
60    }
61};
62
63#else
64#error ali_tarray.hxx included twice
65#endif // ALI_TARRAY_HXX
Note: See TracBrowser for help on using the repository browser.