Implements GTNode::level and GTNode::all_nodes.

This commit is contained in:
Williham Williham Totland 2020-04-29 13:11:22 +02:00 committed by Joakim Hove
parent c22a7e5b46
commit 8af0d505cf
2 changed files with 17 additions and 0 deletions

View File

@ -39,6 +39,9 @@ public:
const std::string& name() const;
const GTNode& parent() const;
const Group& group() const;
std::size_t level() const;
std::vector<const GTNode*> all_nodes() const;
private:
const Group m_group;
const GTNode * m_parent;

View File

@ -58,5 +58,19 @@ const std::vector<GTNode>& GTNode::groups() const {
return this->m_child_groups;
}
std::vector<const GTNode*> GTNode::all_nodes() const {
std::vector<const GTNode*> subs { this } ;
std::transform(m_child_groups.begin(), m_child_groups.end(), std::back_inserter(subs), [](const GTNode& node) { return &node; });
return subs;
}
std::size_t GTNode::level() const {
if (!m_parent) {
return 0;
} else {
return m_parent->level() + 1;
}
}
}