diff options
Diffstat (limited to 'src/console/ConsoleModel.cpp')
| -rw-r--r-- | src/console/ConsoleModel.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/console/ConsoleModel.cpp b/src/console/ConsoleModel.cpp new file mode 100644 index 0000000..fcbee80 --- /dev/null +++ b/src/console/ConsoleModel.cpp @@ -0,0 +1,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() { + +} + |
