-
-
Notifications
You must be signed in to change notification settings - Fork 441
Expand file tree
/
Copy pathstructural_Programming_Graph.cpp
More file actions
52 lines (47 loc) · 1.42 KB
/
structural_Programming_Graph.cpp
File metadata and controls
52 lines (47 loc) · 1.42 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
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <jsoncons/json.hpp>
#include <cassert>
using namespace jsoncons; // for convenience
using namespace std;
void addNode(ojson &j, 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(ojson &j, 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);
}
int main()
{
// visualize `myGraphJson`!
string myGraphJson = "{\"kind\":{\"graph\":true},"
"\"nodes\":[{\"id\":\"1\"},{\"id\":\"2\"}],"
"\"edges\":[{\"from\":\"1\",\"to\":\"2\"}]}";
char *tempPtr = new char[myGraphJson.length() + 1];
strcpy(tempPtr, myGraphJson.c_str());
char *constPtr = tempPtr;
ojson j = ojson::parse(constPtr);
string temps1, temps2, temps3; // apply breakpoint here
// put command once "-exec set print elements 0" in debug console
addNode(j, "3");
j.dump(temps1); // visualize temps1
cout << myGraphJson;
addNode(j, "4");
addEdge(j, "1", "3");
j.dump(temps2); // visualize temps2
cout << myGraphJson;
addEdge(j, "1", "4");
j.dump(temps3); // visualize temps3
cout << myGraphJson;
}