jansson_private.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #ifndef JANSSON_PRIVATE_H
  8. #define JANSSON_PRIVATE_H
  9. #include "jansson.h"
  10. #include "hashtable.h"
  11. #define container_of(ptr_, type_, member_) \
  12. ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_))
  13. typedef struct {
  14. json_t json;
  15. hashtable_t hashtable;
  16. unsigned long serial;
  17. int visited;
  18. } json_object_t;
  19. typedef struct {
  20. json_t json;
  21. unsigned int size;
  22. unsigned int entries;
  23. json_t **table;
  24. int visited;
  25. } json_array_t;
  26. typedef struct {
  27. json_t json;
  28. char *value;
  29. } json_string_t;
  30. typedef struct {
  31. json_t json;
  32. double value;
  33. } json_real_t;
  34. typedef struct {
  35. json_t json;
  36. int value;
  37. } json_integer_t;
  38. #define json_to_object(json_) container_of(json_, json_object_t, json)
  39. #define json_to_array(json_) container_of(json_, json_array_t, json)
  40. #define json_to_string(json_) container_of(json_, json_string_t, json)
  41. #define json_to_real(json_) container_of(json_, json_real_t, json)
  42. #define json_to_integer(json_) container_of(json_, json_integer_t, json)
  43. typedef struct {
  44. unsigned long serial;
  45. char key[];
  46. } object_key_t;
  47. const object_key_t *jsonp_object_iter_fullkey(void *iter);
  48. #endif