source: tags/svn.1.5.4/PROBE/PT_rangeCheck.h

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
File size: 2.5 KB
Line 
1// ============================================================= //
2//                                                               //
3//   File      : PT_rangeCheck.hxx                               //
4//   Purpose   : Check whether probe is inside region            //
5//                                                               //
6//   Coded by Ralf Westram (coder@reallysoft.de) in March 2011   //
7//   Institute of Microbiology (Technical University Munich)     //
8//   http://www.arb-home.de/                                     //
9//                                                               //
10// ============================================================= //
11
12#ifndef PT_RANGECHECK_HXX
13#define PT_RANGECHECK_HXX
14
15#ifndef PROBE_TREE_H
16#include "probe_tree.h"
17#endif
18#ifndef _GLIBCXX_MAP
19#include <map>
20#endif
21
22typedef std::map<int, int>   apos_cache;
23typedef apos_cache::iterator apos_iter;
24
25class Range {
26    int start; // -1 or minimum absolute position
27    int end;   // -1 or maximum absolute position
28    int probe_len; // length of checked probe
29
30    mutable const DataLoc *curr_match;
31    mutable apos_cache     cache;
32
33    int start_pos() const { return curr_match->apos; }
34    int min_end_pos() const { return start_pos()+probe_len-1; } // min abs. probe-end-pos
35
36    int calc_max_abs_pos() const;
37    int max_abs_pos() const {
38        apos_iter found                = cache.find(curr_match->name);
39        if (found != cache.end()) return found->second;
40        return cache[curr_match->name] = calc_max_abs_pos();
41    }
42
43    bool starts_before_start() const { return start != -1 && start_pos() < start; }
44    bool ends_behind_end() const {
45        return end != -1 &&
46            (min_end_pos() > end || // cheap check
47             start > max_abs_pos()); // expensive check
48    }
49
50public:
51    Range(int start_, int end_, int probe_len_)
52        : start(start_),
53          end(end_),
54          probe_len(probe_len_),
55          curr_match(NULL)
56    {}
57    Range(const Range& other)
58        : start(other.start),
59          end(other.end),
60          probe_len(other.probe_len),
61          curr_match(other.curr_match)
62    {}
63    DECLARE_ASSIGNMENT_OPERATOR(Range);
64
65    bool contains(const DataLoc& match) const {
66        // check if found 'match' of probe is inside the Range
67        curr_match  = &match;
68        bool inside = !starts_before_start() && !ends_behind_end();
69        curr_match  = NULL;
70        return inside;
71    }
72};
73
74#else
75#error PT_rangeCheck.hxx included twice
76#endif // PT_RANGECHECK_HXX
Note: See TracBrowser for help on using the repository browser.