PageRenderTime 36ms CodeModel.GetById 22ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/jansson/src/jansson_private.h

http://github.com/nicolasff/webdis
C++ Header | 70 lines | 49 code | 14 blank | 7 comment | 0 complexity | c02f0f98bf1933fce8329af6f03c5a15 MD5 | raw file
 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/* On some platforms, max() may already be defined */
19#ifndef max
20#define max(a, b)  ((a) > (b) ? (a) : (b))
21#endif
22
23typedef struct {
24    json_t json;
25    hashtable_t hashtable;
26    size_t serial;
27    int visited;
28} json_object_t;
29
30typedef struct {
31    json_t json;
32    size_t size;
33    size_t entries;
34    json_t **table;
35    int visited;
36} json_array_t;
37
38typedef struct {
39    json_t json;
40    char *value;
41} json_string_t;
42
43typedef struct {
44    json_t json;
45    double value;
46} json_real_t;
47
48typedef struct {
49    json_t json;
50    json_int_t value;
51} json_integer_t;
52
53#define json_to_object(json_)  container_of(json_, json_object_t, json)
54#define json_to_array(json_)   container_of(json_, json_array_t, json)
55#define json_to_string(json_)  container_of(json_, json_string_t, json)
56#define json_to_real(json_)   container_of(json_, json_real_t, json)
57#define json_to_integer(json_) container_of(json_, json_integer_t, json)
58
59typedef struct {
60    size_t serial;
61    char key[1];
62} object_key_t;
63
64const object_key_t *jsonp_object_iter_fullkey(void *iter);
65
66void jsonp_error_init(json_error_t *error, const char *source);
67void jsonp_error_set(json_error_t *error, int line, int column,
68                     const char *msg, ...);
69
70#endif