bpp-seq3  3.0.0
SiteContainerIterator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_SEQ_CONTAINER_SITECONTAINERITERATOR_H
6 #define BPP_SEQ_CONTAINER_SITECONTAINERITERATOR_H
7 
8 
9 #include "../SiteIterator.h"
10 #include "../SiteTools.h"
11 #include "SiteContainer.h"
12 
13 namespace bpp
14 {
18 template<class SiteType, class SequenceType, class HashType>
20  public virtual TemplateSiteIteratorInterface<const SiteType>
21 {
22 protected:
24  long int currentPosition_;
25 
26 public:
29  sites_(&sites),
31  {}
32 
33 
36  sites_(atsi.sites_),
38  {}
39 
42  {
43  sites_ = atsi.sites_;
45  return *this;
46  }
47 
49 };
50 
51 
55 template<class SiteType, class SequenceType, class HashType>
57  public AbstractTemplateSiteContainerIterator<SiteType, SequenceType, HashType>
58 {
59 protected:
62 
63 public:
66  AbstractTemplateSiteContainerIterator<SiteType, SequenceType, HashType>(sites)
67  {}
68 
70 
71 public:
72  const SiteType& nextSite() override
73  {
74  const SiteType& s = sites_->site(static_cast<size_t>(currentPosition_));
76  return s;
77  }
78 
79  bool hasMoreSites() const override
80  {
81  return static_cast<unsigned int>(currentPosition_) < sites_->getNumberOfSites();
82  }
83 };
84 
87 
91 template<class SiteType, class SequenceType, class HashType>
93  public AbstractTemplateSiteContainerIterator<SiteType, SequenceType, HashType>
94 {
95 protected:
98 
99 public:
102  AbstractTemplateSiteContainerIterator<SiteType, SequenceType, HashType>(sites)
103  {
105  }
106 
108 
109 public:
110  const SiteType& nextSite() override
111  {
112  const SiteType& s = sites_->site(static_cast<size_t>(currentPosition_));
114  return s;
115  }
116 
117  bool hasMoreSites() const override
118  {
119  return currentPosition_ < static_cast<long int>(sites_->getNumberOfSites());
120  }
121 
122  long int nextSiteWithoutGapPosition(int current) const
123  {
124  size_t position = static_cast<size_t>(current + 1);
125  while (position < sites_->getNumberOfSites() && SiteTools::hasGap(sites_->site(position)))
126  position++;
127  return static_cast<int>(position);
128  }
129 
130  long int previousSiteWithoutGapPosition(int current) const
131  {
132  long int position = current - 1;
133  while (position >= 0 && SymbolListTools::hasGap(sites_->site(static_cast<size_t>(position))))
134  position--;
135  return position;
136  }
137 };
138 
143 template<class SiteType, class SequenceType, class HashType>
145  public AbstractTemplateSiteContainerIterator<SiteType, SequenceType, HashType>
146 {
147 protected:
150 
151 public:
154  AbstractTemplateSiteContainerIterator<SiteType, SequenceType, HashType>(sites)
155  {
157  }
158 
160 
161 public:
162  const SiteType& nextSite() override
163  {
164  const Site& s = sites_->site(static_cast<size_t>(currentPosition_));
166  return s;
167  }
168 
169  bool hasMoreSites() const override
170  {
171  return currentPosition_ < static_cast<int>(sites_->getNumberOfSites());
172  }
173 
174  long int nextCompleteSitePosition(long int current) const
175  {
176  size_t position = static_cast<size_t>(current + 1);
177  while (position < sites_->getNumberOfSites() && !SiteTools::isComplete(sites_->site(position)))
178  position++;
179  return static_cast<int>(position);
180  }
181 
182  long int previousCompleteSitePosition(long int current) const
183  {
184  long int position = current - 1;
185  while (position >= 0 && !SymbolListTools::isComplete(sites_->site(static_cast<size_t>(position))))
186  position--;
187  return position;
188  }
189 };
190 } // end of namespace bpp.
191 #endif // BPP_SEQ_CONTAINER_SITECONTAINERITERATOR_H
Partial implementation of the SiteIterator interface, allowing to loop over a site container.
AbstractTemplateSiteContainerIterator(const AbstractTemplateSiteContainerIterator< SiteType, SequenceType, HashType > &atsi)
const TemplateSiteContainerInterface< SiteType, SequenceType, HashType > * sites_
AbstractTemplateSiteContainerIterator & operator=(const AbstractTemplateSiteContainerIterator< SiteType, SequenceType, HashType > &atsi)
AbstractTemplateSiteContainerIterator(const TemplateSiteContainerInterface< SiteType, SequenceType, HashType > &sites)
Loop over all complete sites in a SiteContainer (i.e. sites without gap and unresolved characters).
long int previousCompleteSitePosition(long int current) const
CompleteTemplateSiteContainerIterator(const TemplateSiteContainerInterface< SiteType, SequenceType, HashType > &sites)
long int nextCompleteSitePosition(long int current) const
Loop over all sites without gaps in a SiteContainer.
NoGapTemplateSiteContainerIterator(const TemplateSiteContainerInterface< SiteType, SequenceType, HashType > &sites)
long int nextSiteWithoutGapPosition(int current) const
long int previousSiteWithoutGapPosition(int current) const
Loop over all sites in a SiteContainer.
SimpleTemplateSiteContainerIterator(const TemplateSiteContainerInterface< SiteType, SequenceType, HashType > &sites)
The Site class.
Definition: Site.h:73
static bool hasGap(const IntSymbolListInterface &site)
static bool isComplete(const IntSymbolListInterface &site)
The SiteContainer interface.
Definition: SiteContainer.h:29
Generic site iterator interface, allowing to loop over sites.
Definition: SiteIterator.h:16
This alphabet is used to deal NumericAlphabet.