1 #ifndef C4_YML_EVENT_HANDLER_STACK_HPP_
2 #define C4_YML_EVENT_HANDLER_STACK_HPP_
4 #ifndef C4_YML_DETAIL_STACK_HPP_
5 #include "c4/yml/detail/stack.hpp"
8 #ifndef C4_YML_NODE_TYPE_HPP_
12 #ifndef C4_YML_DETAIL_DBGPRINT_HPP_
13 #include "c4/yml/detail/dbgprint.hpp"
16 #ifndef C4_YML_PARSER_STATE_HPP_
21 #ifndef C4_YML_DETAIL_PRINT_HPP_
22 #include "c4/yml/detail/print.hpp"
36 template<
class HandlerImpl,
class HandlerState>
39 static_assert(std::is_base_of<ParserState, HandlerState>::value,
40 "ParserState must be a base of HandlerState");
60 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_curr !=
nullptr);
61 m_curr->start_parse(filename, m_curr->node_id);
76 m_curr = &m_stack.top();
84 m_parent = &m_stack.top(1);
85 m_curr = &m_stack.top();
91 m_parent = &m_stack.top(1);
92 m_curr = &m_stack.top();
93 m_curr->reset_after_push();
98 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_parent);
99 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_stack.size() > 1);
100 m_parent->reset_before_pop(*m_curr);
102 m_parent = m_stack.size() > 1 ? &m_stack.top(1) :
nullptr;
103 m_curr = &m_stack.top();
106 _c4dbgpf(
"popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id);
108 _c4dbgpf(
"popped! top is now node={} @ ROOT", m_curr->node_id);
115 #define ryml_has_any_(bits) (static_cast<HandlerImpl const* C4_RESTRICT>(this)->template has_any_<bits>())
123 const bool is_root = (m_stack.size() == 1u);
129 const bool is_root = (m_stack.size() == 1u);
bool _stack_should_pop_on_end_doc() const
#define ryml_has_any_(bits)
EventHandlerIntsState state
Use this class a base of implementations of event handler to simplify the stack logic.
A c-style callbacks class to customize behavior on errors or allocation.
void _stack_reset_non_root()
void _stack_start_parse(const char *filename, substr ymlsrc)
void _stack_finish_parse()
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
EventHandlerStack(Callbacks const &cb)
state * m_parent
parent of the current stack level.
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
detail::stack< state > m_stack
bool _stack_should_push_on_begin_doc() const
a seq: a parent of VAL/SEQ/MAP nodes
state * m_curr
current stack level: top of the stack. cached here for easier access.