Merge branch '1.2'
[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 "jansson.h"
12 #include "hashtable.h"
13
14 #define container_of(ptr_, type_, member_)  \
15     ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_))
16
17 typedef struct {
18     json_t json;
19     hashtable_t hashtable;
20     int visited;
21 } json_object_t;
22
23 typedef struct {
24     json_t json;
25     unsigned int size;
26     unsigned int entries;
27     json_t **table;
28     int visited;
29 } json_array_t;
30
31 typedef struct {
32     json_t json;
33     char *value;
34 } json_string_t;
35
36 typedef struct {
37     json_t json;
38     double value;
39 } json_real_t;
40
41 typedef struct {
42     json_t json;
43     int value;
44 } json_integer_t;
45
46 #define json_to_object(json_)  container_of(json_, json_object_t, json)
47 #define json_to_array(json_)   container_of(json_, json_array_t, json)
48 #define json_to_string(json_)  container_of(json_, json_string_t, json)
49 #define json_to_real(json_)   container_of(json_, json_real_t, json)
50 #define json_to_integer(json_) container_of(json_, json_integer_t, json)
51
52 #endif