bpp-seq-omics  2.4.1
MafIterator.h
Go to the documentation of this file.
1 //
2 // File: MafIterator.h
3 // Authors: Julien Dutheil
4 // Created: Tue Sep 07 2010
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (2010)
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 #ifndef _MAFITERATOR_H_
41 #define _MAFITERATOR_H_
42 
43 #include "MafBlock.h"
44 
45 //From the STL:
46 #include <iostream>
47 #include <string>
48 #include <deque>
49 
50 namespace bpp {
51 
52 //Forward declaration:
53 class IterationListener;
54 
59 {
60  public:
61  virtual ~MafIterator() {}
62 
63  public:
69  virtual MafBlock* nextBlock() = 0;
70 
71  virtual bool isVerbose() const = 0;
72 
73  virtual void setVerbose(bool yn) = 0;
74 
75  virtual void addIterationListener(IterationListener* listener) = 0;
76 
77 
78 };
79 
86  public virtual MafIterator
87 {
88  protected:
89  std::vector<IterationListener*> iterationListeners_;
90  bool started_;
91  bool verbose_;
92 
93  public:
95 
96  virtual ~AbstractMafIterator() {}
97 
98  public:
100  iterationListeners_.push_back(listener);
101  }
102 
104  if (!started_) {
106  started_ = true;
107  }
108  MafBlock* block = analyseCurrentBlock_();
109  if (block)
110  fireIterationMoveSignal_(*block);
111  else
113  return block;
114  }
115 
116  bool isVerbose() const { return verbose_; }
117  void setVerbose(bool yn) { verbose_ = yn; }
118 
119  protected:
121  virtual void fireIterationStartSignal_();
122  virtual void fireIterationMoveSignal_(const MafBlock& currentBlock);
123  virtual void fireIterationStopSignal_();
124 
125 };
126 
131 {
132  public:
133  virtual ~MafTrashIterator() {}
134 
135  public:
141  virtual MafBlock* nextRemovedBlock() = 0;
142 
143 };
144 
145 
150  public AbstractMafIterator
151 {
152  protected:
155  std::shared_ptr<OutputStream> logstream_;
156 
157  public:
160  iterator_(iterator), currentBlock_(0),
161  logstream_(ApplicationTools::message) {}
162 
163  private:
165  AbstractMafIterator(it),
167  logstream_(it.logstream_) {}
168 
170  AbstractMafIterator::operator=(it);
171  currentBlock_ = 0;
172  iterator_ = it.iterator_;
173  logstream_ = it.logstream_;
174  return *this;
175  }
176 
177  public:
178  void setLogStream(std::shared_ptr<OutputStream> logstream) { logstream_ = logstream; }
179 
180 };
181 
182 
184  public AbstractMafIterator
185 {
186  private:
188 
189  public:
191  iterator_(iterator) {}
192 
193  private:
195  iterator_(iterator.iterator_) {}
196 
198  iterator_ = iterator.iterator_;
199  return *this;
200  }
201 
202  private:
204  return iterator_->nextRemovedBlock();
205  }
206 };
207 
208 
218 {
219  private:
221 
222  public:
223  MafIteratorSynchronizer(MafIterator* primaryIterator, MafIterator* secondaryIterator) :
224  AbstractFilterMafIterator(primaryIterator), secondaryIterator_(secondaryIterator)
225  {}
226 
227  private:
231  {}
232 
234  {
236  return *this;
237  }
238 
239 
240  private:
243  MafBlock* secondBlock = secondaryIterator_->nextBlock();
244  if (secondBlock)
245  delete secondBlock;
246  return currentBlock_;
247  }
248 
249 };
250 
251 
252 } // end of namespace bpp.
253 
254 #endif //_MAFITERATOR_H_
Helper class for developping filter for maf blocks.
Definition: MafIterator.h:151
AbstractFilterMafIterator(const AbstractFilterMafIterator &it)
Definition: MafIterator.h:164
AbstractFilterMafIterator(MafIterator *iterator)
Definition: MafIterator.h:158
void setLogStream(std::shared_ptr< OutputStream > logstream)
Definition: MafIterator.h:178
AbstractFilterMafIterator & operator=(const AbstractFilterMafIterator &it)
Definition: MafIterator.h:169
std::shared_ptr< OutputStream > logstream_
Definition: MafIterator.h:155
Partial implementation of the MafIterator interface.
Definition: MafIterator.h:87
virtual void fireIterationMoveSignal_(const MafBlock &currentBlock)
Definition: MafIterator.cpp:57
MafBlock * nextBlock()
Get the next available alignment block.
Definition: MafIterator.h:103
virtual ~AbstractMafIterator()
Definition: MafIterator.h:96
virtual void fireIterationStartSignal_()
Definition: MafIterator.cpp:51
void setVerbose(bool yn)
Definition: MafIterator.h:117
virtual void fireIterationStopSignal_()
Definition: MafIterator.cpp:63
void addIterationListener(IterationListener *listener)
Definition: MafIterator.h:99
virtual MafBlock * analyseCurrentBlock_()=0
std::vector< IterationListener * > iterationListeners_
Definition: MafIterator.h:89
Listener which enables to catch events when parsing a Maf file.
A synteny block data structure, the basic unit of a MAF alignement file.
Definition: MafBlock.h:57
This special iterator synchronizes two adaptors.
Definition: MafIterator.h:218
MafIterator * secondaryIterator_
Definition: MafIterator.h:220
MafIteratorSynchronizer & operator=(const MafIteratorSynchronizer &iterator)
Definition: MafIterator.h:233
MafBlock * analyseCurrentBlock_()
Definition: MafIterator.h:241
MafIteratorSynchronizer(const MafIteratorSynchronizer &iterator)
Definition: MafIterator.h:228
MafIteratorSynchronizer(MafIterator *primaryIterator, MafIterator *secondaryIterator)
Definition: MafIterator.h:223
Interface to loop over maf alignment blocks.
Definition: MafIterator.h:59
virtual bool isVerbose() const =0
virtual void addIterationListener(IterationListener *listener)=0
virtual ~MafIterator()
Definition: MafIterator.h:61
virtual void setVerbose(bool yn)=0
virtual MafBlock * nextBlock()=0
Get the next available alignment block.
Interface to loop over removed blocks of a maf alignment.
Definition: MafIterator.h:131
virtual MafBlock * nextRemovedBlock()=0
Get the next available removed alignment block.
virtual ~MafTrashIterator()
Definition: MafIterator.h:133
MafBlock * analyseCurrentBlock_()
Definition: MafIterator.h:203
TrashIteratorAdapter(MafTrashIterator *iterator)
Definition: MafIterator.h:190
TrashIteratorAdapter(const TrashIteratorAdapter &iterator)
Definition: MafIterator.h:194
MafTrashIterator * iterator_
Definition: MafIterator.h:187
TrashIteratorAdapter & operator=(const TrashIteratorAdapter &iterator)
Definition: MafIterator.h:197