V-Gears 0
Free Final Fantasy VII engine.
Stack.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The V-Gears Team
3 *
4 * This file is part of V-Gears
5 *
6 * V-Gears is free software: you can redistribute it and/or modify it under
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, version 3.0 (GPLv3) of the License.
9 *
10 * V-Gears is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#pragma once
17
18#include <deque>
19#include <iostream>
20
24template<typename T> class Stack {
25
26 public:
27
33 bool IsEmpty() const{return stack_.empty();}
34
40 void Push(const T &item){stack_.push_front(item);}
41
47 T Pop(){
48 T retval = stack_.front();
49 stack_.pop_front();
50 return retval;
51 }
52
58 T &Peek(){return stack_.front();}
59
65 const T &Peek() const{return stack_.front();}
66
73 T &PeekPos(size_t pos){
74 if (pos >= stack_.size()) std::cerr << "WARNING: Looking outside stack\n";
75 return stack_.at(pos);
76 }
77
84 const T &PeekPos(size_t pos) const{
85 if (pos >= stack_.size()) std::cerr << "WARNING: Looking outside stack\n";
86 return stack_.at(pos);
87 }
88
89 private:
90
94 std::deque<T> stack_;
95};
96
Stack class based on a deque.
Definition: Stack.h:24
T & Peek()
Return the topmost item on the stack without removing it.
Definition: Stack.h:58
const T & PeekPos(size_t pos) const
Gets item on a specified stack position without removing it.
Definition: Stack.h:84
void Push(const T &item)
Push an item onto the stack.
Definition: Stack.h:40
T Pop()
Pop an item from the stack and return it.
Definition: Stack.h:47
bool IsEmpty() const
Returns whether or not the stack is empty.
Definition: Stack.h:33
const T & Peek() const
Return the topmost item on the stack without removing it.
Definition: Stack.h:65
T & PeekPos(size_t pos)
Gets item on a specified stack position without removing it.
Definition: Stack.h:73
std::deque< T > stack_
The stack.
Definition: Stack.h:94