-
-
Notifications
You must be signed in to change notification settings - Fork 443
Expand file tree
/
Copy pathobject_Oriented_Graph.cpp
More file actions
78 lines (69 loc) · 1.55 KB
/
Copy pathobject_Oriented_Graph.cpp
File metadata and controls
78 lines (69 loc) · 1.55 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
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <jsoncons/json.hpp>
#include <cassert>
using namespace jsoncons; // for convenience
using namespace std;
// visualize `myGraphJson`!
string myGraphJson = "{\"kind\":{\"graph\":true},"
"\"nodes\":[{\"id\":\"1\"},{\"id\":\"2\"}],"
"\"edges\":[{\"from\":\"1\",\"to\":\"2\"}]}";
class Graph
{
private:
char *tempPtr = NULL;
char *constPtr = NULL;
ojson j;
public:
Graph()
{
tempPtr = new char[myGraphJson.length() + 1];
strcpy(tempPtr, myGraphJson.c_str());
constPtr = tempPtr;
j = ojson::parse(constPtr);
}
~Graph()
{
delete[] constPtr;
constPtr = NULL;
tempPtr = NULL;
}
void addNode(string NodeValue)
{
multimap<string, string> Node;
Node.emplace("id", NodeValue);
Node.emplace("label", NodeValue);
Node.emplace("color", "orange");
j["nodes"].push_back(Node);
}
void addEdge(string from, string to)
{
multimap<string, string> Edge;
Edge.emplace("from", from);
Edge.emplace("to", to);
Edge.emplace("color", "blue");
j["edges"].push_back(Edge);
}
void visualize()
{
myGraphJson = "";
j.dump(myGraphJson);
}
};
int main()
{
Graph *g1 = new Graph(); // apply breakpoint here
// put command once "-exec set print elements 0" in debug console
g1->visualize();
g1->addNode("3");
g1->visualize();
g1->addNode("4");
g1->visualize();
g1->addEdge("1", "3");
g1->visualize();
g1->addEdge("1", "4");
g1->visualize();
return 0;
}