A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree_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 namespace genesis {
34 namespace tree {
35 
36 // =================================================================================================
37 // Constructors and Rule of Five
38 // =================================================================================================
39 
40 void TreeSet::swap( TreeSet& other )
41 {
42  using std::swap;
43  swap( trees_, other.trees_ );
44 }
45 
46 // =================================================================================================
47 // Modifiers
48 // =================================================================================================
49 
55 void TreeSet::add( std::string const& name, Tree const& tree )
56 {
57  trees_.push_back( { name, tree } );
58 }
59 
60 void TreeSet::add( std::string&& name, Tree&& tree )
61 {
62  trees_.push_back( { std::move( name ), std::move( tree ) } );
63 }
64 
71 void TreeSet::remove_at( size_t index )
72 {
73  trees_.erase( trees_.begin() + index );
74 }
75 
80 {
81  trees_.clear();
82 }
83 
84 // =================================================================================================
85 // Accessors
86 // =================================================================================================
87 
89 {
90  return trees_.begin();
91 }
92 
94 {
95  return trees_.cbegin();
96 }
97 
99 {
100  return trees_.end();
101 }
102 
104 {
105  return trees_.cend();
106 }
107 
109 {
110  return trees_.at(index);
111 }
112 
113 TreeSet::NamedTree const& TreeSet::at ( size_t index ) const
114 {
115  return trees_.at(index);
116 }
117 
118 TreeSet::NamedTree& TreeSet::operator [] (const std::size_t index)
119 {
120  return trees_[index];
121 }
122 
123 TreeSet::NamedTree const& TreeSet::operator [] (const std::size_t index) const
124 {
125  return trees_[index];
126 }
127 
131 bool TreeSet::empty() const
132 {
133  return trees_.empty();
134 }
135 
139 size_t TreeSet::size() const
140 {
141  return trees_.size();
142 }
143 
144 } // namespace tree
145 } // namespace genesis
NamedTree & operator[](const std::size_t index)
Definition: tree_set.cpp:118
typename std::vector< NamedTree >::const_iterator const_iterator
Definition: tree_set.hpp:65
void swap(SequenceSet &lhs, SequenceSet &rhs)
bool empty() const
Return whether the TreeSet is empty.
Definition: tree_set.cpp:131
void clear()
Clear the TreeSet and destroy all contained Trees.
Definition: tree_set.cpp:79
Store a Tree together with a name for it.
Definition: tree_set.hpp:58
size_t size() const
Return the size of the TreeSet, i.e., the number of stored Trees.
Definition: tree_set.cpp:139
typename std::vector< NamedTree >::iterator iterator
Definition: tree_set.hpp:64
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
void remove_at(size_t index)
Remove the Tree at a certain index position.
Definition: tree_set.cpp:71
void add(std::string const &name, Tree const &tree)
Add a Tree with a name to the TreeSet.
Definition: tree_set.cpp:55
void swap(TreeSet &other)
Definition: tree_set.cpp:40
NamedTree & at(size_t index)
Definition: tree_set.cpp:108