Successfully hid RJP_value implementation from API
This commit is contained in:
@@ -65,42 +65,27 @@ typedef struct RJP_string{
|
||||
}RJP_string;
|
||||
|
||||
//Forward declarations
|
||||
struct RJP_array_element;
|
||||
typedef struct RJP_tree_node RJP_tree_node;
|
||||
|
||||
struct RJP_object_iterator_impl;
|
||||
typedef struct RJP_object_iterator{
|
||||
struct RJP_object_iterator_impl* it;
|
||||
}RJP_object_iterator;
|
||||
|
||||
//Represents a json object
|
||||
typedef struct RJP_object{
|
||||
struct RJP_tree_node* root;
|
||||
int num_members;
|
||||
}RJP_object;
|
||||
struct RJP_array_iterator_impl;
|
||||
typedef struct RJP_array_iterator{
|
||||
struct RJP_array_iterator_impl* it;
|
||||
}RJP_array_iterator;
|
||||
|
||||
//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;
|
||||
typedef struct RJP_value RJP_value;
|
||||
|
||||
//Represents json data
|
||||
//hold any json data type
|
||||
typedef struct RJP_value{
|
||||
typedef struct RJP_vinit{
|
||||
union{
|
||||
RJP_int integer;
|
||||
RJP_float dfloat;
|
||||
char 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;
|
||||
|
||||
enum RJP_data_type type;
|
||||
}RJP_vinit;
|
||||
|
||||
/*
|
||||
Generic operations
|
||||
@@ -110,24 +95,23 @@ RJP_value* rjp_parse(const char* str);
|
||||
//RJP_value* rjp_parse_chunked(const char* str, RJP_value* prev_chunk);
|
||||
|
||||
//Initialize a root RJP_value to NULL
|
||||
RJP_value* rjp_init_json(void);
|
||||
RJP_value* rjp_new_value(void);
|
||||
//Initialize a root RJP_value to copy of value
|
||||
RJP_value* rjp_init_json_as(RJP_value value);
|
||||
RJP_value* rjp_new_value_as(RJP_vinit* val);
|
||||
//Free an RJP_value and all members/elements
|
||||
void rjp_free_value(RJP_value* root);
|
||||
//Deep copy RJP_value
|
||||
void rjp_copy_value(RJP_value* dest, const RJP_value* src);
|
||||
//set existing value
|
||||
void rjp_set_value(RJP_value* dest, RJP_value value);
|
||||
void rjp_set_value(RJP_value* dest, RJP_vinit* val);
|
||||
//initialize a RJP_value to the requested type and value
|
||||
RJP_value rjp_integer(RJP_int i);
|
||||
RJP_value rjp_boolean(char b);
|
||||
RJP_value rjp_dfloat(RJP_float d);
|
||||
RJP_value rjp_string(char* c, RJP_index len);
|
||||
RJP_value rjp_string_copy(const char* c);
|
||||
RJP_value rjp_null(void);
|
||||
RJP_value rjp_object(void);
|
||||
RJP_value rjp_array(void);
|
||||
RJP_vinit rjp_integer(RJP_int i);
|
||||
RJP_vinit rjp_boolean(char b);
|
||||
RJP_vinit rjp_dfloat(RJP_float d);
|
||||
RJP_vinit rjp_string(char* c, RJP_index len);
|
||||
RJP_vinit rjp_null(void);
|
||||
RJP_vinit rjp_object(void);
|
||||
RJP_vinit rjp_array(void);
|
||||
//Return handle to parent of given value
|
||||
RJP_value* rjp_value_parent(const RJP_value* element);
|
||||
//Return type of value
|
||||
@@ -158,13 +142,16 @@ void rjp_free(void* dest);
|
||||
Object operations
|
||||
*/
|
||||
//add a member to a json object, allocating a copy of the key
|
||||
RJP_value* rjp_add_member(RJP_value* dest, const char* key, RJP_index keylen, RJP_value value);
|
||||
RJP_value* rjp_new_member(RJP_value* dest, const char* key, RJP_index keylen, RJP_vinit* value);
|
||||
RJP_value* rjp_add_member(RJP_value* dest, const char* key, RJP_index keylen, RJP_value* value);
|
||||
//add a member to a json object without allocation. key must be allocated using rjp_alloc/rjp_calloc
|
||||
RJP_value* rjp_add_member_no_alloc(RJP_value* dest, char* key, RJP_index keylen, RJP_value value);
|
||||
RJP_value* rjp_new_member_no_alloc(RJP_value* dest, char* key, RJP_index keylen, RJP_vinit* value);
|
||||
RJP_value* rjp_add_member_no_alloc(RJP_value* dest, char* key, RJP_index keylen, RJP_value* value);
|
||||
RJP_value* rjp_remove_member_by_key(RJP_value* obj, const char* key);
|
||||
RJP_value* rjp_remove_member(RJP_value* obj, RJP_value* member);
|
||||
//add an element to a json array
|
||||
RJP_value* rjp_add_element(RJP_value* dest, RJP_value value);
|
||||
RJP_value* rjp_add_element(RJP_value* dest, RJP_value* value);
|
||||
RJP_value* rjp_new_element(RJP_value* dest, RJP_vinit* value);
|
||||
//set existing object member's key
|
||||
void rjp_set_key(RJP_value* dest, const char* key, RJP_index keylen);
|
||||
//set existing object member's key without allocation. key must be allocated using rjp_alloc/rjp_calloc
|
||||
|
||||
@@ -35,12 +35,50 @@
|
||||
#endif
|
||||
|
||||
//
|
||||
//Represents a json object
|
||||
typedef struct RJP_object{
|
||||
struct RJP_tree_node* root;
|
||||
int 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;
|
||||
char 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;
|
||||
}RJP_array_element;
|
||||
|
||||
void irjp_copy_vinit_to_value(RJP_value* dest, RJP_vinit* src);
|
||||
void irjp_add_element(RJP_array* j);
|
||||
void irjp_add_member_no_alloc(RJP_object* j, char* str, size_t len);
|
||||
void irjp_delete_value(RJP_value* root);
|
||||
|
||||
RJP_value irjp_integer(RJP_int i);
|
||||
RJP_value irjp_boolean(char 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);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user