json_journal.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include "json_journal.h"
3 
4 
5 #define MAX_STACK 1000
6 
8 static int jj_stack_index = -1;
9 static FILE * jj_file = 0;
10 
11 
12 int jj_enabled() {
13  return jj_file != 0;
14 }
15 
17  assert(jj_stack_index>=0);
18  return jj_stack[jj_stack_index];
19 }
20 
21 void jj_stack_push(JO jo) {
22  assert(jj_stack_index<MAX_STACK);
23  jj_stack[++jj_stack_index] = jo;
24 }
25 
26 void jj_stack_pop() {
27 /* fprintf(stderr, "jj_stack_pop %d\n", jj_stack_index); */
28  assert(jj_stack_index>=0);
29  if(jj_stack_index == 0 && jj_file) {
30  fprintf(jj_file, "%s\n", json_object_to_json_string(jj_stack_top()));
32  }
34 }
35 
36 void jj_context_enter(const char*context_name) {
37 /* fprintf(stderr, "jj_context_enter('%s') %d\n", context_name, jj_stack_index); */
38 
40  if(jj_stack_index>=0)
41  jo_add(jj_stack_top(), context_name, jo);
42 
43  jj_stack_push(jo);
44 }
45 
46 
47 
50 }
51 
54 }
55 
58  jj_stack_pop();
59 }
60 
61 void jj_loop_enter(const char*loop_name) {
64  jo_add(jj_stack_top(), loop_name, jo);
65  jj_stack_push(jo);
66 }
67 
69  JO this_iteration = json_object_new_object();
71  jj_stack_pop();
73  }
74  json_object_array_add(jj_stack_top(), this_iteration);
75  jj_stack_push(this_iteration);
76 }
77 
78 void jj_loop_exit() {
80  jj_stack_pop();
81 
83  jj_stack_pop();
84 }
85 
86 void jj_add_int(const char*name, int v) {
88  jo_add(jj_stack_top(), name, jo_new_int(v));
89 }
90 
91 void jj_add_double(const char*name, double v) {
94 }
95 
96 void jj_add_double_array(const char *name, double *v, int n) {
97  jj_add(name, jo_new_double_array(v, n));
98 }
99 
100 void jj_add_int_array(const char*name, int* v, int n) {
101  jj_add(name, jo_new_int_array(v, n));
102 }
103 
104 void jj_add(const char*name, JO jo) {
105  jj_must_be_hash();
106  jo_add(jj_stack_top(), name, jo);
107 }
108 
109 void jj_set_stream(FILE* f) {
110  jj_file = f;
111 }
112 
113 FILE * jj_get_stream() {
114  return jj_file;
115 }
static int jj_stack_index
Definition: json_journal.c:8
void jj_add_int(const char *name, int v)
Definition: json_journal.c:86
int json_object_is_type(struct json_object *this, int type)
Definition: json_object.c:184
void jj_loop_enter(const char *loop_name)
Definition: json_journal.c:61
#define jo_new_int
void jj_must_be_hash()
Definition: json_journal.c:48
#define jo_add
int json_object_array_add(struct json_object *this, struct json_object *val)
Definition: json_object.c:522
#define MAX_STACK
Definition: json_journal.c:5
JO jo_new_double_array(const double *v, int n)
static JO jj_stack[MAX_STACK]
Definition: json_journal.c:7
const char * json_object_to_json_string(struct json_object *this)
Definition: json_object.c:199
const char * name
Definition: options.h:51
struct json_object * json_object_new_array()
Definition: json_object.c:495
void jj_context_exit()
Definition: json_journal.c:56
static FILE * jj_file
Definition: json_journal.c:9
struct json_object * json_object_new_object()
Definition: json_object.c:248
json_type
Definition: json_object.h:37
void jj_add(const char *name, JO jo)
Definition: json_journal.c:104
void jj_add_double(const char *name, double v)
Definition: json_journal.c:91
void jj_add_int_array(const char *name, int *v, int n)
Definition: json_journal.c:100
void jj_must_be_array()
Definition: json_journal.c:52
void jj_loop_exit()
Definition: json_journal.c:78
void jj_loop_iteration()
Definition: json_journal.c:68
void jj_stack_push(JO jo)
Definition: json_journal.c:21
void jj_add_double_array(const char *name, double *v, int n)
Definition: json_journal.c:96
int jj_enabled()
Definition: json_journal.c:12
JO jj_stack_top()
Definition: json_journal.c:16
void jj_stack_pop()
Definition: json_journal.c:26
FILE * jj_get_stream()
Definition: json_journal.c:113
void jj_set_stream(FILE *f)
Definition: json_journal.c:109
JO jo_double_or_null(double v)
JO jo_new_int_array(const int *v, int n)
void jj_context_enter(const char *context_name)
Definition: json_journal.c:36
#define jo_free


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23