MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / main

Function main

example/create_and_destroy_map.cpp:16–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16int 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

Callers

nothing calls this directly

Calls 7

get_json_stringFunction · 0.85
HasParseErrorMethod · 0.80
ParseMethod · 0.80
IsObjectMethod · 0.80
FindMemberMethod · 0.80
CreateMapMethod · 0.80
DestroyMapMethod · 0.80

Tested by

no test coverage detected