Repository navigation
Expand file tree
/
Copy pathsearchui.cpp
More file actions
74 lines (67 loc) · 1.91 KB
/
Copy pathsearchui.cpp
File metadata and controls
74 lines (67 loc) · 1.91 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include "searchui.h"
#include "util.h"
using namespace std;
SearchUI::SearchUI(SearchEng* eng)
{
this->eng_ = eng;
this->handlers_ = NULL;
}
/**
* Destructor
*/
SearchUI::~SearchUI() {
delete handlers_;
}
/**
* Add a command handler
*
* @param[in] handler
* Pointer to the handler for a particular command.
*/
void SearchUI::add_handler(Handler* handler)
{
handler->set_next(handlers_);
handlers_ = handler;
}
void SearchUI::run(std::istream& istr, std::ostream& ostr)
{
ostr << "=====================================" << endl;
ostr << "Menu: " << endl;
ostr << " AND term term ... " << endl;
ostr << " OR term term ... " << endl;
ostr << " DIFF term not-present-term not-present-term ... " << endl;
ostr << " PRINT page " << endl;
ostr << " INCOMING page " << endl;
ostr << " OUTGOING page " << endl;
ostr << " QUIT " << endl;
ostr << "=====================================" << endl;
Handler::HANDLER_STATUS_T status = Handler::HANDLER_OK;
while (status != Handler::HANDLER_QUIT)
{
ostr << "\nsearch-shell (prompt) $: ";
string line;
if(getline(istr, line))
{
ostr << endl;
stringstream ss(line);
string cmd;
if ((ss >> cmd)) {
// convert to upper case
cmd = conv_to_upper(cmd);
// Invoke the chain of responsibility
status = handlers_->handle(eng_, cmd, ss, ostr);
if (status == Handler::HANDLER_ERROR)
{
ostr << "Error" << endl;
}
}
}
else {
status = Handler::HANDLER_QUIT;
}
}
}