-
Notifications
You must be signed in to change notification settings - Fork 5
/
GraphDB.hpp
107 lines (90 loc) · 2.55 KB
/
GraphDB.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
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
#ifndef __GRAPHDB__
#define __GRAPHDB__
class GraphDB : public IGraphDB
{
public:
GraphDB()
: IGraphDB(), __current(0x0)
{
Protocol::error_code error_code;
this->add("default", error_code);
this->use("default", error_code);
}
~GraphDB()
{}
void use(std::string const& graph_name, Protocol::error_code& error_code)
{
if (this->__exists(graph_name) == false)
{
error_code = Protocol::DOESNT_EXIST;
return;
}
error_code = Protocol::OK;
this->__current = this->__graphs[graph_name];
}
void add(std::string const& graph_name, Protocol::error_code& error_code)
{
if (this->__exists(graph_name) == true)
{
error_code = Protocol::ALREADY_EXIST;
return;
}
error_code = Protocol::OK;
this->__graphs[graph_name] = new Graph();
}
Edge::id add(Vertex::id const from, Vertex::id const to, std::string const& name, Protocol::error_code& error_code)
{
return this->__current->add(from, to, name, error_code);
}
// FIXME : set vertex attributes
Vertex::id add(std::string const& vertex_name, std::vector<std::string> const& args)
{
return this->__current->add(vertex_name, args);
}
void remove(std::string const& graph_name, Protocol::error_code& error_code)
{
if (this->__exists(graph_name) == false)
{
error_code = Protocol::DOESNT_EXIST;
return;
}
error_code = Protocol::OK;
this->__graphs.erase(graph_name);
}
void remove(Vertex::id const id, Protocol::error_code& error_code)
{
this->__current->remove(id, error_code);
}
void remove(Edge::id const& id, Protocol::error_code& error_code)
{
this->__current->remove(id, error_code);
}
Graph* get(std::string const& graph_name, Protocol::error_code& error_code) const
{
if (this->__exists(graph_name) == false)
{
error_code = Protocol::DOESNT_EXIST;
return NULL;
}
error_code = Protocol::OK;
return (this->__graphs.at(graph_name));
}
Vertex::Vertex* get(Vertex::id const id, Protocol::error_code& error_code) const
{
return this->__current->get(id, error_code);
}
Edge::Edge* get(Edge::id const& id, Protocol::error_code& error_code) const
{
return this->__current->get(id, error_code);
}
private:
GraphDB(const GraphDB&);
GraphDB& operator=(const GraphDB&);
bool __exists(std::string const& graph_name) const
{
return this->__graphs.find(graph_name) != this->__graphs.end();
}
Graph* __current;
std::map<std::string, Graph*> __graphs;
};
#endif /* __GRAPHDB__ */