-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLI.cpp
56 lines (50 loc) · 1.44 KB
/
CLI.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
//
// Hod Amar and Ofek Avergil
//
#include "CLI.h"
/**
* constructor
* @param dio - chosen IO object
*/
CLI::CLI(DefaultIO* dio) {
this->dio = dio;
this->data = new AnomalyDetectorData();
//fill the map with the six types of commands
this->options.insert({1,new UploadCommand(this->dio, this->data)});
this->options.insert({2,new SettingsCommand(this->dio, this->data)});
this->options.insert({3,new AnomalyDetectionCommand(this->dio, this->data)});
this->options.insert({4,new ResultCommand(this->dio, this->data)});
this->options.insert({5,new AnalyzeCommand(this->dio, this->data)});
this->options.insert({6,new ExitCommand(this->dio, this->data)});
}
/**
* the function prints the menu, and call the chosen commands.
*/
void CLI::start(){
//print the menu
this->dio->write("Welcome to the Anomaly Detection Server.\n"
"Please choose an option:\n");
for (auto &iter : options) {
this->dio->write(iter.first);
this->dio->write(".");
this->dio->write(iter.second->getDes());
this->dio->write("\n");
}
//direct to the chosen command
float option;
this->dio->read(&option);
if (option >= 1 && option <= 6) {
this->options.find(option)->second->execute();
}
//finish the program if necessary or start over
if (option == 6) {
return;
} else {
this->start();
}
}
/**
* destructor
*/
CLI::~CLI() {
}