-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster_stack.cpp
More file actions
57 lines (49 loc) · 1.16 KB
/
master_stack.cpp
File metadata and controls
57 lines (49 loc) · 1.16 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
#include "master_stack.hpp"
#include "fluid_wm.hpp"
#include <algorithm>
#include <iostream>
#include <vector>
MasterStack::MasterStack()
{
}
int MasterStack::stackSize()
{
return stack.size();
}
bool MasterStack::empty()
{
return stack.size() == 0;
}
void MasterStack::insert(Window w)
{
stack.push_back(w);
}
void MasterStack::erase(Window w)
{
std::vector<Window>::iterator pos = find(stack.begin(), stack.end(), w);
if (pos == stack.end()) {
std::cout << "Error: Window not found\n";
return;
}
stack.erase(pos);
}
void MasterStack::swapMaster(Window stack_window)
{
std::vector<Window>::iterator posCurrent = find(stack.begin(), stack.end(), stack[0]);
std::vector<Window>::iterator posStack = find(stack.begin(), stack.end(), stack_window);
if (posCurrent == stack.end() || posStack == stack.end()) {
std::cout << "Error: Window not found\n";
return;
}
std::swap(*posCurrent, *posStack);
}
Window MasterStack::getMaster()
{
return stack[0];
}
void MasterStack::printStack()
{
for (int i = 0; i < stackSize(); i++) {
std::cout << i + 1 << " " << stack[i] << std::endl;
}
}