A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sample_set.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_PLACEMENT_SAMPLE_SET_H_
2 #define GENESIS_PLACEMENT_SAMPLE_SET_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
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 
35 
36 #include <string>
37 #include <vector>
38 
39 namespace genesis {
40 namespace placement {
41 
42 // =================================================================================================
43 // SampleSet
44 // =================================================================================================
45 
52 class SampleSet
53 {
54 public:
55 
56  // -------------------------------------------------------------------------
57  // Typedefs
58  // -------------------------------------------------------------------------
59 
66  struct NamedSample
67  {
68  std::string name;
70 
71  operator Sample&()
72  {
73  return sample;
74  }
75 
76  operator Sample const&() const
77  {
78  return sample;
79  }
80  };
81 
82  typedef std::vector<NamedSample>::iterator iterator;
83  typedef std::vector<NamedSample>::const_iterator const_iterator;
84 
85  // -------------------------------------------------------------------------
86  // Constructors and Rule of Five
87  // -------------------------------------------------------------------------
88 
89  SampleSet() = default;
90  ~SampleSet() = default;
91 
92  SampleSet( SampleSet const& ) = default;
93  SampleSet( SampleSet&& ) = default;
94 
95  SampleSet& operator= ( SampleSet const& ) = default;
96  SampleSet& operator= ( SampleSet&& ) = default;
97 
98  void swap( SampleSet& other )
99  {
100  using std::swap;
101  swap( smps_, other.smps_ );
102  }
103 
104  // -------------------------------------------------------------------------
105  // Modifiers
106  // -------------------------------------------------------------------------
107 
113  void add( Sample const& smp )
114  {
115  smps_.push_back( { "", smp } );
116  }
117 
123  void add( Sample const& smp, std::string const& name )
124  {
125  smps_.push_back( { name, smp } );
126  }
127 
133  void add( Sample&& smp )
134  {
135  smps_.push_back( { "", std::move(smp) } );
136  }
137 
143  void add( Sample&& smp, std::string const& name )
144  {
145  smps_.push_back( { name, std::move(smp) } );
146  }
147 
154  void remove_at( size_t index )
155  {
156  smps_.erase( smps_.begin() + index );
157  }
158 
162  void clear()
163  {
164  smps_.clear();
165  }
166 
167  // -------------------------------------------------------------------------
168  // Accessors
169  // -------------------------------------------------------------------------
170 
172  {
173  return smps_.begin();
174  }
175 
177  {
178  return smps_.cbegin();
179  }
180 
182  {
183  return smps_.end();
184  }
185 
187  {
188  return smps_.cend();
189  }
190 
194  NamedSample& at ( size_t index )
195  {
196  return smps_.at(index);
197  }
198 
202  NamedSample const& at ( size_t index ) const
203  {
204  return smps_.at(index);
205  }
206 
210  NamedSample& operator [] ( size_t index )
211  {
212  return smps_[index];
213  }
214 
218  NamedSample const& operator [] ( size_t index ) const
219  {
220  return smps_[index];
221  }
222 
226  bool empty() const
227  {
228  return smps_.empty();
229  }
230 
234  size_t size() const
235  {
236  return smps_.size();
237  }
238 
239  // -------------------------------------------------------------------------
240  // Data Members
241  // -------------------------------------------------------------------------
242 
243 private:
244 
245  std::vector<NamedSample> smps_;
246 
247 };
248 
249 } // namespace placement
250 } // namespace genesis
251 
252 #endif // include guard
SampleSet & operator=(SampleSet const &)=default
std::vector< NamedSample >::iterator iterator
Definition: sample_set.hpp:82
void swap(SequenceSet &lhs, SequenceSet &rhs)
void add(Sample const &smp, std::string const &name)
Add a Sample with a name to the SampleSet.
Definition: sample_set.hpp:123
void add(Sample &&smp)
Add a Sample to the SampleSet.
Definition: sample_set.hpp:133
Store a Sample and a name for it.
Definition: sample_set.hpp:66
NamedSample const & at(size_t index) const
Get the NamedSample at a certain index position.
Definition: sample_set.hpp:202
NamedSample & operator[](size_t index)
Get the NamedSample at a certain index position.
Definition: sample_set.hpp:210
const_iterator end() const
Definition: sample_set.hpp:186
void clear()
Delete all Samples in this SampleSet.
Definition: sample_set.hpp:162
bool empty() const
Return whether the SampleSet is empty.
Definition: sample_set.hpp:226
Store a set of Samples with associated names.
Definition: sample_set.hpp:52
std::vector< NamedSample >::const_iterator const_iterator
Definition: sample_set.hpp:83
size_t size() const
Return the size of the SampleSet, i.e., the number of Samples.
Definition: sample_set.hpp:234
void add(Sample const &smp)
Add a Sample to the SampleSet.
Definition: sample_set.hpp:113
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on...
Definition: sample.hpp:68
NamedSample & at(size_t index)
Get the NamedSample at a certain index position.
Definition: sample_set.hpp:194
void add(Sample &&smp, std::string const &name)
Add a Sample with a name to the SampleSet.
Definition: sample_set.hpp:143
void swap(SampleSet &other)
Definition: sample_set.hpp:98
const_iterator begin() const
Definition: sample_set.hpp:176
void remove_at(size_t index)
Remove the Sample at a certain index position.
Definition: sample_set.hpp:154