| 919 | } |
| 920 | |
| 921 | void |
| 922 | usingPointer() |
| 923 | { |
| 924 | // tag::snippet_pointer_1[] |
| 925 | value jv = { {"one", 1}, {"two", 2} }; |
| 926 | assert( jv.at("one") == jv.at_pointer("/one") ); |
| 927 | |
| 928 | jv.at_pointer("/one") = {{"foo", "bar"}}; |
| 929 | assert( jv.at("one").at("foo") == jv.at_pointer("/one/foo") ); |
| 930 | |
| 931 | jv.at_pointer("/one/foo") = {true, 4, "qwerty"}; |
| 932 | assert( jv.at("one").at("foo").at(1) == jv.at_pointer("/one/foo/1") ); |
| 933 | // end::snippet_pointer_1[] |
| 934 | |
| 935 | value* elem1 = [&]() -> value* |
| 936 | { |
| 937 | // tag::snippet_pointer_2[] |
| 938 | object* obj = jv.if_object(); |
| 939 | if( !obj ) |
| 940 | return nullptr; |
| 941 | |
| 942 | value* val = obj->if_contains("one"); |
| 943 | if( !val ) |
| 944 | return nullptr; |
| 945 | |
| 946 | obj = val->if_object(); |
| 947 | if( !obj ) |
| 948 | return nullptr; |
| 949 | |
| 950 | val = obj->if_contains("foo"); |
| 951 | if( !val ) |
| 952 | return nullptr; |
| 953 | |
| 954 | array* arr = val->if_array(); |
| 955 | if( !arr ) |
| 956 | return nullptr; |
| 957 | |
| 958 | return arr->if_contains(1); |
| 959 | // end::snippet_pointer_2[] |
| 960 | }(); |
| 961 | |
| 962 | value* elem2 = [&]() -> value* |
| 963 | { |
| 964 | // tag::snippet_pointer_3[] |
| 965 | boost::system::error_code ec; |
| 966 | return jv.find_pointer("/one/foo/1", ec); |
| 967 | // end::snippet_pointer_3[] |
| 968 | }(); |
| 969 | |
| 970 | (void)elem1; |
| 971 | (void)elem2; |
| 972 | assert( elem1 == elem2 ); |
| 973 | } |
| 974 | |
| 975 | |
| 976 | void |