7#ifndef AUX_STATE_STACK_H
8#define AUX_STATE_STACK_H
15 template <
typename StateT>
16 class StateStack final
20 friend class StateStack;
22 Accessor() : m_state(nullptr) { }
23 void Set(StateT& state) { m_state = &state; }
25 StateT* operator->() {
return m_state; }
26 const StateT* operator->()
const {
return m_state; }
27 StateT& operator*() {
return *m_state; }
28 const StateT& operator*()
const {
return *m_state; }
38 bool PopLenient(
unsigned popCount = 1);
39 void Pop(
unsigned popCount = 1);
41 unsigned GetSize()
const;
43 void push(
const StateT& state);
45 std::stack<StateT> m_states;
48 template <
typename StateT>
49 StateStack<StateT>::StateStack()
54 template <
typename StateT>
55 void StateStack<StateT>::Push()
60 template <
typename StateT>
61 bool StateStack<StateT>::PopLenient(
unsigned popCount)
63 if (popCount >= m_states.size())
66 for (
unsigned i = 0; i < popCount; i++)
69 Current.Set(m_states.top());
73 template<
typename StateT>
74 inline void StateStack<StateT>::Pop(
unsigned popCount)
76 if (popCount >= m_states.size())
77 throw std::runtime_error(
"Can't pop out all the states in the stack");
79 for (
unsigned i = 0; i < popCount; i++)
82 Current.Set(m_states.top());
85 template <
typename StateT>
86 void StateStack<StateT>::Clear()
88 for (
unsigned i = 0; i < m_states.size(); i++)
94 template <
typename StateT>
95 unsigned StateStack<StateT>::GetSize()
const
97 return (
unsigned)m_states.size();
100 template <
typename StateT>
101 void StateStack<StateT>::push(
const StateT& state)
103 m_states.push(state);
104 Current.Set(m_states.top());
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
@ Push
Display the fields down appearance (requires an additional appearance stream to be set)