38 #include <type_traits> 47 static_assert( std::is_move_constructible<Tree>::value,
"Tree is not move constructible." );
48 static_assert( std::is_move_assignable<Tree>::value,
"Tree is not move assignable." );
56 for(
size_t i = 0; i < res.links_.size(); ++i ) {
59 for(
size_t i = 0; i < res.nodes_.size(); ++i ) {
66 auto const& res_data = *res.node_at(i).
data_ptr();
70 assert(
typeid( res_data ) ==
typeid( oth_data ));
75 for(
size_t i = 0; i < res.edges_.size(); ++i ) {
82 auto const& res_data = *res.edge_at(i).data_ptr();
86 assert(
typeid( res_data ) ==
typeid( oth_data ));
99 if( &other ==
this ) {
119 for(
size_t i = 0; i < links_.size(); ++i ) {
120 res.links_[i] = utils::make_unique< TreeLink >();
122 for(
size_t i = 0; i < nodes_.size(); ++i ) {
123 res.nodes_[i] = utils::make_unique< TreeNode >();
125 for(
size_t i = 0; i < edges_.size(); ++i ) {
126 res.edges_[i] = utils::make_unique< TreeEdge >();
130 for(
size_t i = 0; i < links_.size(); ++i ) {
131 auto const& cur_link =
link_at(i);
132 assert( cur_link.index() == i );
134 res.links_[i]->reset_index( i );
135 res.links_[i]->reset_next( res.links_[ cur_link.next().index() ].get() );
136 res.links_[i]->reset_outer( res.links_[ cur_link.outer().index() ].get() );
137 res.links_[i]->reset_node( res.nodes_[ cur_link.node().index() ].get() );
138 res.links_[i]->reset_edge( res.edges_[ cur_link.edge().index() ].get() );
140 for(
size_t i = 0; i < nodes_.size(); ++i ) {
141 auto const& cur_node =
node_at(i);
142 assert( cur_node.index() == i );
144 res.nodes_[i]->reset_index( i );
145 res.nodes_[i]->reset_primary_link( res.links_[ cur_node.link().index() ].get() );
147 for(
size_t i = 0; i < edges_.size(); ++i ) {
148 auto const& cur_edge =
edge_at(i);
149 assert( cur_edge.index() == i );
151 res.edges_[i]->reset_index( i );
152 res.edges_[i]->reset_primary_link( res.links_[ cur_edge.primary_link().index() ].get() );
153 res.edges_[i]->reset_secondary_link( res.links_[ cur_edge.secondary_link().index() ].get() );
157 res.root_link_ = res.links_[ root_link_->
index() ].get();
165 swap( root_link_, other.root_link_ );
167 swap( links_, other.links_ );
168 swap( nodes_, other.nodes_ );
169 swap( edges_, other.edges_ );
174 root_link_ =
nullptr;
186 assert( root_link->
index() < links_.size() );
ContainerType< TreeEdge > EdgeContainerType
Alias for the container type that is used to store TreeEdges.
virtual std::unique_ptr< BaseEdgeData > clone() const
Polymorphically copy an instance of this class. Use instead of copy constructor.
bool has_data() const
Return true if the TreeEdge has a data object assigned to it.
void swap(SequenceSet &lhs, SequenceSet &rhs)
size_t index() const
Return the index of this Link.
size_t edge_count() const
Return the number of TreeEdges of the Tree.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
Provides some valuable additions to STD.
ContainerType< TreeNode > NodeContainerType
Alias for the container type that is used to store TreeNodes.
Tree clone_topology() const
Return a Tree with the same topology, but without any data.
BaseEdgeData * data_ptr()
Return a pointer to the data.
Tree & operator=(Tree const &other)
Assignment operator.
Class for representing phylogenetic trees.
bool has_data() const
Return true if the TreeNode has a data object assigned to it.
size_t link_count() const
Return the number of TreeLinks of the Tree.
Tree & reset_root_link(TreeLink *root_link)
Reset the link that is considered to be the root of the Tree.
TreeNode & node_at(size_t index)
Return the TreeNode at a certain index.
void swap(Tree &other)
Swap.
TreeLink & root_link()
Return the TreeLink at the current root of the Tree.
LinkContainerType & expose_link_container()
Get the container that stores all TreeLinks of the Tree.
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
size_t node_count() const
Return the number of TreeNodes of the Tree.
TreeLink & link_at(size_t index)
Return the TreeLink at a certain index.
void clear()
Deletes all data of the tree, including all links, nodes and edges.
virtual std::unique_ptr< BaseNodeData > clone() const
Polymorphically copy an instance of this class. Use instead of copy constructor.
ContainerType< TreeLink > LinkContainerType
Alias for the container type that is used to store TreeLinks.
TreeNode & reset_data(std::unique_ptr< BaseNodeData > data)
Reset the data pointer of this TreeNode.
EdgeContainerType & expose_edge_container()
Get the container that stores all TreeEdges of the Tree.
BaseNodeData * data_ptr()
Return a pointer to the data.
NodeContainerType & expose_node_container()
Get the container that stores all TreeNodes of the Tree.