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 bool empty() const
Return whether the TreeSet is empty.
const_iterator end() const
void add(Tree const &tree, std::string const &name="")
Add a Tree with a name to the TreeSet.
std::string const & name_at(size_t index) const
typename std::vector< Tree >::iterator iterator
void swap(SequenceSet &lhs, SequenceSet &rhs)
size_t size() const
Return the size of the TreeSet, i.e., the number of stored Trees.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
void clear()
Clear the TreeSet and destroy all contained Trees.
void add(Tree &&tree, std::string const &name="")
Add a Tree with a name to the TreeSet.
Class for representing phylogenetic trees.
std::vector< Tree > const & trees() const
std::vector< std::string > const & names() const
void remove_at(size_t index)
Remove the Tree at a certain index position.
Tree & operator[](const std::size_t index)
const_iterator begin() const
TreeSet & operator=(TreeSet const &)=default
std::shared_ptr< BaseOutputTarget > to_string(std::string &target_string)
Obtain an output target for writing to a string.
typename std::vector< Tree >::const_iterator const_iterator
void swap(TreeSet &other)
Tree const & at(size_t index) const