|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
*******************************************************************************
|
|
Packit Service |
def718 |
* @file json_object_iterator.h
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* This library is free software; you can redistribute it and/or modify
|
|
Packit Service |
def718 |
* it under the terms of the MIT license. See COPYING for details.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @brief An API for iterating over json_type_object objects,
|
|
Packit Service |
def718 |
* styled to be familiar to C++ programmers.
|
|
Packit Service |
def718 |
* Unlike json_object_object_foreach() and
|
|
Packit Service |
def718 |
* json_object_object_foreachC(), this avoids the need to expose
|
|
Packit Service |
def718 |
* json-c internals like lh_entry.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* API attributes:
|
|
Packit Service |
def718 |
* * Thread-safe: NO
|
|
Packit Service |
def718 |
* * Reentrant: NO
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
*******************************************************************************
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifndef JSON_OBJECT_ITERATOR_H
|
|
Packit Service |
def718 |
#define JSON_OBJECT_ITERATOR_H
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#include <stddef.h>
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifdef __cplusplus
|
|
Packit Service |
def718 |
extern "C" {
|
|
Packit Service |
def718 |
#endif
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Forward declaration for the opaque iterator information.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
struct json_object_iter_info_;
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* The opaque iterator that references a name/value pair within
|
|
Packit Service |
def718 |
* a JSON Object instance or the "end" iterator value.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
struct json_object_iterator {
|
|
Packit Service |
def718 |
const void* opaque_;
|
|
Packit Service |
def718 |
};
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* forward declaration of json-c's JSON value instance structure
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
struct json_object;
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/**
|
|
Packit Service |
def718 |
* Initializes an iterator structure to a "default" value that
|
|
Packit Service |
def718 |
* is convenient for initializing an iterator variable to a
|
|
Packit Service |
def718 |
* default state (e.g., initialization list in a class'
|
|
Packit Service |
def718 |
* constructor).
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @code
|
|
Packit Service |
def718 |
* struct json_object_iterator iter = json_object_iter_init_default();
|
|
Packit Service |
def718 |
* MyClass() : iter_(json_object_iter_init_default())
|
|
Packit Service |
def718 |
* @endcode
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @note The initialized value doesn't reference any specific
|
|
Packit Service |
def718 |
* pair, is considered an invalid iterator, and MUST NOT
|
|
Packit Service |
def718 |
* be passed to any json-c API that expects a valid
|
|
Packit Service |
def718 |
* iterator.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @note User and internal code MUST NOT make any assumptions
|
|
Packit Service |
def718 |
* about and dependencies on the value of the "default"
|
|
Packit Service |
def718 |
* iterator value.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @return json_object_iterator
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
struct json_object_iterator
|
|
Packit Service |
def718 |
json_object_iter_init_default(void);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/** Retrieves an iterator to the first pair of the JSON Object.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @warning Any modification of the underlying pair invalidates all
|
|
Packit Service |
def718 |
* iterators to that pair.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @param obj JSON Object instance (MUST be of type json_object)
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @return json_object_iterator If the JSON Object has at
|
|
Packit Service |
def718 |
* least one pair, on return, the iterator refers
|
|
Packit Service |
def718 |
* to the first pair. If the JSON Object doesn't
|
|
Packit Service |
def718 |
* have any pairs, the returned iterator is
|
|
Packit Service |
def718 |
* equivalent to the "end" iterator for the same
|
|
Packit Service |
def718 |
* JSON Object instance.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @code
|
|
Packit Service |
def718 |
* struct json_object_iterator it;
|
|
Packit Service |
def718 |
* struct json_object_iterator itEnd;
|
|
Packit Service |
def718 |
* struct json_object* obj;
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* obj = json_tokener_parse("{'first':'george', 'age':100}");
|
|
Packit Service |
def718 |
* it = json_object_iter_begin(obj);
|
|
Packit Service |
def718 |
* itEnd = json_object_iter_end(obj);
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* while (!json_object_iter_equal(&it, &itEnd)) {
|
|
Packit Service |
def718 |
* printf("%s\n",
|
|
Packit Service |
def718 |
* json_object_iter_peek_name(&it);;
|
|
Packit Service |
def718 |
* json_object_iter_next(&it);
|
|
Packit Service |
def718 |
* }
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @endcode
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
struct json_object_iterator
|
|
Packit Service |
def718 |
json_object_iter_begin(struct json_object* obj);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/** Retrieves the iterator that represents the position beyond the
|
|
Packit Service |
def718 |
* last pair of the given JSON Object instance.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @warning Do NOT write code that assumes that the "end"
|
|
Packit Service |
def718 |
* iterator value is NULL, even if it is so in a
|
|
Packit Service |
def718 |
* particular instance of the implementation.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @note The reason we do not (and MUST NOT) provide
|
|
Packit Service |
def718 |
* "json_object_iter_is_end(json_object_iterator* iter)"
|
|
Packit Service |
def718 |
* type of API is because it would limit the underlying
|
|
Packit Service |
def718 |
* representation of name/value containment (or force us
|
|
Packit Service |
def718 |
* to add additional, otherwise unnecessary, fields to
|
|
Packit Service |
def718 |
* the iterator structure). The "end" iterator and the
|
|
Packit Service |
def718 |
* equality test method, on the other hand, permit us to
|
|
Packit Service |
def718 |
* cleanly abstract pretty much any reasonable underlying
|
|
Packit Service |
def718 |
* representation without burdening the iterator
|
|
Packit Service |
def718 |
* structure with unnecessary data.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @note For performance reasons, memorize the "end" iterator prior
|
|
Packit Service |
def718 |
* to any loop.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @param obj JSON Object instance (MUST be of type json_object)
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @return json_object_iterator On return, the iterator refers
|
|
Packit Service |
def718 |
* to the "end" of the Object instance's pairs
|
|
Packit Service |
def718 |
* (i.e., NOT the last pair, but "beyond the last
|
|
Packit Service |
def718 |
* pair" value)
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
struct json_object_iterator
|
|
Packit Service |
def718 |
json_object_iter_end(const struct json_object* obj);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/** Returns an iterator to the next pair, if any
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @warning Any modification of the underlying pair
|
|
Packit Service |
def718 |
* invalidates all iterators to that pair.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @param iter [IN/OUT] Pointer to iterator that references a
|
|
Packit Service |
def718 |
* name/value pair; MUST be a valid, non-end iterator.
|
|
Packit Service |
def718 |
* WARNING: bad things will happen if invalid or "end"
|
|
Packit Service |
def718 |
* iterator is passed. Upon return will contain the
|
|
Packit Service |
def718 |
* reference to the next pair if there is one; if there
|
|
Packit Service |
def718 |
* are no more pairs, will contain the "end" iterator
|
|
Packit Service |
def718 |
* value, which may be compared against the return value
|
|
Packit Service |
def718 |
* of json_object_iter_end() for the same JSON Object
|
|
Packit Service |
def718 |
* instance.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
void
|
|
Packit Service |
def718 |
json_object_iter_next(struct json_object_iterator* iter);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/** Returns a const pointer to the name of the pair referenced
|
|
Packit Service |
def718 |
* by the given iterator.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @param iter pointer to iterator that references a name/value
|
|
Packit Service |
def718 |
* pair; MUST be a valid, non-end iterator.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @warning bad things will happen if an invalid or
|
|
Packit Service |
def718 |
* "end" iterator is passed.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @return const char* Pointer to the name of the referenced
|
|
Packit Service |
def718 |
* name/value pair. The name memory belongs to the
|
|
Packit Service |
def718 |
* name/value pair, will be freed when the pair is
|
|
Packit Service |
def718 |
* deleted or modified, and MUST NOT be modified or
|
|
Packit Service |
def718 |
* freed by the user.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
const char*
|
|
Packit Service |
def718 |
json_object_iter_peek_name(const struct json_object_iterator* iter);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/** Returns a pointer to the json-c instance representing the
|
|
Packit Service |
def718 |
* value of the referenced name/value pair, without altering
|
|
Packit Service |
def718 |
* the instance's reference count.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @param iter pointer to iterator that references a name/value
|
|
Packit Service |
def718 |
* pair; MUST be a valid, non-end iterator.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @warning bad things will happen if invalid or
|
|
Packit Service |
def718 |
* "end" iterator is passed.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @return struct json_object* Pointer to the json-c value
|
|
Packit Service |
def718 |
* instance of the referenced name/value pair; the
|
|
Packit Service |
def718 |
* value's reference count is not changed by this
|
|
Packit Service |
def718 |
* function: if you plan to hold on to this json-c node,
|
|
Packit Service |
def718 |
* take a look at json_object_get() and
|
|
Packit Service |
def718 |
* json_object_put(). IMPORTANT: json-c API represents
|
|
Packit Service |
def718 |
* the JSON Null value as a NULL json_object instance
|
|
Packit Service |
def718 |
* pointer.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
struct json_object*
|
|
Packit Service |
def718 |
json_object_iter_peek_value(const struct json_object_iterator* iter);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
/** Tests two iterators for equality. Typically used to test
|
|
Packit Service |
def718 |
* for end of iteration by comparing an iterator to the
|
|
Packit Service |
def718 |
* corresponding "end" iterator (that was derived from the same
|
|
Packit Service |
def718 |
* JSON Object instance).
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @note The reason we do not (and MUST NOT) provide
|
|
Packit Service |
def718 |
* "json_object_iter_is_end(json_object_iterator* iter)"
|
|
Packit Service |
def718 |
* type of API is because it would limit the underlying
|
|
Packit Service |
def718 |
* representation of name/value containment (or force us
|
|
Packit Service |
def718 |
* to add additional, otherwise unnecessary, fields to
|
|
Packit Service |
def718 |
* the iterator structure). The equality test method, on
|
|
Packit Service |
def718 |
* the other hand, permits us to cleanly abstract pretty
|
|
Packit Service |
def718 |
* much any reasonable underlying representation.
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @param iter1 Pointer to first valid, non-NULL iterator
|
|
Packit Service |
def718 |
* @param iter2 POinter to second valid, non-NULL iterator
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @warning if a NULL iterator pointer or an uninitialized
|
|
Packit Service |
def718 |
* or invalid iterator, or iterators derived from
|
|
Packit Service |
def718 |
* different JSON Object instances are passed, bad things
|
|
Packit Service |
def718 |
* will happen!
|
|
Packit Service |
def718 |
*
|
|
Packit Service |
def718 |
* @return json_bool non-zero if iterators are equal (i.e., both
|
|
Packit Service |
def718 |
* reference the same name/value pair or are both at
|
|
Packit Service |
def718 |
* "end"); zero if they are not equal.
|
|
Packit Service |
def718 |
*/
|
|
Packit Service |
def718 |
json_bool
|
|
Packit Service |
def718 |
json_object_iter_equal(const struct json_object_iterator* iter1,
|
|
Packit Service |
def718 |
const struct json_object_iterator* iter2);
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifdef __cplusplus
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
#endif
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#endif /* JSON_OBJECT_ITERATOR_H */
|