rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
c4::yml::EventHandlerStack< HandlerImpl, HandlerState > Struct Template Reference

Use this class a base of implementations of event handler to simplify the stack logic. More...

#include <event_handler_stack.hpp>

Public Types

using state = HandlerState

Public Attributes

detail::stack< statem_stack
statem_curr
 current stack level: top of the stack. cached here for easier access.
statem_parent
 parent of the current stack level.
substr m_src

Protected Member Functions

 EventHandlerStack ()
 EventHandlerStack (Callbacks const &cb)
void _stack_start_parse (const char *filename, substr ymlsrc)
void _stack_finish_parse ()
void _stack_reset_root ()
void _stack_reset_non_root ()
void _stack_push ()
void _stack_pop ()
bool _stack_should_push_on_begin_doc () const
bool _stack_should_pop_on_end_doc () const

Detailed Description

template<class HandlerImpl, class HandlerState>
struct c4::yml::EventHandlerStack< HandlerImpl, HandlerState >

Use this class a base of implementations of event handler to simplify the stack logic.

Definition at line 37 of file event_handler_stack.hpp.

Member Typedef Documentation

◆ state

template<class HandlerImpl, class HandlerState>
using c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::state = HandlerState

Definition at line 42 of file event_handler_stack.hpp.

Constructor & Destructor Documentation

◆ EventHandlerStack() [1/2]

template<class HandlerImpl, class HandlerState>
c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::EventHandlerStack ( )
inlineprotected

Definition at line 53 of file event_handler_stack.hpp.

53: m_stack(), m_curr(), m_parent(), m_src() {} // NOLINT
state * m_curr
current stack level: top of the stack. cached here for easier access.
detail::stack< state > m_stack
state * m_parent
parent of the current stack level.

◆ EventHandlerStack() [2/2]

template<class HandlerImpl, class HandlerState>
c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::EventHandlerStack ( Callbacks const & cb)
inlineprotected

Definition at line 54 of file event_handler_stack.hpp.

54: m_stack(cb), m_curr(), m_parent(), m_src() {} // NOLINT
Use this class a base of implementations of event handler to simplify the stack logic.

Member Function Documentation

◆ _stack_start_parse()

template<class HandlerImpl, class HandlerState>
void c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_start_parse ( const char * filename,
substr ymlsrc )
inlineprotected

Definition at line 58 of file event_handler_stack.hpp.

59 {
60 _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_curr != nullptr);
61 m_curr->start_parse(filename, m_curr->node_id);
62 m_src = ymlsrc;
63 }

◆ _stack_finish_parse()

template<class HandlerImpl, class HandlerState>
void c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_finish_parse ( )
inlineprotected

Definition at line 65 of file event_handler_stack.hpp.

66 {
67 }

◆ _stack_reset_root()

template<class HandlerImpl, class HandlerState>
void c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_reset_root ( )
inlineprotected

Definition at line 71 of file event_handler_stack.hpp.

72 {
73 m_stack.clear();
74 m_stack.push({});
75 m_parent = nullptr;
76 m_curr = &m_stack.top();
77 }

◆ _stack_reset_non_root()

template<class HandlerImpl, class HandlerState>
void c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_reset_non_root ( )
inlineprotected

Definition at line 79 of file event_handler_stack.hpp.

80 {
81 m_stack.clear();
82 m_stack.push({}); // parent
83 m_stack.push({}); // node
84 m_parent = &m_stack.top(1);
85 m_curr = &m_stack.top();
86 }

◆ _stack_push()

template<class HandlerImpl, class HandlerState>
void c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_push ( )
inlineprotected

Definition at line 88 of file event_handler_stack.hpp.

89 {
90 m_stack.push_top();
91 m_parent = &m_stack.top(1); // don't use m_curr. watch out for relocations inside the prev push
92 m_curr = &m_stack.top();
93 m_curr->reset_after_push();
94 }

◆ _stack_pop()

template<class HandlerImpl, class HandlerState>
void c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_pop ( )
inlineprotected

Definition at line 96 of file event_handler_stack.hpp.

97 {
99 _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_stack.size() > 1);
100 m_parent->reset_before_pop(*m_curr);
101 m_stack.pop();
102 m_parent = m_stack.size() > 1 ? &m_stack.top(1) : nullptr;
103 m_curr = &m_stack.top();
104 #ifdef RYML_DBG
105 if(m_parent)
106 _c4dbgpf("popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id);
107 else
108 _c4dbgpf("popped! top is now node={} @ ROOT", m_curr->node_id);
109 #endif
110 }

◆ _stack_should_push_on_begin_doc()

template<class HandlerImpl, class HandlerState>
bool c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_should_push_on_begin_doc ( ) const
inlineprotected

Definition at line 121 of file event_handler_stack.hpp.

122 {
123 const bool is_root = (m_stack.size() == 1u);
124 return is_root && (m_curr->has_children || _has_any_(DOC|VAL|MAP|SEQ));
125 }
#define _has_any_(bits)

◆ _stack_should_pop_on_end_doc()

template<class HandlerImpl, class HandlerState>
bool c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::_stack_should_pop_on_end_doc ( ) const
inlineprotected

Definition at line 127 of file event_handler_stack.hpp.

128 {
129 const bool is_root = (m_stack.size() == 1u);
130 return !is_root && _has_any_(DOC);
131 }

Member Data Documentation

◆ m_stack

template<class HandlerImpl, class HandlerState>
detail::stack<state> c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_stack

Definition at line 46 of file event_handler_stack.hpp.

◆ m_curr

template<class HandlerImpl, class HandlerState>
state* c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_curr

current stack level: top of the stack. cached here for easier access.

Definition at line 47 of file event_handler_stack.hpp.

◆ m_parent

template<class HandlerImpl, class HandlerState>
state* c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_parent

parent of the current stack level.

Definition at line 48 of file event_handler_stack.hpp.

◆ m_src

template<class HandlerImpl, class HandlerState>
substr c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_src

Definition at line 49 of file event_handler_stack.hpp.


The documentation for this struct was generated from the following file: