A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fasta_output_iterator.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_FORMATS_FASTA_OUTPUT_ITERATOR_H_
2 #define GENESIS_SEQUENCE_FORMATS_FASTA_OUTPUT_ITERATOR_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
36 
37 #include <iterator>
38 #include <iostream>
39 
40 namespace genesis {
41 namespace sequence {
42 
43 // =================================================================================================
44 // Fasta Output Iterator
45 // =================================================================================================
46 
51 {
52 public:
53 
54  // -------------------------------------------------------------------------
55  // Member Types
56  // -------------------------------------------------------------------------
57 
59  using iterator_category = std::output_iterator_tag;
60 
61  // -------------------------------------------------------------------------
62  // Constructors and Rule of Five
63  // -------------------------------------------------------------------------
64 
65  FastaOutputIterator() = default;
66 
67  FastaOutputIterator( std::ostream& out )
68  : writer_()
69  , output_stream_( out )
70  {}
71 
72  FastaOutputIterator( std::ostream& out, FastaWriter const& writer )
73  : writer_( writer )
74  , output_stream_( out )
75  {}
76 
77  ~FastaOutputIterator() = default;
78 
79  FastaOutputIterator( self_type const& ) = default;
80  FastaOutputIterator( self_type&& ) = default;
81 
82  self_type& operator= ( self_type const& ) = default;
83  self_type& operator= ( self_type&& ) = default;
84 
85  // -------------------------------------------------------------------------
86  // Accessors
87  // -------------------------------------------------------------------------
88 
90  {
91  writer_.write_sequence( seq, output_stream_ );
92  return *this;
93  }
94 
96  {
97  return *this;
98  }
99 
106  {
107  return writer_;
108  }
109 
110  // -------------------------------------------------------------------------
111  // Iteration
112  // -------------------------------------------------------------------------
113 
115  {
116  return *this;
117  }
118 
120  {
121  return *this;
122  }
123 
124  // -------------------------------------------------------------------------
125  // Data Members
126  // -------------------------------------------------------------------------
127 
128 private:
129 
130  FastaWriter writer_;
131  std::ostream& output_stream_;
132 };
133 
134 } // namespace sequence
135 } // namespace genesis
136 
137 #endif // include guard
self_type & operator=(self_type const &)=default
FastaOutputIterator(std::ostream &out, FastaWriter const &writer)
void write_sequence(Sequence const &seq, std::ostream &os) const
Write a single Sequence to an output stream in Fasta format.
FastaWriter & writer()
Return the FastaWrtier used for this iterator.