| 6 | using PointerType = sonic_json::GenericJsonPointer<sonic_json::StringView>; |
| 7 | |
| 8 | int main() { |
| 9 | std::string json = R"( |
| 10 | { |
| 11 | "a":1, |
| 12 | "b":[ |
| 13 | {"a":1}, |
| 14 | {"b":2} |
| 15 | ] |
| 16 | } |
| 17 | )"; |
| 18 | |
| 19 | sonic_json::Document doc; |
| 20 | if (doc.Parse(json).HasParseError()) { |
| 21 | std::cout << "Parse failed!\n"; |
| 22 | return -1; |
| 23 | } |
| 24 | |
| 25 | sonic_json::Node* node1 = doc.AtPointer(PointerType({"a"})); |
| 26 | if (node1 != nullptr) { |
| 27 | std::cout << "/a exists!\n"; |
| 28 | } else { |
| 29 | std::cout << "/a doesn't exist!\n"; |
| 30 | } |
| 31 | |
| 32 | sonic_json::Node* node2 = doc.AtPointer(PointerType({"b", 1, "a"})); |
| 33 | if (node2 != nullptr) { |
| 34 | std::cout << "/b/1/a Eixsts!\n"; |
| 35 | } else { |
| 36 | std::cout << "/b/1/a doesn't exist!\n"; |
| 37 | } |
| 38 | |
| 39 | sonic_json::Node* node3 = doc.AtPointer("b", 1, "b"); |
| 40 | if (node3 != nullptr) { |
| 41 | std::cout << "/b/1/b Eixsts!\n"; |
| 42 | } else { |
| 43 | std::cout << "/b/1/b doesn't exist!\n"; |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | // g++ -I../include/ -march=haswell --std=c++11 at_pointer.cpp -o at_pointer |
nothing calls this directly
no test coverage detected