/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. #ifndef JANSSON_PRIVATE_H
  8. #define JANSSON_PRIVATE_H
  9. #include <stddef.h>
  10. #include "jansson.h"
  11. #include "hashtable.h"
  12. #define container_of(ptr_, type_, member_) \
  13. ((type_ *)((char *)ptr_ - offsetof(type_, member_)))
  14. /* On some platforms, max() may already be defined */
  15. #ifndef max
  16. #define max(a, b) ((a) > (b) ? (a) : (b))
  17. #endif
  18. typedef struct {
  19. json_t json;
  20. hashtable_t hashtable;
  21. size_t serial;
  22. int visited;
  23. } json_object_t;
  24. typedef struct {
  25. json_t json;
  26. size_t size;
  27. size_t entries;
  28. json_t **table;
  29. int visited;
  30. } json_array_t;
  31. typedef struct {
  32. json_t json;
  33. char *value;
  34. } json_string_t;
  35. typedef struct {
  36. json_t json;
  37. double value;
  38. } json_real_t;
  39. typedef struct {
  40. json_t json;
  41. json_int_t value;
  42. } json_integer_t;
  43. #define json_to_object(json_) container_of(json_, json_object_t, json)
  44. #define json_to_array(json_) container_of(json_, json_array_t, json)
  45. #define json_to_string(json_) container_of(json_, json_string_t, json)
  46. #define json_to_real(json_) container_of(json_, json_real_t, json)
  47. #define json_to_integer(json_) container_of(json_, json_integer_t, json)
  48. typedef struct {
  49. size_t serial;
  50. char key[1];
  51. } object_key_t;
  52. const object_key_t *jsonp_object_iter_fullkey(void *iter);
  53. void jsonp_error_init(json_error_t *error, const char *source);
  54. void jsonp_error_set(json_error_t *error, int line, int column,
  55. const char *msg, ...);
  56. #endif