acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
stack.h
1
#pragma once
2
3
4
template
<
class
TYPE,
class
ARG_TYPE = const TYPE &,
class
BASE_CONTAINER = deque < TYPE, ARG_TYPE > >
5
class
stack
:
6
public
BASE_CONTAINER
7
{
8
public
:
9
10
11
inline
TYPE * operator ->()
12
{
13
return
&BASE_CONTAINER::last();
14
}
15
16
inline
const
TYPE * operator ->()
const
17
{
18
return
&BASE_CONTAINER::last();
19
}
20
21
inline
TYPE & top
22
{
23
return
BASE_CONTAINER::last();
24
}
25
26
inline
const
TYPE & top
const
27
{
28
return
BASE_CONTAINER::last();
29
}
30
31
inline
void
push(ARG_TYPE t)
32
{
33
BASE_CONTAINER::add(t);
34
}
35
36
inline
TYPE pop(index n = -1)
37
{
38
39
::collection::index i = this->get_upper_bound(n);
40
41
TYPE t = this->element_at(i);
42
43
this->erase_at(i);
44
45
return
t;
46
47
}
48
49
50
inline
TYPE pop_to()
51
{
52
53
TYPE lastelement = this->pop();
54
55
this->last() = lastelement;
56
57
return
this->last();
58
59
}
60
61
inline
void
push_last()
62
{
63
64
this->add(this->last());
65
66
}
67
68
69
};
70
71
72
template
<
class
TYPE,
class
ARG_TYPE = const TYPE & >
73
class
raw_stack
:
74
virtual
public
stack
< TYPE, raw_array < TYPE, ARG_TYPE > >
75
{
76
public
:
77
78
79
};
80
81
template
<
class
TYPE,
class
STACK = stack < TYPE > >
82
class
stacker
83
{
84
public
:
85
86
STACK & m_stack;
87
88
stacker(STACK &
stack
) :
89
m_stack(
stack
)
90
{
91
m_stack.add_new();
92
m_stack.last() = m_stack.last(-2);
93
}
94
95
~stacker()
96
{
97
m_stack.pop();
98
}
99
100
TYPE * operator ->()
101
{
102
return
&m_stack.last();
103
}
104
105
const
TYPE * operator ->()
const
106
{
107
return
&m_stack.last();
108
}
109
110
};
111
112
113
114
raw_stack
Definition
stack.h:75
stack
Definition
stack.h:7
prototype
collection
stack.h
Generated by
1.17.0