source: branches/stable/NALIGNER/ali_tstack.hxx

Last change on this file was 7623, checked in by westram, 8 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_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
14template<class T>
15class ALI_TSTACK : virtual Noncopyable {
16    T **array;
17    unsigned long size_of_array;
18    unsigned long next_elem;
19
20public:
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
Note: See TracBrowser for help on using the repository browser.