-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.cpp
42 lines (36 loc) · 1.11 KB
/
model.cpp
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
#include "include/model.h"
#include "include/shift_visitor.h"
#include <sstream>
QueueModel::QueueModel() : _queue(), _lastAction() {}
std::string QueueModel::GetQueueString() const {
std::ostringstream stream;
stream << _queue;
return stream.str();
}
std::string QueueModel::GetStatusString() const {
std::ostringstream stream;
stream << _lastAction << ", "
<< "size: " << _queue.Size();
return stream.str();
}
void QueueModel::Push(const std::string& val) {
_queue.Push(val);
std::ostringstream stream;
stream << "pushed \"" << val << "\"";
_lastAction = stream.str();
SendEvent(ModelUpdateEvent(GetQueueString(), GetStatusString()));
}
void QueueModel::Pop() {
std::string val = _queue.Pop();
std::ostringstream stream;
stream << "popped \"" << val << "\"";
_lastAction = stream.str();
SendEvent(ModelUpdateEvent(GetQueueString(), GetStatusString()));
}
void QueueModel::Shift() {
_queue.Accept(ShiftVisitor<Queue<std::string>>());
std::ostringstream stream;
stream << "shifted 1 left";
_lastAction = stream.str();
SendEvent(ModelUpdateEvent(GetQueueString(), GetStatusString()));
}