A library for working with phylogenetic and population genetic data.
v0.32.0
taxonomy/iterator/postorder.hpp
Go to the documentation of this file.
1
#ifndef GENESIS_TAXONOMY_ITERATOR_POSTORDER_H_
2
#define GENESIS_TAXONOMY_ITERATOR_POSTORDER_H_
3
4
/*
5
Genesis - A toolkit for working with phylogenetic data.
6
Copyright (C) 2014-2020 Lucas Czech
7
8
This program is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21
Contact:
22
Lucas Czech <lucas.czech@h-its.org>
23
Exelixis Lab, Heidelberg Institute for Theoretical Studies
24
Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25
*/
26
34
#include "
genesis/taxonomy/taxonomy.hpp
"
35
#include "
genesis/taxonomy/taxon.hpp
"
36
#include "
genesis/utils/containers/range.hpp
"
37
38
#include <functional>
39
40
namespace
genesis
{
41
namespace
taxonomy {
42
43
// =================================================================================================
44
// Postorder For Each
45
// =================================================================================================
46
57
inline
void
postorder_for_each
(
58
Taxonomy
& tax,
59
std::function<
void
(
Taxon
& )> fn,
60
bool
include_inner_taxa =
true
61
) {
62
for
(
auto
& t : tax ) {
63
postorder_for_each
( t, fn, include_inner_taxa );
64
65
if
( include_inner_taxa || t.size() == 0 ) {
66
fn( t );
67
}
68
}
69
}
70
81
inline
void
postorder_for_each
(
82
Taxonomy
const
& tax,
83
std::function<
void
(
Taxon
const
& )> fn,
84
bool
include_inner_taxa =
true
85
) {
86
for
(
auto
const
& t : tax ) {
87
postorder_for_each
( t, fn, include_inner_taxa );
88
89
if
( include_inner_taxa || t.size() == 0 ) {
90
fn( t );
91
}
92
}
93
}
94
95
}
// namespace taxonomy
96
}
// namespace genesis
97
98
#endif // include guard
genesis::taxonomy::postorder_for_each
void postorder_for_each(Taxonomy &tax, std::function< void(Taxon &)> fn, bool include_inner_taxa=true)
Apply a function to all taxa of the Taxonomy, traversing it in postorder.
Definition:
taxonomy/iterator/postorder.hpp:57
genesis::taxonomy::Taxon
Store a Taxon, i.e., an element in a Taxonomy, with its name, rank, ID and sub-taxa.
Definition:
taxon.hpp:76
taxonomy.hpp
range.hpp
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition:
placement/formats/edge_color.cpp:42
genesis::taxonomy::Taxonomy
Store a Taxonomy, i.e., a nested hierarchy of Taxa.
Definition:
taxonomy/taxonomy.hpp:96
taxon.hpp
lib
genesis
taxonomy
iterator
postorder.hpp
Generated on Mon Aug 5 2024 16:57:52 for genesis by
1.8.17