bpp-seq3  3.0.0
SequencePositionIterators.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 using namespace bpp;
8 using namespace std; // for the STL
9 
10 /******************************************************************************/
11 
13 {
14  return this->getPosition() == it.getPosition();
15 }
16 
17 /******************************************************************************/
18 
20 {
21  return this->getPosition() != it.getPosition();
22 }
23 
24 /******************************************************************************/
25 
27 {
28  this->currentPosition_ = pos;
29 }
30 
31 /******************************************************************************/
32 
34 {
35  return *(this->sequence_);
36 }
37 
38 /******************************************************************************/
39 
41 {
42  return this->currentPosition_;
43 }
44 
45 /******************************************************************************/
46 
48 {
49  return this->sequence_->getValue(this->currentPosition_);
50 }
51 
52 /******************************************************************************/
53 
55 {
56  return this->sequence_->getChar(this->currentPosition_);
57 }
58 
59 
60 // ===============================
61 // SimpleSequencePositionIterator
62 // ===============================
63 /******************************************************************************/
64 
66  AbstractSequencePositionIterator(it.getSequence(), it.getPosition()) {}
67 
68 /******************************************************************************/
69 
71 {
72  this->setPosition(this->getPosition() + 1);
73  return *this;
74 }
75 
76 /******************************************************************************/
77 
79 {
81  ++(*this);
82  return ans;
83 }
84 
85 /******************************************************************************/
86 
88 {
89  if (i > 0)
90  this->setPosition(this->getPosition() + static_cast<unsigned int>(i));
91  else if (i < 0)
92  {
93  unsigned int d = static_cast<unsigned int>(-i);
94  if (d > this->getPosition())
95  throw Exception("SimpleSequencePositionIterator::operator+=. Negative increment too large.");
96  else
97  this->setPosition(this->getPosition() - d);
98  }
99  return *this;
100 }
101 
102 /******************************************************************************/
103 
105 {
106  return (*this) += -i;
107 }
108 
109 /******************************************************************************/
110 
112 {
114  res += i;
115  return res;
116 }
117 
118 /******************************************************************************/
119 
121 {
122  return (*this) + (-i);
123 }
124 
125 /******************************************************************************/
126 
128 {
129  return this->getPosition() < this->getSequence().size();
130 }
131 /******************************************************************************/
Partial implementation of the SequencePositionIterator interface.
bool operator==(const SequencePositionIterator &it) const
unsigned int getPosition() const
Get the actual position of the iterator in the Sequence.
bool operator!=(const SequencePositionIterator &it) const
int getValue() const
Get the numerical value of the Sequence at current position.
const Sequence & getSequence() const
Get the Sequence on which the iterator loops.
std::string getChar() const
Get the textual value of the Sequence at current position.
void setPosition(unsigned int pos)
Set the position of the iterator.
size_t size() const override
Get the number of elements in the list.
Definition: SymbolList.h:124
virtual unsigned int getPosition() const =0
Get the actual position of the iterator in the Sequence.
A basic implementation of the Sequence interface.
Definition: Sequence.h:117
Loop over all positions in a Sequence.
SimpleSequencePositionIterator & operator++()
bool hasMorePositions() const
Tells if there is more positions in the Sequence.
SimpleSequencePositionIterator & operator+=(int i)
virtual SimpleSequencePositionIterator operator-(int i) const
SimpleSequencePositionIterator & operator-=(int i)
SimpleSequencePositionIterator(const Sequence &seq, unsigned int pos=0)
General constructor.
virtual SimpleSequencePositionIterator operator+(int i) const
This alphabet is used to deal NumericAlphabet.