MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
json_object_iterator.c File Reference

json-c forces clients to use its private data structures for JSON Object iteration. This API implementation corrects that by abstracting the private json-c details. More...

#include <stddef.h>
#include "json.h"
#include "json_object_private.h"
#include "json_object_iterator.h"

Go to the source code of this file.

Functions

struct json_object_iterator json_object_iter_begin (struct json_object *obj)
 
struct json_object_iterator json_object_iter_end (const struct json_object *obj)
 
void json_object_iter_next (struct json_object_iterator *iter)
 
const char * json_object_iter_peek_name (const struct json_object_iterator *iter)
 
struct json_objectjson_object_iter_peek_value (const struct json_object_iterator *iter)
 
json_bool json_object_iter_equal (const struct json_object_iterator *iter1, const struct json_object_iterator *iter2)
 
struct json_object_iterator json_object_iter_init_default (void)
 

Variables

static const void * kObjectEndIterValue = NULL
 

Detailed Description

json-c forces clients to use its private data structures for JSON Object iteration. This API implementation corrects that by abstracting the private json-c details.

Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See COPYING for details.

Definition in file json_object_iterator.c.

Function Documentation

struct json_object_iterator json_object_iter_begin ( struct json_object obj)

Note
json_object_get_object will return NULL if passed NULL or a non-json_type_object instance
For a pair-less Object, head is NULL, which matches our definition of the "end" iterator

Definition at line 67 of file json_object_iterator.c.

struct json_object_iterator json_object_iter_end ( const struct json_object obj)

Definition at line 87 of file json_object_iterator.c.

void json_object_iter_next ( struct json_object_iterator iter)

Definition at line 103 of file json_object_iterator.c.

const char* json_object_iter_peek_name ( const struct json_object_iterator iter)

Definition at line 116 of file json_object_iterator.c.

struct json_object* json_object_iter_peek_value ( const struct json_object_iterator iter)

Definition at line 129 of file json_object_iterator.c.

json_bool json_object_iter_equal ( const struct json_object_iterator iter1,
const struct json_object_iterator iter2 
)

Definition at line 142 of file json_object_iterator.c.

struct json_object_iterator json_object_iter_init_default ( void  )

Note
Make this a negative, invalid value, such that accidental access to it would likely be trapped by the hardware as an invalid address.

Definition at line 156 of file json_object_iterator.c.

Variable Documentation

const void* kObjectEndIterValue = NULL
static

How It Works

For each JSON Object, json-c maintains a linked list of zero or more lh_entry (link-hash entry) structures inside the Object's link-hash table (lh_table).

Each lh_entry structure on the JSON Object's linked list represents a single name/value pair. The "next" field of the last lh_entry in the list is set to NULL, which terminates the list.

We represent a valid iterator that refers to an actual name/value pair via a pointer to the pair's lh_entry structure set as the iterator's opaque_ field.

We follow json-c's current pair list representation by representing a valid "end" iterator (one that refers past the last pair) with a NULL value in the iterator's opaque_ field.

A JSON Object without any pairs in it will have the "head" field of its lh_table structure set to NULL. For such an object, json_object_iter_begin will return an iterator with the opaque_ field set to NULL, which is equivalent to the "end" iterator.

When iterating, we simply update the iterator's opaque_ field to point to the next lh_entry structure in the linked list. opaque_ will become NULL once we iterate past the last pair in the list, which makes the iterator equivalent to the "end" iterator.Our current representation of the "end" iterator;

Note
May not always be NULL

Definition at line 61 of file json_object_iterator.c.