Fix r3 json writer
This commit is contained in:
parent
c3ef959539
commit
03031e02aa
5 changed files with 13 additions and 17 deletions
|
@ -1,8 +1,5 @@
|
||||||
language: c
|
language: c
|
||||||
|
|
||||||
compiler:
|
|
||||||
- gcc
|
|
||||||
|
|
||||||
git:
|
git:
|
||||||
depth: 1
|
depth: 1
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
#include "r3.h"
|
#include "r3.h"
|
||||||
|
|
||||||
json_object * r3_edge_to_json_object(const edge * e);
|
json_object * r3_edge_to_json_object(const R3Edge * e);
|
||||||
json_object * r3_node_to_json_object(const node * n);
|
json_object * r3_node_to_json_object(const R3Node * n);
|
||||||
json_object * r3_route_to_json_object(const R3Route * r);
|
json_object * r3_route_to_json_object(const R3Route * r);
|
||||||
|
|
||||||
const char * r3_node_to_json_string_ext(const node * n, int options);
|
const char * r3_node_to_json_string_ext(const R3Node * n, int options);
|
||||||
const char * r3_node_to_json_pretty_string(const node * n);
|
const char * r3_node_to_json_pretty_string(const R3Node * n);
|
||||||
const char * r3_node_to_json_string(const node * n);
|
const char * r3_node_to_json_string(const R3Node * n);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
12
src/json.c
12
src/json.c
|
@ -27,7 +27,7 @@ json_object * r3_route_to_json_object(const R3Route * r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
json_object * r3_edge_to_json_object(const edge * e) {
|
json_object * r3_edge_to_json_object(const R3Edge * e) {
|
||||||
json_object *obj;
|
json_object *obj;
|
||||||
|
|
||||||
obj = json_object_new_object();
|
obj = json_object_new_object();
|
||||||
|
@ -42,7 +42,7 @@ json_object * r3_edge_to_json_object(const edge * e) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object * r3_node_to_json_object(const node * n) {
|
json_object * r3_node_to_json_object(const R3Node * n) {
|
||||||
json_object *obj;
|
json_object *obj;
|
||||||
|
|
||||||
obj = json_object_new_object();
|
obj = json_object_new_object();
|
||||||
|
@ -60,7 +60,7 @@ json_object * r3_node_to_json_object(const node * n) {
|
||||||
json_object *edges_array = json_object_new_array();
|
json_object *edges_array = json_object_new_array();
|
||||||
json_object_object_add(obj, "edges", edges_array);
|
json_object_object_add(obj, "edges", edges_array);
|
||||||
for (i = 0 ; i < n->edge_len ; i++ ) {
|
for (i = 0 ; i < n->edge_len ; i++ ) {
|
||||||
json_object *edge_json_obj = r3_edge_to_json_object(n->edges[i]);
|
json_object *edge_json_obj = r3_edge_to_json_object(&n->edges[i]);
|
||||||
json_object_array_add(edges_array, edge_json_obj);
|
json_object_array_add(edges_array, edge_json_obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,17 +79,17 @@ json_object * r3_node_to_json_object(const node * n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * r3_node_to_json_string_ext(const node * n, int options) {
|
const char * r3_node_to_json_string_ext(const R3Node * n, int options) {
|
||||||
json_object *obj = r3_node_to_json_object(n);
|
json_object *obj = r3_node_to_json_object(n);
|
||||||
return json_object_to_json_string_ext(obj, options);
|
return json_object_to_json_string_ext(obj, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * r3_node_to_json_pretty_string(const node * n) {
|
const char * r3_node_to_json_pretty_string(const R3Node * n) {
|
||||||
json_object *obj = r3_node_to_json_object(n);
|
json_object *obj = r3_node_to_json_object(n);
|
||||||
return json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
|
return json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * r3_node_to_json_string(const node * n) {
|
const char * r3_node_to_json_string(const R3Node * n) {
|
||||||
json_object *obj = r3_node_to_json_object(n);
|
json_object *obj = r3_node_to_json_object(n);
|
||||||
return json_object_to_json_string(obj);
|
return json_object_to_json_string(obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
TESTS =
|
TESTS =
|
||||||
|
|
||||||
AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) $(JSONC_CFLAGS) @CHECK_CFLAGS@ -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/src -I$(top_builddir)/3rdparty -Wall -std=c99 -ggdb -Wall
|
AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) $(JSONC_CFLAGS) @CHECK_CFLAGS@ -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/src -I$(top_builddir)/3rdparty -Wall -std=c99 -ggdb
|
||||||
AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) $(JSONC_LIBS) @CHECK_LIBS@ $(top_builddir)/libr3.la
|
AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) $(JSONC_LIBS) @CHECK_LIBS@ $(top_builddir)/libr3.la
|
||||||
|
|
||||||
if USE_JEMALLOC
|
if USE_JEMALLOC
|
||||||
|
@ -49,4 +49,3 @@ bench_SOURCES = bench.c
|
||||||
# AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir)/include
|
# AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir)/include
|
||||||
# AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include
|
# AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include
|
||||||
CLEANFILES = check_tree.log
|
CLEANFILES = check_tree.log
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
START_TEST (test_json_encode)
|
START_TEST (test_json_encode)
|
||||||
{
|
{
|
||||||
node * n;
|
R3Node * n;
|
||||||
n = r3_tree_create(10);
|
n = r3_tree_create(10);
|
||||||
|
|
||||||
ck_assert(n);
|
ck_assert(n);
|
||||||
|
|
Loading…
Reference in a new issue