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.2 kB

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