bpp-seq  2.2.0
SiteContainerIterator.cpp
Go to the documentation of this file.
1 //
2 // File: SiteContainerIterator.cpp
3 // Created by: Julien Dutheil
4 // Created on: Sun Oct 19 12:47:16 2003
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
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 
40 #include "SiteContainerIterator.h"
41 #include "../SiteTools.h"
42 
43 using namespace bpp;
44 
45 // From the STL:
46 #include <iostream>
47 
48 using namespace std;
49 
50 /******************************************************************************/
51 
53  sites_(&sites),
54  currentPosition_(0)
55 {}
56 
57 /******************************************************************************/
58 
60 
62 {
63  const Site* s = &sites_->getSite(static_cast<size_t>(currentPosition_));
65  return s;
66 }
67 
69 {
70  return currentPosition_ < static_cast<int>(sites_->getNumberOfSites());
71 }
72 
73 /******************************************************************************/
74 
76 {
78 }
79 
81 {
82  const Site* s = &sites_->getSite(static_cast<size_t>(currentPosition_));
84  return s;
85 }
86 
88 {
89  return currentPosition_ < static_cast<int>(sites_->getNumberOfSites());
90 }
91 
93 {
94  size_t position = static_cast<size_t>(current + 1);
95  while (position < sites_->getNumberOfSites() && SiteTools::hasGap(sites_->getSite(position)))
96  position++;
97  return static_cast<int>(position);
98 }
99 
101 {
102  int position = current - 1;
103  while (position >= 0 && SiteTools::hasGap(sites_->getSite(static_cast<size_t>(position))))
104  position--;
105  return position;
106 }
107 
108 /******************************************************************************/
109 
111 {
113 }
114 
116 {
117  const Site* s = &sites_->getSite(static_cast<size_t>(currentPosition_));
119  return s;
120 }
121 
123 {
124  return currentPosition_ < static_cast<int>(sites_->getNumberOfSites());
125 }
126 
128 {
129  size_t position = static_cast<size_t>(current + 1);
130  while (position < sites_->getNumberOfSites() && !SiteTools::isComplete(sites_->getSite(position)))
131  position++;
132  return static_cast<int>(position);
133 }
134 
136 {
137  int position = current - 1;
138  while (position >= 0 && !SiteTools::isComplete(sites_->getSite(static_cast<size_t>(position))))
139  position --;
140  return position;
141 }
142 
143 /******************************************************************************/
144 
Partial implementation of the SiteIterator interface, allowing to loop over a site container...
The SiteContainer interface.
Definition: SiteContainer.h:63
This alphabet is used to deal NumericAlphabet.
SimpleSiteContainerIterator(const SiteContainer &sites)
CompleteSiteContainerIterator(const SiteContainer &sites)
STL namespace.
static bool isComplete(const Site &site)
Definition: SiteTools.cpp:108
AbstractSiteContainerIterator(const SiteContainer &sites)
static bool hasGap(const Site &site)
Definition: SiteTools.cpp:56
int nextSiteWithoutGapPosition(int current) const
virtual const Site & getSite(size_t siteIndex) const =0
Get a site from the container.
virtual size_t getNumberOfSites() const =0
Get the number of sites in the container.
int previousCompleteSitePosition(int current) const
int previousSiteWithoutGapPosition(int current) const
NoGapSiteContainerIterator(const SiteContainer &sites)
The Site class.
Definition: Site.h:61