-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue_stack.cpp
More file actions
70 lines (63 loc) · 1.34 KB
/
Copy pathvalue_stack.cpp
File metadata and controls
70 lines (63 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Implementation of the ValueStack class.
* Represents an operand stack for a client connection.
*
* CSF Assignment 5
*
* Ifrah Attar - iattar1@jh.edu
* Morgan Huberty - mhubert3@jh.edu
*
*/
#include "value_stack.h"
#include "exceptions.h"
/**
* @brief Constructs a new, empty ValueStack object.
*/
ValueStack::ValueStack()
{
}
/**
* @brief Destroys the ValueStack object.
*/
ValueStack::~ValueStack()
{
}
/**
* @brief Checks if the stack is empty.
* @return True if the stack is empty, false otherwise.
*/
bool ValueStack::is_empty() const
{
return stack.empty();
}
/**
* @brief Pushes a value onto top of the stack.
* @param value The string value to push.
*/
void ValueStack::push( const std::string &value )
{
stack.push_back(value);
}
/**
* @brief Gets the value at the top of the stack without removing it.
* @return Value at the top of the stack.
* @throw OperationException if the stack is empty.
*/
std::string ValueStack::get_top() const
{
if (is_empty()) {
throw OperationException("Stack is empty");
}
return stack.back();
}
/**
* @brief Removes value from the top of the stack.
* @throw OperationException if the stack is empty.
*/
void ValueStack::pop()
{
if (is_empty()) {
throw OperationException("Stack is empty");
}
stack.pop_back();
}