/
CommandParser.cpp
34 lines (30 loc) · 940 Bytes
/
CommandParser.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
#include <iostream>
#include "UDF.hpp"
#include "CommandParser.hpp"
#include "ParseLinkFDISK.hpp"
#include "ParseLinkEXIT.hpp"
#include "ParseLinkDIR.hpp"
#include "ParseLinkCD.hpp"
#include "ParseLinkCP.hpp"
CommandParser::CommandParser() {
chainOfResponsibility = new ParseLinkFDISK;
chainOfResponsibility->next = new ParseLinkCP;
chainOfResponsibility->next->next = new ParseLinkEXIT;
chainOfResponsibility->next->next->next = new ParseLinkDIR;
chainOfResponsibility->next->next->next->next = new ParseLinkCD;
}
Command *CommandParser::parse(std::string commandString) {
ParseLink *pl;
pl = chainOfResponsibility;
while (pl != NULL) {
if (pl->test(commandString)) {
return pl->parse(commandString);
}
pl = pl->next;
}
std::cout<<"Unrecognized command."<<std::endl;
return NULL;
}
bool CommandParser::execute(FileSystem &fs, Command *command, UDF *udf) {
return command->execute(fs, *udf);
}