|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_TREE_TREE_SET_H_
2 #define GENESIS_TREE_TREE_SET_H_
56 using iterator =
typename std::vector<Tree>::iterator;
75 swap( names_, other.names_ );
76 swap( trees_, other.trees_ );
88 void add(
Tree const& tree, std::string
const& name =
"" )
90 names_.push_back( name );
91 trees_.push_back( tree );
99 void add(
Tree&& tree, std::string
const& name =
"" )
101 names_.push_back( name );
102 trees_.push_back( std::move( tree ));
113 if( index >= trees_.size() ) {
114 throw std::invalid_argument(
115 "Cannot remove element at index " +
std::to_string( index ) +
" from TreeSet with " +
119 assert( names_.size() == trees_.size() );
121 names_.erase( names_.begin() + index );
122 trees_.erase( trees_.begin() + index );
138 std::string
const&
name_at(
size_t index )
const
140 if( index >= names_.size() ) {
141 throw std::invalid_argument(
142 "Cannot access element at index " +
std::to_string( index ) +
" from TreeSet with " +
146 return names_[index];
149 std::vector<std::string>
const&
names()
const
160 return trees_.begin();
165 return trees_.cbegin();
175 return trees_.cend();
180 return trees_.at(index);
185 return trees_.at(index);
190 return trees_[index];
195 return trees_[index];
198 std::vector<Tree>
const&
trees()
const
207 operator std::vector<Tree>
const&()
const
221 assert( names_.empty() == trees_.empty() );
222 return trees_.empty();
230 assert( names_.size() == trees_.size() );
231 return trees_.size();
240 std::vector<std::string> names_;
241 std::vector<Tree> trees_;
248 #endif // include guard
void add(Tree const &tree, std::string const &name="")
Add a Tree with a name to the TreeSet.
void swap(Sample &lhs, Sample &rhs)
TreeSet & operator=(TreeSet const &)=default
void swap(TreeSet &other)
const_iterator end() const
size_t size() const
Return the size of the TreeSet, i.e., the number of stored Trees.
std::string const & name_at(size_t index) const
void clear()
Clear the TreeSet and destroy all contained Trees.
typename std::vector< Tree >::iterator iterator
std::string to_string(GenomeLocus const &locus)
Class for representing phylogenetic trees.
void add(Tree &&tree, std::string const &name="")
Add a Tree with a name to the TreeSet.
std::vector< Tree > const & trees() const
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
const_iterator begin() const
void remove_at(size_t index)
Remove the Tree at a certain index position.
std::vector< std::string > const & names() const
typename std::vector< Tree >::const_iterator const_iterator
Tree const & at(size_t index) const
bool empty() const
Return whether the TreeSet is empty.
Tree & operator[](const std::size_t index)