-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstack.js
87 lines (71 loc) · 1.35 KB
/
stack.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
/*
* Stack
* - stackMode (enum)
* - string
* - float
* - array
* */
let StackMode = require("./stackMode.js");
module.exports = class Stack {
constructor() {
this.string = "";
this.float = 0.0;
this.array = [];
this.stackMode = StackMode.STRING;
}
// clone
clone() {
var _stack = new Stack();
_stack.setString(this.getString());
_stack.setFloat(this.getFloat());
_stack.setArray(this.getArray());
_stack.setStackMode(this.getStackMode());
return _stack;
}
// reset all data to falsey values
clearAll() {
this.setString("");
this.setFloat(0.0);
this.setArray([]);
}
getStack() {
return this.stackMode === StackMode.STRING ? this.string
: this.stackMode === StackMode.FLOAT ? this.float
: this.array;
}
getStackMode() {
return this.stackMode;
}
get(mode) {
return mode === StackMode.STRING ? this.string
: mode === StackMode.FLOAT ? this.float
: this.array;
}
getString() {
return this.string;
}
getFloat() {
return this.float;
}
getArray() {
return this.array;
}
setStackMode(arg) {
this.stackMode = arg;
}
set(mode, arg) {
if(mode === StackMode.STRING) this.string = arg;
else if(mode === StackMode.FLOAT) this.float = arg;
else this.array = arg;
}
setString(str) {
this.string = str;
}
setFloat(f) {
this.float = f;
}
setArray(arr) {
this.array = arr;
}
}