Merge branch '1.3'
[jansson.git] / src / jansson_private.h
1 /*
2  * Copyright (c) 2009, 2010 Petri Lehtinen <petri@digip.org>
3  *
4  * Jansson is free software; you can redistribute it and/or modify
5  * it under the terms of the MIT license. See LICENSE for details.
6  */
7
8 #ifndef JANSSON_PRIVATE_H
9 #define JANSSON_PRIVATE_H
10
11 #include <stddef.h>
12 #include "jansson.h"
13 #include "hashtable.h"
14
15 #define container_of(ptr_, type_, member_)  \
16     ((type_ *)((char *)ptr_ - offsetof(type_, member_)))
17
18 typedef struct {
19     json_t json;
20     hashtable_t hashtable;
21     size_t serial;
22     int visited;
23 } json_object_t;
24
25 typedef struct {
26     json_t json;
27     size_t size;
28     size_t entries;
29     json_t **table;
30     int visited;
31 } json_array_t;
32
33 typedef struct {
34     json_t json;
35     char *value;
36 } json_string_t;
37
38 typedef struct {
39     json_t json;
40     double value;
41 } json_real_t;
42
43 typedef struct {
44     json_t json;
45     json_int_t value;
46 } json_integer_t;
47
48 #define json_to_object(json_)  container_of(json_, json_object_t, json)
49 #define json_to_array(json_)   container_of(json_, json_array_t, json)
50 #define json_to_string(json_)  container_of(json_, json_string_t, json)
51 #define json_to_real(json_)   container_of(json_, json_real_t, json)
52 #define json_to_integer(json_) container_of(json_, json_integer_t, json)
53
54 typedef struct {
55     size_t serial;
56     char key[1];
57 } object_key_t;
58
59 const object_key_t *jsonp_object_iter_fullkey(void *iter);
60
61 #endif