-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
71 lines (69 loc) · 1.8 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
#include <iostream>
#include <sstream>
#include <string.h>
#include <thread>
#include "include/simpletoydb.hpp"
using namespace std;
void prompt(toy::IToyDB *db)
{
bool running = true;
while (running)
{
cout << "\n put/get/index/values/init/compact/quit \n >> ";
string command;
std::getline(std::cin, command);
istringstream iss(command);
string cmdname;
iss >> cmdname;
if (cmdname == "init")
{
db->put("name", "Vimal");
db->put("age", "ancient");
db->put("occupation", "jobless");
}
if (cmdname == "put")
{
string name;
iss >> name;
string value;
iss >> value;
db->put(name, value);
}
if (cmdname == "get")
{
string name;
iss >> name;
string value;
db->get(name, value);
cout << "value is : " << value << endl;
}
if (cmdname == "index")
{
simpletoydb::CSimpleToydb *sdb = dynamic_cast<simpletoydb::CSimpleToydb *>(db);
sdb->printoffsets();
}
if (cmdname == "values")
{
simpletoydb::CSimpleToydb *sdb = dynamic_cast<simpletoydb::CSimpleToydb *>(db);
sdb->printvalues();
}
if(cmdname == "compact")
{
simpletoydb::CSimpleToydb *sdb = dynamic_cast<simpletoydb::CSimpleToydb *>(db);
sdb->compact();
}
if (cmdname == "quit")
{
running = false;
}
}
}
int main(int argc, char const *argv[])
{
toy::IToyDB *db = new simpletoydb::CSimpleToydb();
cout << "This is a toy db. This will be fun." << endl;
thread p(prompt, db);
p.join();
delete db;
return 0;
}