blob: fcbee8033738244a3259cca4761a393d5a63e7fd (
plain)
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
|
/*
* ConsoleModel.cpp
*
* Created on: Feb 1, 2012
* Author: Simon
*/
#include "ConsoleModel.h"
ConsoleModel::ConsoleModel() {
}
void ConsoleModel::AddObserver(ConsoleView * observer)
{
observers.push_back(observer);
}
int ConsoleModel::GetCurrentCommandIndex()
{
return currentCommandIndex;
}
void ConsoleModel::SetCurrentCommandIndex(int index)
{
currentCommandIndex = index;
notifyCurrentCommandChanged();
}
ConsoleCommand ConsoleModel::GetCurrentCommand()
{
if(currentCommandIndex < 0 || currentCommandIndex >= previousCommands.size())
{
return ConsoleCommand("", 0, "");
}
return previousCommands[currentCommandIndex];
}
void ConsoleModel::AddLastCommand(ConsoleCommand command)
{
previousCommands.push_back(command);
if(previousCommands.size()>25)
previousCommands.pop_front();
currentCommandIndex = previousCommands.size();
notifyPreviousCommandsChanged();
}
std::deque<ConsoleCommand> ConsoleModel::GetPreviousCommands()
{
return previousCommands;
}
void ConsoleModel::notifyPreviousCommandsChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyPreviousCommandsChanged(this);
}
}
void ConsoleModel::notifyCurrentCommandChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyCurrentCommandChanged(this);
}
}
ConsoleModel::~ConsoleModel() {
}
|