ARB
SEC_iter.hxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : SEC_iter.hxx //
4 // Purpose : secondary structure iterators //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in August 2007 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // =============================================================== //
11 
12 #ifndef SEC_ITER_HXX
13 #define SEC_ITER_HXX
14 
15 // iterates over all parts of the structure (segments/strands)
17  SEC_base_part *start;
18  SEC_base_part *curr;
19 
20 public:
22  : start(root->get_root_loop()->get_fixpoint_strand()), curr(start)
23  {}
24 
25  SEC_base_part& operator*() { return *curr; }
26  SEC_base_part* operator->() { return curr; }
27 
29  if (curr) {
30  curr = curr->next();
31  if (curr == start) curr = NULp;
32  }
33  return *this;
34  }
35 
36  operator bool() const { return curr; }
37 
38 };
39 
40 // iterates over all bases of the structure (loops/helices)
42  SEC_base_part_iterator part; // always points to an outgoing strand
43  bool do_loop; // true -> curr is origin loop, false -> curr is helix
44 
45  SEC_base *curr() {
46  SEC_helix_strand& strand = static_cast<SEC_helix_strand&>(*part);
47  return do_loop
48  ? static_cast<SEC_base*>(strand.get_origin_loop())
49  : static_cast<SEC_base*>(strand.get_helix());
50  }
51 
52 public:
53  SEC_base_iterator(SEC_root *root) : part(root), do_loop(true) {}
54 
55  SEC_base& operator*() { return *curr(); }
56  SEC_base* operator->() { return curr(); }
57 
59  if (part) {
60  if (do_loop) do_loop = false;
61  else {
62  // skip over all strands pointing to root
63  int steps = 0;
64  do {
65  ++++part;
66  ++steps;
67  }
68  while (part && static_cast<SEC_helix_strand&>(*part).pointsToRoot());
69  do_loop = (steps == 1);
70  }
71  }
72  return *this;
73  }
74 
75  operator bool() const { return part; }
76 };
77 
78 
79 // iterates over all strands in one loop (starting with fixpoint strand)
81  SEC_helix_strand *start;
82  SEC_helix_strand *curr;
83 public:
84  SEC_strand_iterator(SEC_loop *loop) : start(loop->get_fixpoint_strand()), curr(start) {}
85 
86  SEC_helix_strand& operator*() { return *curr; }
87  SEC_helix_strand* operator->() { return curr; }
88 
90  sec_assert(curr);
91  SEC_segment *seg = curr->get_next_segment();
92 
93  if (seg) {
94  curr = seg->get_next_strand();
95  if (curr == start) curr = NULp;
96  }
97  else {
98  curr = NULp;
99  }
100  return *this;
101  }
102 
103  operator bool() const { return curr; }
104 };
105 
106 // iterates over all segments in one loop (starting with segment behind fixpoint strand)
108  const SEC_strand_iterator& strand_iter() const { return static_cast<const SEC_strand_iterator&>(*this); }
109  SEC_strand_iterator& strand_iter() { return static_cast<SEC_strand_iterator&>(*this); }
110 public:
111  SEC_segment_iterator(SEC_loop *loop) : SEC_strand_iterator(loop) {}
112 
113  SEC_segment& operator*() { return *strand_iter()->get_next_segment(); }
114  SEC_segment* operator->() { return strand_iter()->get_next_segment(); }
115 
117  SEC_strand_iterator& si = strand_iter();
118  ++si;
119  return *this;
120  }
121 
122  operator bool() const { return strand_iter(); }
123 
124  SEC_helix_strand *get_previous_strand() { return &*strand_iter(); }
125 };
126 
127 
128 // const versions
129 
131  const SEC_strand_iterator& strand_iter() const { return static_cast<const SEC_strand_iterator&>(*this); }
132  SEC_strand_iterator& strand_iter() { return static_cast<SEC_strand_iterator&>(*this); }
133 public:
134  SEC_strand_const_iterator(const SEC_loop *loop) : SEC_strand_iterator(const_cast<SEC_loop*>(loop)) {}
135  const SEC_helix_strand& operator*() { return *strand_iter(); }
136  const SEC_helix_strand* operator->() { return strand_iter().operator->(); }
137  SEC_strand_const_iterator& operator++() { return static_cast<SEC_strand_const_iterator&>(++strand_iter()); }
138  operator bool() const { return bool(strand_iter()); }
139 };
140 
141 #else
142 #error SEC_iter.hxx included twice
143 #endif // SEC_ITER_HXX
SEC_base_part_iterator(SEC_root *root)
Definition: SEC_iter.hxx:21
SEC_base_iterator(SEC_root *root)
Definition: SEC_iter.hxx:53
SEC_segment * operator->()
Definition: SEC_iter.hxx:114
SEC_base * operator->()
Definition: SEC_iter.hxx:56
SEC_helix_strand * get_previous_strand()
Definition: SEC_iter.hxx:124
SEC_base_iterator & operator++()
Definition: SEC_iter.hxx:58
SEC_helix_strand & operator*()
Definition: SEC_iter.hxx:86
SEC_base & operator*()
Definition: SEC_iter.hxx:55
const SEC_helix_strand & operator*()
Definition: SEC_iter.hxx:135
#define true
Definition: ureadseq.h:14
SEC_base_part * operator->()
Definition: SEC_iter.hxx:26
SEC_segment_iterator & operator++()
Definition: SEC_iter.hxx:116
SEC_base_part & operator*()
Definition: SEC_iter.hxx:25
SEC_segment & operator*()
Definition: SEC_iter.hxx:113
SEC_segment_iterator(SEC_loop *loop)
Definition: SEC_iter.hxx:111
const SEC_helix_strand * operator->()
Definition: SEC_iter.hxx:136
SEC_base_part_iterator & operator++()
Definition: SEC_iter.hxx:28
SEC_base_part * next()
Definition: SEC_root.hxx:301
SEC_strand_const_iterator & operator++()
Definition: SEC_iter.hxx:137
SEC_strand_iterator(SEC_loop *loop)
Definition: SEC_iter.hxx:84
#define NULp
Definition: cxxforward.h:97
SEC_strand_iterator & operator++()
Definition: SEC_iter.hxx:89
SEC_strand_const_iterator(const SEC_loop *loop)
Definition: SEC_iter.hxx:134
SEC_helix_strand * operator->()
Definition: SEC_iter.hxx:87
#define sec_assert(cond)
Definition: SEC_defs.hxx:19