This is from the javadoc
| 26 | public: |
| 27 | // This is from the javadoc |
| 28 | void |
| 29 | testValueStack() |
| 30 | { |
| 31 | |
| 32 | //---------------------------------- |
| 33 | // value_stack |
| 34 | { |
| 35 | // This example builds a json::value without any dynamic memory allocations: |
| 36 | |
| 37 | // Construct the value stack using a local buffer |
| 38 | unsigned char temp[4096]; |
| 39 | value_stack st( storage_ptr(), temp, sizeof(temp) ); |
| 40 | |
| 41 | // Create a static resource with a local initial buffer |
| 42 | unsigned char buf[4096]; |
| 43 | static_resource mr( buf, sizeof(buf) ); |
| 44 | |
| 45 | // All values on the stack will use `mr` |
| 46 | st.reset(&mr); |
| 47 | |
| 48 | // Push the key/value pair "a":1. |
| 49 | st.push_key("a"); |
| 50 | st.push_int64(1); |
| 51 | |
| 52 | // Push "b":null |
| 53 | st.push_key("b"); |
| 54 | st.push_null(); |
| 55 | |
| 56 | // Push "c":"hello" |
| 57 | st.push_key("c"); |
| 58 | st.push_string("hello"); |
| 59 | |
| 60 | // Pop the three key/value pairs and push an object with those three values. |
| 61 | st.push_object(3); |
| 62 | |
| 63 | // Pop the object from the stack and take ownership. |
| 64 | value jv = st.release(); |
| 65 | |
| 66 | assert( serialize(jv) == "{\"a\":1,\"b\":null,\"c\":\"hello\"}" ); |
| 67 | |
| 68 | // At this point we could re-use the stack by calling reset |
| 69 | } |
| 70 | |
| 71 | //---------------------------------- |
| 72 | // value_stack::push_array |
| 73 | { |
| 74 | value_stack st; |
| 75 | |
| 76 | // reset must be called first or else the behavior is undefined |
| 77 | st.reset(); |
| 78 | |
| 79 | // Place three values on the stack |
| 80 | st.push_int64( 1 ); |
| 81 | st.push_int64( 2 ); |
| 82 | st.push_int64( 3 ); |
| 83 | |
| 84 | // Remove the 3 values, and push an array with those 3 elements on the stack |
| 85 | st.push_array( 3 ); |
nothing calls this directly
no test coverage detected