11#ifndef TREE_H_INCLUDED
12#define TREE_H_INCLUDED
28template <
class CellT>
class Tree
33 std::vector<Tree<CellT>> m_children;
102 const CellT &
cell()
const;
142 return m_parent !=
nullptr;
161 for (
auto const &child : this->m_children)
163 child.visit_cells_by_pre_order_DFS(op);
177 for (
auto &child : this->m_children)
179 child.visit_subtrees_by_pre_order_DFS(op);
183 template <
typename Op1,
typename Op2,
typename Op3>
184 void visit_subtrees_by_generic_DFS(Op1 preorder, Op2 inorder, Op3 postorder)
187 for (
auto &child : this->m_children)
189 child.visit_subtrees_by_generic_DFS(preorder, inorder, postorder);
201 auto const &parent()
const
207 unsigned int nb_children()
const
209 return m_children.size();
222 for (
auto const &child : this->m_children)
224 child.visit_leaves_cells_by_DFS(op);
238template <
typename CellT>
Tree<CellT>::Tree(
const CellT &cell) : m_parent(nullptr), m_cell(cell), m_children()
242template <
typename CellT>
243Tree<CellT>::Tree(CellT &&cell) noexcept : m_parent(
nullptr), m_cell(std::move(cell)), m_children()
247template <
class CellT>
251 child.m_parent =
this;
254template <
class CellT>
256 : m_parent(
nullptr), m_cell(std::move(other.m_cell)), m_children(std::move(other.m_children))
259 child.m_parent =
this;
262template <
class CellT>
264 : m_parent(
nullptr), m_cell(std::move(cell)), m_children(std::move(children))
267 child.m_parent =
this;
273 *
this = std::move(otherCopy);
279 m_cell = std::move(other.m_cell);
280 m_children = std::move(other.m_children);
282 child.m_parent =
this;
299 otherCopy.m_parent =
this;
300 m_children.push_back(std::move(otherCopy));
306 subtree.m_parent =
this;
307 m_children.push_back(std::move(subtree));
314 subtree.m_parent =
this;
315 m_children.push_back(std::move(subtree));
316 return m_children.back();
321 return !m_children.empty();
Data structure for representing tree topologies where each node contains a data field.
Definition Tree.hpp:29
Tree< CellT > & add_child(const Tree< CellT > &subtree)
Add a subtree to the children list of the tree.
Definition Tree.hpp:296
const CellT & cell() const
Cell accessor.
Definition Tree.hpp:286
void visit_subtrees_by_pre_order_DFS(UnaryOperation op)
Applies a function object to each node encountered in a depth first search algorithm.
Definition Tree.hpp:174
bool has_children() const
Checks whether the tree has one or more child.
Definition Tree.hpp:319
Tree()
Default constructor.
Definition Tree.hpp:234
Tree< CellT > & operator=(const Tree< CellT > &other)
Copy assignment operator.
Definition Tree.hpp:270
void visit_leaves_cells_by_DFS(UnaryOperation op) const
Applies a function object to each leave encountered in a depth first search algorithm.
Definition Tree.hpp:218
bool has_parent() const
Checks whether the tree has a parent.
Definition Tree.hpp:140
void visit_cells_by_pre_order_DFS(UnaryOperation op) const
Applies a function object to each node encountered in a depth first search algorithm.
Definition Tree.hpp:158
Simulation of coalescence-based models of molecular evolution.
Definition coalescence.hpp:21