-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualize.cpp
More file actions
57 lines (48 loc) · 1.57 KB
/
Visualize.cpp
File metadata and controls
57 lines (48 loc) · 1.57 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
#include "Visualize.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include "Orihsay/misc/CharHelper.h"
Visualize* Visualize::_instance = nullptr;
void Visualize::add(VisualizeShape* shape){
shapes.push_back(shape);
}
Visualize::~Visualize(){
for (int i = 0; i < shapes.size(); i++){
if (shapes[i] != nullptr){
delete shapes[i];
}
}
shapes.clear();
}
void Visualize::flush(){
rapidjson::Document jsonDoc;
jsonDoc.SetObject();
rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator();
jsonDoc.AddMember("type", "visualizer0", allocator);
rapidjson::Value vertexArray(rapidjson::kArrayType);
for (int i = 0; i < shapes.size(); i++){
VisualizeShape* iter = shapes[i];
rapidjson::Value objValue;
objValue.SetObject();
char tempName[32];
char tempDesc[128];
iter->getType32(tempName);
iter->getDesc128(tempDesc);
rapidjson::Value typeObj(rapidjson::kStringType);
typeObj.SetString(tempName, allocator);
objValue.AddMember("type", typeObj, allocator);
rapidjson::Value descObj(rapidjson::kStringType);
descObj.SetString(tempDesc, allocator);
objValue.AddMember("desc", descObj, allocator);
vertexArray.PushBack(objValue, allocator);
}
jsonDoc.AddMember("shape_array", vertexArray, allocator);
rapidjson::StringBuffer strbuf;
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
jsonDoc.Accept(writer);
CharBuffer outBuffer;
outBuffer.buffer = const_cast<char *>(strbuf.GetString());
outBuffer.length = strbuf.GetSize();
CharHelper::writeTextFile("visualize.json", outBuffer);
}