ARB
RangeList.h
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : RangeList.h //
4 // Purpose : //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in April 2012 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // ============================================================= //
11 
12 #ifndef RANGELIST_H
13 #define RANGELIST_H
14 
15 #ifndef POS_RANGE_H
16 #include <pos_range.h>
17 #endif
18 #ifndef _GLIBCXX_SET
19 #include <set>
20 #endif
21 
22 #define rl_assert(cond) arb_assert(cond)
23 
25  bool operator()(const PosRange& r1, const PosRange& r2) const {
26  // true if r1 is less than r2
27  // overlapping and adjacent ranges are never less than each other!
28 
29  rl_assert(!r1.is_empty());
30  rl_assert(!r2.is_empty());
31 
32  return r1.end()<(r2.start()-1);
33  }
34 };
35 
36 
37 class RangeList {
38  typedef std::set<PosRange, less_DistinctPosRange> range_set;
39 
40  range_set ranges;
41 
42  void add_combined(const PosRange& range, range_set::const_iterator found);
43 
44 public:
45 
46  typedef range_set::const_iterator iterator;
47  typedef range_set::const_reverse_iterator reverse_iterator;
48 
49  size_t size() const { return ranges.size(); }
50 
51  iterator begin() const { return ranges.begin(); }
52  iterator end() const { return ranges.end(); }
53 
54  reverse_iterator rbegin() const { return ranges.rbegin(); }
55  reverse_iterator rend() const { return ranges.rend(); }
56 
58 
59  bool empty() const { return ranges.empty(); }
60 
61  void add(const PosRange& range) {
62  if (!range.is_empty()) {
63  iterator found = ranges.find(range);
64  if (found != ranges.end()) add_combined(range, found); // overlapping or adjacent to range
65  else ranges.insert(range);
66  }
67  }
68 };
69 
70 RangeList build_RangeList_from_string(const char *SAI_data, const char *set_bytes, bool invert);
71 
72 #else
73 #error RangeList.h included twice
74 #endif // RANGELIST_H
int start() const
Definition: pos_range.h:57
range_set::const_iterator iterator
Definition: RangeList.h:46
size_t size() const
Definition: RangeList.h:49
void add(const PosRange &range)
Definition: RangeList.h:61
bool is_empty() const
Definition: pos_range.h:69
bool empty() const
Definition: RangeList.h:59
RangeList build_RangeList_from_string(const char *SAI_data, const char *set_bytes, bool invert)
Definition: RangeList.cxx:32
reverse_iterator rend() const
Definition: RangeList.h:55
iterator begin() const
Definition: RangeList.h:51
iterator end() const
Definition: RangeList.h:52
#define rl_assert(cond)
Definition: RangeList.h:22
reverse_iterator rbegin() const
Definition: RangeList.h:54
RangeList inverse(ExplicitRange versus)
Definition: RangeList.cxx:20
bool operator()(const PosRange &r1, const PosRange &r2) const
Definition: RangeList.h:25
int end() const
Definition: pos_range.h:61
range_set::const_reverse_iterator reverse_iterator
Definition: RangeList.h:47