A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sequence_set.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2017 Lucas Czech
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
33 #include <stdexcept>
34 
35 namespace genesis {
36 namespace sequence {
37 
38 // =============================================================================
39 // Constructors and Rule of Five
40 // =============================================================================
41 
42 void swap( SequenceSet& lhs, SequenceSet& rhs )
43 {
44  using std::swap;
45  swap( lhs.sequences_, rhs.sequences_ );
46 }
47 
48 // =============================================================================
49 // Accessors
50 // =============================================================================
51 
52 size_t SequenceSet::size() const
53 {
54  return sequences_.size();
55 }
56 
57 bool SequenceSet::empty() const
58 {
59  return sequences_.empty();
60 }
61 
63 {
64  return sequences_.at( index );
65 }
66 
68 {
69  return sequences_.at( index );
70 }
71 
73 {
74  return sequences_[ index ];
75 }
76 
78 {
79  return sequences_[ index ];
80 }
81 
82 // =============================================================================
83 // Modifiers
84 // =============================================================================
85 
87 {
88  sequences_.push_back( s );
89  return sequences_.back();
90 }
91 
93 {
94  sequences_.push_back( std::move(s) );
95  return sequences_.back();
96 }
97 
98 void SequenceSet::remove( size_t index )
99 {
100  if( index >= sequences_.size() ) {
101  throw std::out_of_range( "Index out of range for removing from SequenceSet." );
102  }
103 
104  sequences_.erase( sequences_.begin() + index );
105 }
106 
107 void SequenceSet::remove( size_t first_index, size_t last_index )
108 {
109  if( first_index >= sequences_.size()
110  || last_index >= sequences_.size()
111  || first_index >= last_index
112  ) {
113  throw std::out_of_range( "Invalid indices for removing from SequenceSet." );
114  }
115 
116  sequences_.erase( sequences_.begin() + first_index, sequences_.begin() + last_index );
117 }
118 
120 {
121  sequences_.erase( position );
122 
123 }
124 
126 {
127  sequences_.erase( first, last );
128 }
129 
131 {
132  sequences_.clear();
133 }
134 
135 // =============================================================================
136 // Iterators
137 // =============================================================================
138 
140 {
141  return sequences_.begin();
142 }
143 
145 {
146  return sequences_.end();
147 }
148 
150 {
151  return sequences_.cbegin();
152 }
153 
155 {
156  return sequences_.cend();
157 }
158 
160 {
161  return sequences_.cbegin();
162 }
163 
165 {
166  return sequences_.cend();
167 }
168 
169 } // namespace sequence
170 } // namespace genesis
reference at(size_t index)
void swap(SequenceSet &lhs, SequenceSet &rhs)
void clear()
Remove all Sequences from the SequenceSet, leaving it with a size() of 0.
const_iterator cend() const
Sequence const & const_reference
std::vector< Sequence >::const_iterator const_iterator
const_iterator cbegin() const
void remove(size_t index)
Remove the Sequence at a given index from the SequenceSet.
Store a set of Sequences.
std::vector< Sequence >::iterator iterator
reference add(Sequence const &s)
Add a Sequence to the SequenceSet by copying it, and return a reference to it.
reference operator[](size_t index)