|
7 | 7 | #include <rapidjson/prettywriter.h>
|
8 | 8 | #include <rapidjson/stringbuffer.h>
|
9 | 9 | #include <string>
|
| 10 | +#include <unordered_map> |
10 | 11 |
|
11 | 12 | using WDocument = rapidjson::GenericDocument<rapidjson::UTF16<>>;
|
12 | 13 | using WValue = rapidjson::GenericValue<rapidjson::UTF16<>>;
|
@@ -92,6 +93,32 @@ namespace domutils
|
92 | 93 | }
|
93 | 94 | }
|
94 | 95 |
|
| 96 | + void makeNodeIdToNodeMap(WValue& nodeTree, std::unordered_map<int, WValue*>& map) |
| 97 | + { |
| 98 | + map.insert_or_assign(nodeTree[L"nodeId"].GetInt(), &nodeTree); |
| 99 | + if (nodeTree.HasMember(L"children") && nodeTree[L"children"].IsArray()) |
| 100 | + { |
| 101 | + for (auto& child : nodeTree[L"children"].GetArray()) |
| 102 | + { |
| 103 | + map.insert_or_assign(child[L"nodeId"].GetInt(), &child); |
| 104 | + makeNodeIdToNodeMap(child, map); |
| 105 | + } |
| 106 | + } |
| 107 | + if (nodeTree.HasMember(L"contentDocument")) |
| 108 | + { |
| 109 | + auto& contentDocument = nodeTree[L"contentDocument"]; |
| 110 | + map.insert_or_assign(contentDocument[L"nodeId"].GetInt(), &contentDocument); |
| 111 | + makeNodeIdToNodeMap(contentDocument, map); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + std::unordered_map<int, WValue*> makeNodeIdToNodeMap(WValue& nodeTree) |
| 116 | + { |
| 117 | + std::unordered_map<int, WValue*> map; |
| 118 | + makeNodeIdToNodeMap(nodeTree, map); |
| 119 | + return map; |
| 120 | + } |
| 121 | + |
95 | 122 | std::pair<WValue*, WValue*> findNodeId(WValue& nodeTree, int nodeId)
|
96 | 123 | {
|
97 | 124 | if (nodeTree[L"nodeId"].GetInt() == nodeId)
|
|
0 commit comments