s2j.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * This file is part of the struct2json Library.
  3. *
  4. * Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * 'Software'), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Function: It is an head file for this library. You can see all be called functions.
  26. * Created on: 2015-10-14
  27. */
  28. #ifndef __S2J_H__
  29. #define __S2J_H__
  30. #include <cJSON.h>
  31. #include <string.h>
  32. #include "s2jdef.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* struct2json software version number */
  37. #define S2J_SW_VERSION "1.0.2"
  38. /* Create JSON object */
  39. #define s2j_create_json_obj(json_obj) \
  40. S2J_CREATE_JSON_OBJECT(json_obj)
  41. /* Delete JSON object */
  42. #define s2j_delete_json_obj(json_obj) \
  43. S2J_DELETE_JSON_OBJECT(json_obj)
  44. /* Set basic type element for JSON object */
  45. #define s2j_json_set_basic_element(to_json, from_struct, type, element) \
  46. S2J_JSON_SET_BASIC_ELEMENT(to_json, from_struct, type, element)
  47. /* Set array type element for JSON object */
  48. #define s2j_json_set_array_element(to_json, from_struct, type, element, size) \
  49. S2J_JSON_SET_ARRAY_ELEMENT(to_json, from_struct, type, element, size)
  50. /* Set child structure type element for JSON object */
  51. #define s2j_json_set_struct_element(child_json, to_json, child_struct, from_struct, type, element) \
  52. S2J_JSON_SET_STRUCT_ELEMENT(child_json, to_json, child_struct, from_struct, type, element)
  53. /* Create structure object */
  54. #define s2j_create_struct_obj(struct_obj, type) \
  55. S2J_CREATE_STRUCT_OBJECT(struct_obj, type)
  56. /* Delete structure object */
  57. #define s2j_delete_struct_obj(struct_obj) \
  58. S2J_DELETE_STRUCT_OBJECT(struct_obj)
  59. /* Get basic type element for structure object */
  60. #define s2j_struct_get_basic_element(to_struct, from_json, type, element) \
  61. S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, element)
  62. /* Get array type element for structure object */
  63. #define s2j_struct_get_array_element(to_struct, from_json, type, element) \
  64. S2J_STRUCT_GET_ARRAY_ELEMENT(to_struct, from_json, type, element)
  65. /* Get child structure type element for structure object */
  66. #define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \
  67. S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element)
  68. /* s2j.c */
  69. extern S2jHook s2jHook;
  70. void s2j_init(S2jHook *hook);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* __S2J_H__ */