Function visit_stacked

Summary

#include <src/c4/yml/node.hpp>

(1) template <class Visitor>
    bool visit_stacked(Visitor fn, size_t indentation_level=0, bool skip_root=true)

(2) template <class Visitor>
    bool visit_stacked(Visitor fn, size_t indentation_level=0, bool skip_root=true) const

Function overload

Synopsis

#include <src/c4/yml/node.hpp>

template <class Visitor>
bool visit_stacked(Visitor fn, size_t indentation_level=0, bool skip_root=true)

Description

visit every child node calling fn(node, level)

Source

Lines 832-836 in src/c4/yml/node.hpp. Line 778 in src/c4/yml/node.hpp.

template<class Visitor>
bool NodeRef::visit_stacked(Visitor fn, size_t indentation_level, bool skip_root)
{
    return const_cast< NodeRef const* >(this)->visit_stacked(fn, indentation_level, skip_root);
}

Synopsis

#include <src/c4/yml/node.hpp>

template <class Visitor>
bool visit_stacked(Visitor fn, size_t indentation_level=0, bool skip_root=true) const

Description

visit every child node calling fn(node, level)

Source

Lines 838-864 in src/c4/yml/node.hpp. Line 780 in src/c4/yml/node.hpp.

template<class Visitor>
bool NodeRef::visit_stacked(Visitor fn, size_t indentation_level, bool skip_root) const
{
    size_t increment = 0;
    if( ! (is_root() && skip_root))
    {
        if(fn(this, indentation_level))
        {
            return true;
        }
        ++increment;
    }
    if(has_children())
    {
        fn.push(this, indentation_level);
        for(auto ch : children())
        {
            if(ch.visit(fn, indentation_level + increment)) // no need to forward skip_root as it won't be root
            {
                fn.pop(this, indentation_level);
                return true;
            }
        }
        fn.pop(this, indentation_level);
    }
    return false;
}





Add Discussion as Guest

Log in