-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppProcessor.cpp
71 lines (58 loc) · 2.45 KB
/
AppProcessor.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
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
// Created by rick gessner on 3/30/18.
// Copyright © 2018 rick gessner. All rights reserved.
//
// Modified by Zongheng Cao after the skeleton All rights reserved.
#include <iostream>
#include "AppProcessor.hpp"
#include "Tokenizer.hpp"
#include <memory>
#include <vector>
#include <algorithm>
namespace ECE141 {
//.....................................
AppCmdProcessor::AppCmdProcessor(CommandProcessor *aNext) : CommandProcessor(aNext) {
}
//1 help
StatusResult doHelpStatement(const Statement& theStatement){
std::cout << "help -- the available list of commands shown below:\n";
std::cout << "-- help - shows this list of commands\n";
std::cout << "-- version -- shows the current version of this application\n";
std::cout << "-- create database <name> -- creates a new database\n";
std::cout << "-- drop database <name> -- drops the given database\n";
std::cout << "-- use database <name> -- uses the given database\n";
std::cout << "-- describe database <name> -- describes the given database\n";
std::cout << "-- show databases -- shows the list of databases available\n";
return StatusResult();
}
//2 version
StatusResult doVersionStatement(const Statement& theStatement){
std::cout << "version ECE141b-10";
return StatusResult();
}
StatusResult doQuitStatement(const Statement& theStatement){
return StatusResult(Errors::userTerminated);
}
// USE: -----------------------------------------------------
StatusResult AppCmdProcessor::interpret(const Statement &aStatement) {
switch(aStatement.getType()){ //type which is a Keywords
case Keywords::help_kw: return doHelpStatement(aStatement); //if debugging clog
case Keywords::version_kw: return doVersionStatement(aStatement);
case Keywords::quit_kw: return doQuitStatement(aStatement);
default: break;
}
return StatusResult();
}
// USE: factory to create statement based on given tokens...
Statement* AppCmdProcessor::getStatement(Tokenizer &aTokenizer) {
std::vector<ECE141::Keywords> theTerms{
{Keywords::help_kw, Keywords::version_kw, Keywords::quit_kw}
};
Token & theToken = aTokenizer.current();
auto it = std::find(theTerms.begin(), theTerms.end(), theToken.keyword);
if(it != theTerms.end()){
aTokenizer.next();
return new Statement(theToken.keyword); //make a statement and its type
}
return nullptr;
}
}