-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.hpp
More file actions
61 lines (45 loc) · 1.51 KB
/
controller.hpp
File metadata and controls
61 lines (45 loc) · 1.51 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
58
/*
* controller.hpp
*
* Created on: Dec 6, 2010
* Author: Fei Huang
* Email: felix.fei.huang@yale.edu
*/
#pragma once
#include <vector>
#include <map>
#include <boost/shared_ptr.hpp>
#include "basicchatclient.hpp"
#include "view.hpp"
#include "command.hpp"
using namespace std;
namespace openchat {
/**
* Controller is the "controller" in MVC architecture and is responsible for manipulating Client's state
*/
class Controller {
public:
Controller(boost::shared_ptr<BasicChatClient> model, boost::shared_ptr<View> view, istream &is)
: model_(model), view_(view), is_(is) {
initCommandDescriptions();
}
virtual ~Controller() { }
void processIncomingMessage(const string &rawMessage, boost::shared_ptr<udp::endpoint> remoteEndpoint);
bool processUserInput(const string &input);
// print the basic instruction to users
void presentOpeningLine() const {
view_->presentLine("Type \"help\" for usage, \"history\" for checking command history, \"undo\" for undoing the last command, and \"exit\" for leaving.");
}
private:
boost::shared_ptr<BasicChatClient> model_;
boost::shared_ptr<View> view_;
istream &is_;
// store the history of used commands, supporting undo operation
vector<boost::shared_ptr<Command> > commandHistory_;
// store the description of commands
map<string, string> commandDescriptions_;
void initCommandDescriptions();
// create a command for certain command name, using Factory Method Pattern
boost::shared_ptr<Command> createCommand(const string &commandName);
};
}