| 14 | } |
| 15 | |
| 16 | int main() { |
| 17 | std::string json = get_json_string(); |
| 18 | sonic_json::Document doc; |
| 19 | |
| 20 | if (doc.Parse(json).HasParseError()) { |
| 21 | std::cout << "Parse failed!\n"; |
| 22 | return -1; |
| 23 | } |
| 24 | |
| 25 | sonic_json::Node* node = doc.AtPointer("a", 0); |
| 26 | if (node == nullptr || !node->IsObject()) { |
| 27 | std::cout << "/a/0 doesn't exist or isn't an object!\n"; |
| 28 | return -1; |
| 29 | } |
| 30 | |
| 31 | if (node->FindMember("e") == node->MemberEnd()) { |
| 32 | std::cout << "/a/0/e doesn't exist!\n"; |
| 33 | } |
| 34 | |
| 35 | // Create a map. If node already has a map, do nothing. |
| 36 | node->CreateMap(doc.GetAllocator()); // Need Allocator |
| 37 | // Use the map to query. This is same as above. |
| 38 | if (node->FindMember("e") == node->MemberEnd()) { |
| 39 | std::cout << "/a/0/e doesn't exist!\n"; |
| 40 | } |
| 41 | |
| 42 | // Not need the map anymore. |
| 43 | node->DestroyMap(); |
| 44 | |
| 45 | std::cout << "Quering finish!\n"; |
| 46 | return 0; |
| 47 | } |
| 48 | // g++ -I../include/ -march=haswell --std=c++11 create_and_destroy_map.cpp -o |
| 49 | // create_and_destroy_map |
nothing calls this directly
no test coverage detected