Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
12
#include "
core/types.h
"
13
#include "
util/array.h
"
14
15
//------------------------------------------------------------------------------
16
namespace
Util
17
{
18
template
<
class
TYPE>
class
Stack
19
{
20
public
:
22
Stack
();
24
Stack
(
const
Stack<TYPE>
& rhs);
25
27
void
operator=
(
const
Stack<TYPE>
& rhs);
29
TYPE&
operator[]
(
IndexT
index)
const
;
31
bool
operator==
(
const
Stack<TYPE>
& rhs)
const
;
33
bool
operator!=
(
const
Stack<TYPE>
& rhs)
const
;
35
SizeT
Size
()
const
;
37
bool
IsEmpty
()
const
;
39
void
Clear
();
41
bool
Contains
(
const
TYPE& e)
const
;
43
void
EraseIndex
(
const
IndexT
i);
44
46
void
Push
(
const
TYPE& e);
48
TYPE&
Peek
()
const
;
50
TYPE
Pop
();
51
52
private
:
53
Array<TYPE>
stackArray
;
54
};
55
56
//------------------------------------------------------------------------------
59
template
<
class
TYPE>
60
Stack<TYPE>::Stack
()
61
{
62
// empty
63
}
64
65
//------------------------------------------------------------------------------
68
template
<
class
TYPE>
69
Stack<TYPE>::Stack
(
const
Stack<TYPE>
& rhs)
70
{
71
this->
stackArray
= rhs.
stackArray
;
72
}
73
74
//------------------------------------------------------------------------------
77
template
<
class
TYPE>
78
void
79
Stack<TYPE>::operator=
(
const
Stack<TYPE>
& rhs)
80
{
81
this->
stackArray
= rhs.
stackArray
;
82
}
83
84
//------------------------------------------------------------------------------
87
template
<
class
TYPE>
88
TYPE&
89
Stack<TYPE>::operator[]
(
IndexT
index)
const
90
{
91
return
this->
stackArray
[this->
stackArray
.Size() - 1 - index];
92
}
93
94
//------------------------------------------------------------------------------
97
template
<
class
TYPE>
98
bool
99
Stack<TYPE>::operator==
(
const
Stack<TYPE>
& rhs)
const
100
{
101
return
this->
stackArray
== rhs.
stackArray
;
102
}
103
104
//------------------------------------------------------------------------------
107
template
<
class
TYPE>
108
bool
109
Stack<TYPE>::operator!=
(
const
Stack<TYPE>
& rhs)
const
110
{
111
return
this->
stackArray
!= rhs.
stackArray
;
112
}
113
114
//------------------------------------------------------------------------------
117
template
<
class
TYPE>
118
bool
119
Stack<TYPE>::Contains
(
const
TYPE& e)
const
120
{
121
return
(
InvalidIndex
!= this->
stackArray
.FindIndex(e));
122
}
123
124
//------------------------------------------------------------------------------
127
template
<
class
TYPE>
128
void
129
Stack<TYPE>::Clear
()
130
{
131
this->
stackArray
.Clear();
132
}
133
134
//------------------------------------------------------------------------------
137
template
<
class
TYPE>
138
SizeT
139
Stack<TYPE>::Size
()
const
140
{
141
return
this->
stackArray
.Size();
142
}
143
144
//------------------------------------------------------------------------------
147
template
<
class
TYPE>
148
bool
149
Stack<TYPE>::IsEmpty
()
const
150
{
151
return
this->
stackArray
.IsEmpty();
152
}
153
154
//------------------------------------------------------------------------------
157
template
<
class
TYPE>
158
void
159
Util::Stack<TYPE>::EraseIndex
(
const
IndexT
i)
160
{
161
this->
stackArray
.EraseIndex(i);
162
}
163
164
//------------------------------------------------------------------------------
167
template
<
class
TYPE>
168
void
169
Stack<TYPE>::Push
(
const
TYPE& e)
170
{
171
this->
stackArray
.Append(e);
172
}
173
174
//------------------------------------------------------------------------------
177
template
<
class
TYPE>
178
TYPE&
179
Stack<TYPE>::Peek
()
const
180
{
181
return
this->
stackArray
.Back();
182
}
183
184
//------------------------------------------------------------------------------
187
template
<
class
TYPE>
188
TYPE
189
Stack<TYPE>::Pop
()
190
{
191
TYPE e = this->
stackArray
.Back();
192
this->
stackArray
.EraseIndex(this->
stackArray
.Size() - 1);
193
return
e;
194
}
195
196
197
}
// namespace Util
198
//------------------------------------------------------------------------------
array.h
Util::Array
Nebula's dynamic array class.
Definition
array.h:61
Util::Stack::Stack
Stack()
constructor
Definition
stack.h:60
Util::Stack::Push
void Push(const TYPE &e)
push an element on the stack
Definition
stack.h:169
Util::Stack::Pop
TYPE Pop()
get topmost element of stack, remove element
Definition
stack.h:189
Util::Stack::Contains
bool Contains(const TYPE &e) const
return true if stack contains element
Definition
stack.h:119
Util::Stack::Size
SizeT Size() const
returns number of elements on stack
Definition
stack.h:139
Util::Stack::operator=
void operator=(const Stack< TYPE > &rhs)
assignment operator
Definition
stack.h:79
Util::Stack::EraseIndex
void EraseIndex(const IndexT i)
erase element at index
Definition
stack.h:159
Util::Stack::operator!=
bool operator!=(const Stack< TYPE > &rhs) const
inequality operator
Definition
stack.h:109
Util::Stack::IsEmpty
bool IsEmpty() const
returns true if stack is empty
Definition
stack.h:149
Util::Stack::Clear
void Clear()
remove all elements from the stack
Definition
stack.h:129
Util::Stack::operator[]
TYPE & operator[](IndexT index) const
access element by index, 0 is the topmost element
Definition
stack.h:89
Util::Stack::Peek
TYPE & Peek() const
get reference of topmost element of stack, without removing it
Definition
stack.h:179
Util::Stack::stackArray
Array< TYPE > stackArray
Definition
stack.h:53
Util::Stack::operator==
bool operator==(const Stack< TYPE > &rhs) const
equality operator
Definition
stack.h:99
Util
A quad tree designed to return regions of free 2D space.
Definition
String.cs:6
types.h
InvalidIndex
static const int InvalidIndex
Definition
types.h:47
SizeT
int SizeT
Definition
types.h:42
IndexT
int IndexT
Definition
types.h:41
code
foundation
util
stack.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.