You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

json_visit.h 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef _json_c_json_visit_h_
  2. #define _json_c_json_visit_h_
  3. /**
  4. * @file
  5. * @brief Methods for walking a tree of objects.
  6. */
  7. #include "json_object.h"
  8. typedef int(json_c_visit_userfunc)(json_object *jso, int flags, json_object *parent_jso,
  9. const char *jso_key, size_t *jso_index, void *userarg);
  10. /**
  11. * Visit each object in the JSON hierarchy starting at jso.
  12. * For each object, userfunc is called, passing the object and userarg.
  13. * If the object has a parent (i.e. anything other than jso itself)
  14. * its parent will be passed as parent_jso, and either jso_key or jso_index
  15. * will be set, depending on whether the parent is an object or an array.
  16. *
  17. * Nodes will be visited depth first, but containers (arrays and objects)
  18. * will be visited twice, the second time with JSON_C_VISIT_SECOND set in
  19. * flags.
  20. *
  21. * userfunc must return one of the defined return values, to indicate
  22. * whether and how to continue visiting nodes, or one of various ways to stop.
  23. *
  24. * Returns 0 if nodes were visited successfully, even if some were
  25. * intentionally skipped due to what userfunc returned.
  26. * Returns <0 if an error occurred during iteration, including if
  27. * userfunc returned JSON_C_VISIT_RETURN_ERROR.
  28. */
  29. JSON_EXPORT int json_c_visit(json_object *jso, int future_flags, json_c_visit_userfunc *userfunc,
  30. void *userarg);
  31. /**
  32. * Passed to json_c_visit_userfunc as one of the flags values to indicate
  33. * that this is the second time a container (array or object) is being
  34. * called, after all of it's members have been iterated over.
  35. */
  36. #define JSON_C_VISIT_SECOND 0x02
  37. /**
  38. * This json_c_visit_userfunc return value indicates that iteration
  39. * should proceed normally.
  40. */
  41. #define JSON_C_VISIT_RETURN_CONTINUE 0
  42. /**
  43. * This json_c_visit_userfunc return value indicates that iteration
  44. * over the members of the current object should be skipped.
  45. * If the current object isn't a container (array or object), this
  46. * is no different than JSON_C_VISIT_RETURN_CONTINUE.
  47. */
  48. #define JSON_C_VISIT_RETURN_SKIP 7547
  49. /**
  50. * This json_c_visit_userfunc return value indicates that iteration
  51. * of the fields/elements of the <b>containing</b> object should stop
  52. * and continue "popped up" a level of the object hierarchy.
  53. * For example, returning this when handling arg will result in
  54. * arg3 and any other fields being skipped. The next call to userfunc
  55. * will be the JSON_C_VISIT_SECOND call on "foo", followed by a userfunc
  56. * call on "bar".
  57. * <pre>
  58. * {
  59. * "foo": {
  60. * "arg1": 1,
  61. * "arg2": 2,
  62. * "arg3": 3,
  63. * ...
  64. * },
  65. * "bar": {
  66. * ...
  67. * }
  68. * }
  69. * </pre>
  70. */
  71. #define JSON_C_VISIT_RETURN_POP 767
  72. /**
  73. * This json_c_visit_userfunc return value indicates that iteration
  74. * should stop immediately, and cause json_c_visit to return success.
  75. */
  76. #define JSON_C_VISIT_RETURN_STOP 7867
  77. /**
  78. * This json_c_visit_userfunc return value indicates that iteration
  79. * should stop immediately, and cause json_c_visit to return an error.
  80. */
  81. #define JSON_C_VISIT_RETURN_ERROR -1
  82. #endif /* _json_c_json_visit_h_ */