1 #ifndef GENESIS_TREE_FUNCTION_OPERATORS_H_
2 #define GENESIS_TREE_FUNCTION_OPERATORS_H_
62 template<
class NodeDataType,
class EdgeDataType >
66 for(
auto const& node : tree.
nodes() ) {
67 if( ! node->has_data() ) {
70 auto const& ref = *node->data_ptr();
71 if(
typeid( ref ) !=
typeid( NodeDataType )) {
77 for(
auto const& edge : tree.
edges() ) {
78 if( ! edge->has_data() ) {
81 auto const& ref = *edge->data_ptr();
82 if(
typeid( ref ) !=
typeid( EdgeDataType )) {
97 template<
class NodeDataType,
class EdgeDataType >
101 for(
auto const& node : tree.
nodes() ) {
102 if( dynamic_cast< NodeDataType const* >( node->data_ptr() ) ==
nullptr ) {
108 for(
auto const& edge : tree.
edges() ) {
109 if( dynamic_cast< EdgeDataType const* >( edge->data_ptr() ) ==
nullptr ) {
123 std::function< std::unique_ptr<BaseNodeData>( BaseNodeData
const& node_data )> node_data_converter,
124 std::function< std::unique_ptr<BaseEdgeData>( BaseEdgeData
const& edge_data )> edge_data_converter
134 std::function<
bool ( TreeNode
const&, TreeNode
const&) > node_comparator,
135 std::function<
bool ( TreeEdge
const&, TreeEdge
const&) > edge_comparator
142 bool belongs_to( Tree
const& tree, TreeNode
const& node );
143 bool belongs_to( TreeNode
const& node, Tree
const& tree );
144 bool belongs_to( Tree
const& tree, TreeEdge
const& edge );
145 bool belongs_to( TreeEdge
const& edge, Tree
const& tree );
146 bool belongs_to( Tree
const& tree, TreeLink
const& link );
147 bool belongs_to( TreeLink
const& link, Tree
const& tree );
150 TreeEdge
const*
edge_between( TreeNode
const& lhs, TreeNode
const& rhs );
156 std::ostream&
operator << ( std::ostream& out, Tree
const& tree );
167 #endif // include guard
Tree convert(Tree const &source, std::function< std::unique_ptr< BaseNodeData >(BaseNodeData const &node_data)> node_data_converter, std::function< std::unique_ptr< BaseEdgeData >(BaseEdgeData const &edge_data)> edge_data_converter)
Create a tree with the same topology as the source tree, while converting its data.
bool tree_data_is(Tree const &tree)
Check whether the data of the nodes and edges of the Tree are exactly of the specified data types...
bool tree_data_is_derived_from(Tree const &tree)
Check whether the data of the nodes and edges of the Tree are derived from the specified data types...
utils::Range< IteratorNodes > nodes()
TreeEdge * edge_between(TreeNode &lhs, TreeNode &rhs)
Return the TreeEdge between two TreeNode&s, if they are neighbours, or nullptr otherwise.
utils::Range< IteratorEdges > edges()
Class for representing phylogenetic trees.
bool belongs_to(Tree const &tree, TreeNode const &node)
Return whether the TreeNode belongs to the Tree, i.e., whether it is owned by the Tree...
bool validate_topology(Tree const &tree)
Validate that all internal pointers of the Tree elements (TreeLinks, TreeNodes, TreeEdges) to each ot...
bool identical_topology(Tree const &lhs, Tree const &rhs)
Returns true iff both trees have an identical topology.
std::ostream & operator<<(std::ostream &out, Tree const &tree)
bool equal(Tree const &lhs, Tree const &rhs, std::function< bool(TreeNode const &, TreeNode const &) > node_comparator, std::function< bool(TreeEdge const &, TreeEdge const &) > edge_comparator)
Compares two trees for equality given binary comparator functionals for their nodes and edges...