Write a new file test_json.cpp: Using nlohmann json API, read @in0.json , parse it into…
- User
Write a new file
test_json.cpp: Using nlohmann json API, read @in0.json , parse it into the data structures in @routenodes.h , then dump it toout.json--- Content from referenced files --- Content from @C:\routenodes\in0.json: { "Canvas": { "Height": 500, "Width": 500 }, "Blocks": [ { "BlockType": "A", "Height": 20, "Width": 10, "Position": "87,110" }, { "BlockType": "B", "Height": 20, "Width": 10, "Position": "379,40" } ], "Lines": [ { "Line": [ "100,200", "100,300", "200,300" ] }, { "Line": [ "150,300", "150,200" ] } ], "StartNode": "100,100", "EndNode": "200,100" } Content from @C:\routenodes\routenodes.h: #include// 路径方向 enum class Direction { North, South, East, West, None, };
// 路径上的点 struct CustomPoint { float x; float y; Direction direction = Direction::None; };
// 路径 using Path = std::vector;
// 模块信息 struct CompPartInfo { // 模块宽 float width; // 模块高 float height; // 模块所在位置,矩形的左上角坐标 CustomPoint pos; };
// 画布信息 struct CompAndCanvasInfo { // 当前画布的宽 float graphicSceneWidth; // 当前画布的高 float graphicSceneHeight; // 当前画布中所有的模块 std::vector compPartInfos; // 当前画布中所有的路径 std::vector paths;
code// 所求连线的起点 CustomPoint startNode; // 所求连线的终点 CustomPoint endNode;};
void routeNodes(const CompAndCanvasInfo& wsg, Path& path); --- End of content ---
Assistant
Done. I have created the
test_json.cppfile. It readsin0.json, parses it into the data structures fromroutenodes.h, and then writes the result toout.json.