Blame json_visit.h

Packit ea8578
Packit ea8578
#ifndef _json_c_json_visit_h_
Packit ea8578
#define _json_c_json_visit_h_
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * @file
Packit ea8578
 * @brief Methods for walking a tree of objects.
Packit ea8578
 */
Packit ea8578
#include "json_object.h"
Packit ea8578
Packit ea8578
typedef int (json_c_visit_userfunc)(json_object *jso, int flags,
Packit ea8578
                                     json_object *parent_jso,                                                        const char *jso_key,
Packit ea8578
                                     size_t *jso_index, void *userarg);
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * Visit each object in the JSON hierarchy starting at jso.
Packit ea8578
 * For each object, userfunc is called, passing the object and userarg.
Packit ea8578
 * If the object has a parent (i.e. anything other than jso itself)
Packit ea8578
 * its parent will be passed as parent_jso, and either jso_key or jso_index
Packit ea8578
 * will be set, depending on whether the parent is an object or an array.
Packit ea8578
 *
Packit ea8578
 * Nodes will be visited depth first, but containers (arrays and objects)
Packit ea8578
 * will be visited twice, the second time with JSON_C_VISIT_SECOND set in
Packit ea8578
 * flags.
Packit ea8578
 *
Packit ea8578
 * userfunc must return one of the defined return values, to indicate
Packit ea8578
 * whether and how to continue visiting nodes, or one of various ways to stop.
Packit ea8578
 *
Packit ea8578
 * Returns 0 if nodes were visited successfully, even if some were 
Packit ea8578
 *  intentionally skipped due to what userfunc returned.
Packit ea8578
 * Returns <0 if an error occurred during iteration, including if
Packit ea8578
 *  userfunc returned JSON_C_VISIT_RETURN_ERROR.
Packit ea8578
 */
Packit ea8578
int json_c_visit(json_object *jso, int future_flags,
Packit ea8578
                 json_c_visit_userfunc *userfunc, void *userarg);
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * Passed to json_c_visit_userfunc as one of the flags values to indicate
Packit ea8578
 * that this is the second time a container (array or object) is being
Packit ea8578
 * called, after all of it's members have been iterated over.
Packit ea8578
 */
Packit ea8578
#define JSON_C_VISIT_SECOND  0x02
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * This json_c_visit_userfunc return value indicates that iteration
Packit ea8578
 * should proceed normally.
Packit ea8578
 */
Packit ea8578
#define JSON_C_VISIT_RETURN_CONTINUE 0
Packit ea8578
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * This json_c_visit_userfunc return value indicates that iteration
Packit ea8578
 * over the members of the current object should be skipped.
Packit ea8578
 * If the current object isn't a container (array or object), this
Packit ea8578
 * is no different than JSON_C_VISIT_RETURN_CONTINUE.
Packit ea8578
 */
Packit ea8578
#define JSON_C_VISIT_RETURN_SKIP 7547
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * This json_c_visit_userfunc return value indicates that iteration
Packit ea8578
 * of the fields/elements of the containing object should stop
Packit ea8578
 * and continue "popped up" a level of the object hierarchy.
Packit ea8578
 * For example, returning this when handling arg will result in 
Packit ea8578
 * arg3 and any other fields being skipped.   The next call to userfunc
Packit ea8578
 * will be the JSON_C_VISIT_SECOND call on "foo", followed by a userfunc
Packit ea8578
 * call on "bar".
Packit ea8578
 * 
Packit ea8578
 * {
Packit ea8578
 *   "foo": {
Packit ea8578
 *     "arg1": 1,
Packit ea8578
 *     "arg2": 2,
Packit ea8578
 *     "arg3": 3,
Packit ea8578
 *     ...
Packit ea8578
 *   },
Packit ea8578
 *   "bar": {
Packit ea8578
 *     ...
Packit ea8578
 *   }
Packit ea8578
 * }
Packit ea8578
 * 
Packit ea8578
 */
Packit ea8578
#define JSON_C_VISIT_RETURN_POP 767
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * This json_c_visit_userfunc return value indicates that iteration
Packit ea8578
 * should stop immediately, and cause json_c_visit to return success.
Packit ea8578
 */
Packit ea8578
#define JSON_C_VISIT_RETURN_STOP 7867
Packit ea8578
Packit ea8578
/**
Packit ea8578
 * This json_c_visit_userfunc return value indicates that iteration
Packit ea8578
 * should stop immediately, and cause json_c_visit to return an error.
Packit ea8578
 */
Packit ea8578
#define JSON_C_VISIT_RETURN_ERROR -1
Packit ea8578
Packit ea8578
#endif /* _json_c_json_visit_h_ */