rjp/include/rjp_internal.h

93 lines
2.5 KiB
C

/**
rjp
Copyright (C) 2018-2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RJP_INTERNAL_H
#define RJP_INTERNAL_H
#include "rjp.h"
#include <stdio.h>
#ifdef __GNUC__
#define MAYBE_UNUSED __attribute__((unused))
#else
#define MAYBE_UNUSED
#endif
#ifdef RJP_DIAGNOSTICS
#define DIAG_PRINT(...) fprintf(__VA_ARGS__)
#else
#define DIAG_PRINT(...) irjp_ignore_unused(__VA_ARGS__)
#endif
#define UNUSED_VARIABLE(thing) (void)(thing)
static inline void irjp_ignore_unused(FILE* fp, ...){
UNUSED_VARIABLE(fp);
}
//
//Represents a json object
typedef struct RJP_object{
struct RJP_tree_node* root;
RJP_index num_members;
}RJP_object;
//Represents a json array
typedef struct RJP_array{
struct RJP_array_element* elements; //linked list of elements
struct RJP_array_element* last; //final member of linked list
RJP_index num_elements;
}RJP_array;
//Represents json data
//hold any json data type
typedef struct RJP_value{
union{
RJP_int integer;
RJP_float dfloat;
RJP_bool boolean;
struct RJP_object object;
struct RJP_string string;
struct RJP_array array;
};
struct RJP_value* parent; //pointer to parent (either an array or object or NULL)
enum RJP_data_type type; //flag to determine active member of union
}RJP_value;
typedef struct RJP_array_element{
struct RJP_value value;
struct RJP_array_element* next;
struct RJP_array_element* prev;
}RJP_array_element;
void irjp_copy_array(RJP_value* dest, const RJP_value* src);
void irjp_add_element(RJP_array* j);
void irjp_delete_value(RJP_value* root);
RJP_value irjp_integer(RJP_int i);
RJP_value irjp_boolean(RJP_bool b);
RJP_value irjp_dfloat(RJP_float d);
RJP_value irjp_string(char* c, RJP_index len);
RJP_value irjp_string_copy(const char* c);
RJP_value irjp_null(void);
RJP_value irjp_object(void);
RJP_value irjp_array(void);
RJP_index rjp_dump_array(const RJP_value* arr, char* dest);
RJP_index rjp_dump_object(const RJP_value* root, char* dest);
#endif