-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.hpp
65 lines (59 loc) · 1.28 KB
/
Command.hpp
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
#pragma once
#include <vector>
#include <string>
#include <sstream>
#include "UDF.hpp"
#include "FileSystem.hpp"
enum CommandType {
COMMAND_TYPE_CD = 0,
COMMAND_TYPE_DIR,
COMMAND_TYPE_CP,
COMMAND_TYPE_EXIT,
COMMAND_TYPE_FDISK
};
class Command
{
protected:
enum CommandType type;
std::vector<std::string> arguments;
UDF::Info *i;
public:
void setUDFInfo(UDF::Info *i) {
this->i = i;
}
virtual bool execute(FileSystem &tree, UDF& udf) = 0;
void addArgument(std::string argument) {
this->arguments.push_back(argument);
}
unsigned int getArgumentNumber() {
return arguments.size();
}
std::vector<std::string> &getArgumentList() {
return arguments;
}
std::string getArgument(unsigned int i) {
unsigned int count = 0;
std::vector<std::string>::iterator it;
if (i >= arguments.size()) {
return "";
}
it = arguments.begin();
while (count < i) {
it++;
count++;
}
return *it;
}
std::vector<std::string> splitPath(std::string path, char delimiter) {
std::vector<std::string> result;
std::stringstream data(path);
std::string line;
while (std::getline(data, line, delimiter)) {
if (line != "") {
result.push_back(line);
}
}
return result;
}
virtual ~Command(){}
};