bpp-seq  2.2.0
SequencePositionIterators.cpp
Go to the documentation of this file.
1 //
2 // File: SequencePositionIterators.cpp
3 // Author: Sylvain Gaillard
4 // Created: 23/06/2009 11:38:27
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (June 23, 2009)
9 
10 This software is a computer program whose purpose is to provide classes
11 for sequences analysis.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
41 
42 using namespace bpp;
43 using namespace std; // for the STL
44 
45 /******************************************************************************/
46 
48  return this->getPosition() == it.getPosition();
49 }
50 
51 /******************************************************************************/
52 
54  return this->getPosition() != it.getPosition();
55 }
56 
57 /******************************************************************************/
58 
60  this->currentPosition_ = pos;
61 }
62 
63 /******************************************************************************/
64 
66  return * (this->sequence_);
67 }
68 
69 /******************************************************************************/
70 
72  return this->currentPosition_;
73 }
74 
75 /******************************************************************************/
76 
78  return this->sequence_->getValue(this->currentPosition_);
79 }
80 
81 /******************************************************************************/
82 
84  return this->sequence_->getChar(this->currentPosition_);
85 }
86 
87 
88 //===============================
89 // SimpleSequencePositionIterator
90 //===============================
91 /******************************************************************************/
92 
94  AbstractSequencePositionIterator(it.getSequence(), it.getPosition()) {};
95 
96 /******************************************************************************/
97 
99  this->setPosition(this->getPosition() + 1);
100  return *this;
101 }
102 
103 /******************************************************************************/
104 
106  SimpleSequencePositionIterator ans = *this;
107  ++(*this);
108  return ans;
109 }
110 
111 /******************************************************************************/
112 
114  if (i > 0)
115  this->setPosition(this->getPosition() + static_cast<unsigned int>(i));
116  else if (i < 0) {
117  unsigned int d = static_cast<unsigned int>(-i);
118  if (d > this->getPosition())
119  throw Exception("SimpleSequencePositionIterator::operator+=. Negative increment too large.");
120  else
121  this->setPosition(this->getPosition() - d);
122  }
123  return *this;
124 }
125 
126 /******************************************************************************/
127 
129  return (*this) += -i;
130 }
131 
132 /******************************************************************************/
133 
136  res += i;
137  return res;
138 }
139 
140 /******************************************************************************/
141 
143  return (*this) + (- i);
144 }
145 
146 /******************************************************************************/
147 
149  return (this->getPosition() < this->getSequence().size());
150 }
151 /******************************************************************************/
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.
SimpleSequencePositionIterator(const Sequence &seq, unsigned int pos=0)
General constructor.
This alphabet is used to deal NumericAlphabet.
STL namespace.
virtual SimpleSequencePositionIterator operator-(int i) const
SimpleSequencePositionIterator & operator+=(int i)
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.
bool hasMorePositions() const
Tells if there is more positions in the Sequence.
SimpleSequencePositionIterator & operator++()
SimpleSequencePositionIterator & operator-=(int i)
const Sequence & getSequence() const
Get the Sequence on which the iterator loops.
The sequence interface.
Definition: Sequence.h:74
virtual SimpleSequencePositionIterator operator+(int i) const
bool operator!=(const SequencePositionIterator &it) const
Loop over all positions in a Sequence.
Partial implementation of the SequencePositionIterator interface.
virtual unsigned int getPosition() const =0
Get the actual position of the iterator in the Sequence.