-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
127 lines (103 loc) · 3.39 KB
/
Main.cpp
File metadata and controls
127 lines (103 loc) · 3.39 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include "TreeDB.h"
#include "TreeNode.h"
#include "DBentry.h"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
string input;
string command;
TreeDB tree;
cout << "> ";
getline(cin, input);
while (!cin.eof()) {
stringstream linestream(input);
linestream >> command;
//parse insert function
if (command == "insert") {
string name;
int IPaddress;
string status;
DBentry* temp;
linestream >> name >> IPaddress >> status;
if (status == "active")
temp = new DBentry(name, IPaddress, 1);
else
temp = new DBentry(name, IPaddress, 0);
bool success = tree.insert(temp);
if (success)
cout << "Success" << endl;
else
cout << "Error: entry already exists" << endl;
}
//parse find function
else if (command == "find") {
string name;
linestream >> name;
DBentry* temp = tree.find(name);
if (temp == NULL)
cout << "Error: entry does not exist" << endl;
else if (temp -> getActive())
cout << temp -> getName() << " : " << temp -> getIPaddress() << " : active" << endl;
else
cout << temp -> getName() << " : " << temp -> getIPaddress() << " : inactive" << endl;
}
//parse remove function
else if (command == "remove") {
string name;
linestream >> name;
bool removed = tree.remove(name);
if (removed)
cout << "Success" << endl;
else
cout << "Error: entry does not exist" << endl;
}
//parse printall function
else if (command == "printall") {
cout << tree;
}
//parse printprobes function
else if (command == "printprobes") {
string name;
linestream >> name;
DBentry* temp = tree.find(name);
if (temp == NULL)
cout << "Error: entry does not exist" << endl;
else
tree.printProbes();
}
//parse removeall function
else if (command == "removeall") {
tree.clear();
cout << "Success" << endl;
}
//parse countactive function
else if (command == "countactive") {
tree.countActive();
}
//parse updatestatus function
else if (command == "updatestatus") {
string name;
string status;
linestream >> name >> status;
DBentry* temp = tree.find(name);
if (temp == NULL)
cout << "Error: entry does not exist" << endl;
else {
if (status == "active")
temp -> setActive(true);
else if (status == "inactive")
temp -> setActive(false);
cout << "Success" << endl;
}
}
cout << "> ";
getline(cin, input);
}
return 0;
}