-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
93 lines (85 loc) · 2.41 KB
/
Main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* File: Main.cpp
* Author: Matthew
*
* Created on November 14, 2016, 5:23 PM
*/
#include <cstdlib>
#include <iostream>
#include <sstream>
#include "TreeDB.h"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
string input,cmd,name,status;
bool statusBool;
unsigned int ip;
TreeDB tree;
DBentry* entry;
do{
cout << "> ";
getline(cin,input);
stringstream ss(input);
ss >> cmd;
if(cmd=="insert"){
ss >> name;
ss >> ip;
ss >> status;
if(status=="active") statusBool = true;
else statusBool = false;
entry = new DBentry(name,ip,statusBool);
if(tree.insert(entry)) //It was inserted
cout << "Success" << endl;
else //It already exists
cout << "Error: entry already exists" << endl;
}
else if(cmd=="find"){
ss >> name;
entry = tree.find(name);
if(entry==NULL) //'name' was not found
cout << "Error: entry does not exist" << endl;
else //Determine its status, print
entry->print();
}
else if(cmd=="remove"){
ss >> name;
if(tree.remove(name))
cout << "Success" << endl;
else
cout << "Error: entry does not exist" << endl;
}
else if(cmd=="printall")
tree.print();
else if(cmd=="printprobes"){
ss >> name;
if(tree.find(name)!=NULL) //'name' exists
tree.printProbes();
else
cout << "Error: entry does not exist" << endl;
}
else if(cmd=="removeall"){
tree.clear();
cout << "Success" << endl;
}
else if(cmd=="countactive")
tree.countActive();
else if(cmd=="updatestatus"){
ss >> name;
ss >> status;
entry = tree.find(name);
if(entry==NULL)
cout << "Error: entry does not exist" << endl;
else{
if(status=="active")
entry->setActive(true);
else if(status=="inactive")
entry->setActive(false);
cout << "Success" << endl;
}
}
}while(!cin.eof());
tree.clear();
return 0;
}