rapidyaml  0.12.0
parse and emit YAML, and do it fast
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. More...
 
statem_parent
 parent of the current stack level. More...
 
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

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  }

References c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_curr, c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_src, and c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_stack.

◆ _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

◆ _stack_reset_non_root()

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

◆ _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  }

References c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_curr, c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_parent, and c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_stack.

◆ _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  {
98  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
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  }

References c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_curr, c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_parent, and c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_stack.

◆ _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)
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:39
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition: node_type.hpp:38
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:40
@ DOC
a document
Definition: node_type.hpp:41

References _has_any_, c4::yml::DOC, c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_curr, c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_stack, c4::yml::MAP, c4::yml::SEQ, and c4::yml::VAL.

◆ _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  }

References _has_any_, c4::yml::DOC, and c4::yml::EventHandlerStack< HandlerImpl, HandlerState >::m_stack.

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: