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

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