/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include #include "bits/__generics.h" #include "../modules/libcdsb/include/vtype.h" #ifndef LIBCJSONP_JSONP_H #define LIBCJSONP_JSONP_H typedef struct { void* data; vtype type; } json_t; extern void json_free (json_t* x); inline vtype json_type (json_t* x) Always_inline__ Nonnull__(1); inline void* json_value(json_t* x) Always_inline__ Nonnull__(1); extern bool json_load (json_t* x, FILE* s) Nonnull__(1, 2); inline vtype json_type (json_t* x) { return x->type; } inline void* json_value(json_t* x) { return x->data; } /*#####################################################################################################################*/ #define json_parse(x, src) libcjsonp_json_parse (x, _LIBCDSB_to_cstring(src), 0) #define json_init(x, value) libcjsonp_json_init (x, _LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 0) #define json_stringify(value) libcjsonp_json_stringify (_LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 0, 0) #define json_stringify_pretty(value) libcjsonp_json_stringify (_LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 4, 0) #define json_dump(dest, value) libcjsonp_json_dump(dest, _LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 0, 0) #define json_dump_pretty(dest, value) libcjsonp_json_dump(dest, _LIBCJSONP_value_pointer(value), _LIBCJSONP_vtypeof(value), 4, 0) /*#####################################################################################################################*/ extern void libcjsonp_json_init (json_t* x, void* value, vtype type, bool attach) Nonnull__(1); extern bool libcjsonp_json_parse(json_t* x, const char* value, size_t nmemb) Nonnull__(1); extern vtype_string libcjsonp_json_stringify (const void* value, vtype type, size_t padsize, int padchr) Pure__; extern bool libcjsonp_json_dump(FILE* dest, const void* value, vtype type, size_t padsize, int padchr) Nonnull__(1); #endif /* LIBCJSONP_JSONP_H */