Line data Source code
1 : /* File: json_element_writer.inl; Copyright and License: see below */
2 :
3 : #include <json/json_element_writer.h>
4 : #include "json/json_constants.h"
5 : #include "meta/meta_info.h"
6 : #include "meta/meta_version.h"
7 : #include "u8/u8_trace.h"
8 : #include "u8/u8_log.h"
9 : #include <assert.h>
10 :
11 : #define io_element_writer_impl_t json_element_writer_t
12 : /*!
13 : * \brief A struct of function pointers which is the interface of an io_element_writer
14 : *
15 : * To avoid typecasts, this struct provides function pointers with the exact right signatures
16 : * provided via io_element_writer_impl_t
17 : */
18 : struct json_element_writer_io_element_writer_if_struct {
19 : #include "io_element_writer_if.inl"
20 : };
21 : #undef io_element_writer_impl_t
22 :
23 : /* the vmt implementing the interface */
24 : static const struct json_element_writer_io_element_writer_if_struct json_element_writer_private_io_element_writer_if
25 : = {
26 : .write_header = &json_element_writer_write_header,
27 : .start_main = &json_element_writer_start_main,
28 : .can_classifier_nest_classifier = &json_element_writer_can_classifier_nest_classifier,
29 : .can_classifier_nest_relationship = &json_element_writer_can_classifier_nest_relationship,
30 : .start_classifier = &json_element_writer_start_classifier,
31 : .assemble_classifier = &json_element_writer_assemble_classifier,
32 : .end_classifier = &json_element_writer_end_classifier,
33 : .start_feature = &json_element_writer_start_feature,
34 : .assemble_feature = &json_element_writer_assemble_feature,
35 : .end_feature = &json_element_writer_end_feature,
36 : .start_relationship = &json_element_writer_start_relationship,
37 : .assemble_relationship = &json_element_writer_assemble_relationship,
38 : .end_relationship = &json_element_writer_end_relationship,
39 : .start_diagram = &json_element_writer_start_diagram,
40 : .assemble_diagram = &json_element_writer_assemble_diagram,
41 : .descend_diagram = &json_element_writer_descend_diagram,
42 : .end_diagram = &json_element_writer_end_diagram_fake,
43 : .start_diagramelement = &json_element_writer_start_diagramelement,
44 : .assemble_diagramelement = &json_element_writer_assemble_diagramelement,
45 : .end_diagramelement = &json_element_writer_end_diagramelement,
46 : .end_main = &json_element_writer_end_main,
47 : .write_footer = &json_element_writer_write_footer
48 : };
49 :
50 2 : void json_element_writer_init( json_element_writer_t *this_,
51 : data_stat_t *io_export_stat,
52 : universal_output_stream_t *output)
53 : {
54 2 : U8_TRACE_BEGIN();
55 2 : assert( io_export_stat != NULL );
56 2 : assert( output != NULL );
57 :
58 2 : io_element_writer_private_init( &((*this_).element_writer),
59 : (io_element_writer_if_t*) &json_element_writer_private_io_element_writer_if,
60 : this_
61 : );
62 :
63 2 : json_writer_init( &((*this_).json_writer), output );
64 :
65 2 : json_type_name_map_init( &((*this_).type_map) );
66 :
67 2 : (*this_).in_outer_array = false;
68 2 : (*this_).is_outer_first = false;
69 2 : (*this_).in_inner_array = false;
70 2 : (*this_).is_inner_first = false;
71 :
72 2 : (*this_).mode = JSON_WRITER_PASS_NODES;
73 2 : (*this_).export_stat = io_export_stat;
74 :
75 2 : U8_TRACE_END();
76 2 : }
77 :
78 2 : void json_element_writer_destroy( json_element_writer_t *this_ )
79 : {
80 2 : U8_TRACE_BEGIN();
81 :
82 2 : json_type_name_map_destroy( &((*this_).type_map) );
83 :
84 2 : json_writer_destroy( &((*this_).json_writer) );
85 :
86 2 : io_element_writer_private_destroy( &((*this_).element_writer) );
87 2 : (*this_).export_stat = NULL;
88 :
89 2 : U8_TRACE_END();
90 2 : }
91 :
92 4 : io_element_writer_t * json_element_writer_get_element_writer( json_element_writer_t *this_ )
93 : {
94 4 : U8_TRACE_BEGIN();
95 :
96 4 : io_element_writer_t * base = &((*this_).element_writer);
97 :
98 4 : U8_TRACE_END();
99 4 : return base;
100 : }
101 :
102 6 : void json_element_writer_set_mode( json_element_writer_t *this_, json_writer_pass_t mode )
103 : {
104 6 : U8_TRACE_BEGIN();
105 :
106 6 : (*this_).mode = mode;
107 :
108 6 : U8_TRACE_END();
109 6 : }
110 :
111 2 : u8_error_t json_element_writer_write_header( json_element_writer_t *this_, const char *document_title )
112 : {
113 2 : U8_TRACE_BEGIN();
114 2 : assert( document_title != NULL );
115 2 : assert( (*this_).in_outer_array == false );
116 2 : assert( (*this_).in_inner_array == false );
117 2 : u8_error_t out_err = U8_ERROR_NONE;
118 :
119 2 : out_err |= json_writer_write_plain( &((*this_).json_writer),
120 : JSON_CONSTANTS_BEGIN_OBJECT_NL
121 : JSON_CONSTANTS_TAB
122 : JSON_CONSTANTS_QUOTE
123 : JSON_CONSTANTS_KEY_HEAD
124 : JSON_CONSTANTS_QUOTE
125 : JSON_CONSTANTS_DEF
126 : JSON_CONSTANTS_BEGIN_OBJECT_NL
127 : );
128 :
129 2 : out_err |= json_writer_write_member_string( &((*this_).json_writer), 2, "encoding", "utf-8", true );
130 : /* hexadecimal escapes are complex: */
131 : /* a single 6-byte sequence can only encode a codepoint of the the basic multilingual plane, */
132 : /* two of these 6-byte sequences may form a surrogate pair */
133 2 : out_err |= json_writer_write_member_string( &((*this_).json_writer), 2, "structure_format", "rfc-8259 w/o hexadecimal escapes", true );
134 2 : out_err |= json_writer_write_member_string( &((*this_).json_writer), 2, "format", "cfu-json", true );
135 : /* version 1.1 stores stereotypes for diagrams and relationships */
136 2 : out_err |= json_writer_write_member_int( &((*this_).json_writer), 2, "major_version", 1, true );
137 2 : out_err |= json_writer_write_member_int( &((*this_).json_writer), 2, "minor_version", 2, true );
138 2 : out_err |= json_writer_write_member_string( &((*this_).json_writer), 2, "generator_name", META_INFO_PROGRAM_ID_STR, true );
139 2 : out_err |= json_writer_write_member_string( &((*this_).json_writer), 2, "generator_version", META_VERSION_STR, false );
140 :
141 2 : out_err |= json_writer_write_plain( &((*this_).json_writer),
142 : JSON_CONSTANTS_TAB
143 : JSON_CONSTANTS_END_OBJECT
144 : JSON_CONSTANTS_NL
145 : );
146 :
147 :
148 2 : if ( out_err != 0 )
149 : {
150 0 : U8_LOG_ERROR( "output buffer exceeded." );
151 : }
152 :
153 2 : U8_TRACE_END_ERR(out_err);
154 2 : return out_err;
155 : }
156 :
157 6 : u8_error_t json_element_writer_start_main( json_element_writer_t *this_, const char *document_title )
158 : {
159 6 : U8_TRACE_BEGIN();
160 6 : assert( document_title != NULL );
161 6 : assert( (*this_).in_outer_array == false );
162 6 : assert( (*this_).in_inner_array == false );
163 6 : u8_error_t out_err = U8_ERROR_NONE;
164 :
165 6 : out_err |= json_writer_write_plain( &((*this_).json_writer),
166 : JSON_CONSTANTS_TAB
167 : JSON_CONSTANTS_NEXT_NL
168 : JSON_CONSTANTS_TAB
169 : JSON_CONSTANTS_QUOTE
170 : );
171 :
172 :
173 6 : switch( (*this_).mode )
174 : {
175 2 : case JSON_WRITER_PASS_VIEWS:
176 : {
177 2 : out_err |= json_writer_write_plain( &((*this_).json_writer), JSON_CONSTANTS_KEY_VIEWS );
178 : }
179 2 : break;
180 :
181 2 : case JSON_WRITER_PASS_NODES:
182 : {
183 2 : out_err |= json_writer_write_plain( &((*this_).json_writer), JSON_CONSTANTS_KEY_NODES );
184 : }
185 2 : break;
186 :
187 2 : case JSON_WRITER_PASS_EDGES:
188 : {
189 2 : out_err |= json_writer_write_plain( &((*this_).json_writer), JSON_CONSTANTS_KEY_EDGES );
190 : }
191 2 : break;
192 :
193 0 : default:
194 : {
195 0 : assert( false );
196 : }
197 : break;
198 : }
199 :
200 6 : out_err |= json_writer_write_plain( &((*this_).json_writer),
201 : JSON_CONSTANTS_QUOTE
202 : JSON_CONSTANTS_DEF_NL
203 : JSON_CONSTANTS_TAB
204 : JSON_CONSTANTS_BEGIN_ARRAY
205 : );
206 :
207 6 : if ( out_err != 0 )
208 : {
209 0 : U8_LOG_ERROR( "output buffer exceeded." );
210 : }
211 :
212 6 : (*this_).in_outer_array = true;
213 6 : (*this_).is_outer_first = true;
214 :
215 6 : U8_TRACE_END_ERR(out_err);
216 6 : return out_err;
217 : }
218 :
219 0 : bool json_element_writer_can_classifier_nest_classifier( json_element_writer_t *this_,
220 : data_classifier_type_t host_type,
221 : data_classifier_type_t child_type )
222 : {
223 0 : U8_TRACE_BEGIN();
224 0 : const bool can_nest = false;
225 0 : U8_TRACE_END();
226 0 : return can_nest;
227 : }
228 :
229 0 : bool json_element_writer_can_classifier_nest_relationship( json_element_writer_t *this_,
230 : data_classifier_type_t host_type,
231 : data_relationship_type_t child_type )
232 : {
233 0 : U8_TRACE_BEGIN();
234 0 : const bool can_nest = true;
235 0 : U8_TRACE_END();
236 0 : return can_nest;
237 : }
238 :
239 0 : u8_error_t json_element_writer_start_classifier( json_element_writer_t *this_,
240 : data_classifier_type_t host_type,
241 : const data_classifier_t *classifier_ptr )
242 : {
243 0 : U8_TRACE_BEGIN();
244 0 : assert( classifier_ptr != NULL );
245 0 : u8_error_t out_err = U8_ERROR_NONE;
246 :
247 0 : if ( (*this_).mode == JSON_WRITER_PASS_NODES )
248 : {
249 : /* separate objects in array if not first */
250 0 : if ( (*this_).is_outer_first )
251 : {
252 0 : (*this_).is_outer_first = false;
253 0 : out_err |= json_writer_write_plain( &((*this_).json_writer), JSON_CONSTANTS_NL );
254 : }
255 : else
256 : {
257 0 : out_err |= json_writer_write_plain( &((*this_).json_writer), JSON_CONSTANTS_NEXT_NL );
258 : }
259 :
260 : /* begin classifier */
261 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
262 : JSON_CONSTANTS_TAB
263 : JSON_CONSTANTS_TAB
264 : JSON_CONSTANTS_BEGIN_OBJECT
265 : JSON_CONSTANTS_NL
266 : JSON_CONSTANTS_TAB
267 : JSON_CONSTANTS_TAB
268 : JSON_CONSTANTS_TAB
269 : JSON_CONSTANTS_QUOTE
270 : JSON_CONSTANTS_KEY_CLASSIFIER
271 : JSON_CONSTANTS_QUOTE
272 : JSON_CONSTANTS_DEF
273 : JSON_CONSTANTS_BEGIN_OBJECT_NL );
274 : }
275 :
276 0 : U8_TRACE_END_ERR(out_err);
277 0 : return out_err;
278 : }
279 :
280 0 : u8_error_t json_element_writer_assemble_classifier( json_element_writer_t *this_,
281 : data_classifier_type_t host_type,
282 : const data_classifier_t *classifier_ptr )
283 : {
284 0 : U8_TRACE_BEGIN();
285 0 : assert( classifier_ptr != NULL );
286 0 : u8_error_t out_err = U8_ERROR_NONE;
287 :
288 0 : if ( (*this_).mode == JSON_WRITER_PASS_NODES )
289 : {
290 0 : assert( (*this_).in_outer_array == true );
291 0 : assert( (*this_).in_inner_array == false );
292 :
293 : /* id */
294 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
295 : 4,
296 : JSON_CONSTANTS_KEY_CLASSIFIER_ID,
297 0 : data_classifier_get_row_id( classifier_ptr ),
298 : true
299 : );
300 :
301 : /* type */
302 : const char *const type_name
303 0 : = json_type_name_map_get_classifier_type( &((*this_).type_map),
304 : data_classifier_get_main_type( classifier_ptr )
305 : );
306 0 : out_err |= json_writer_write_member_enum( &((*this_).json_writer),
307 : 4,
308 : JSON_CONSTANTS_KEY_CLASSIFIER_MAIN_TYPE_NAME,
309 : type_name,
310 : JSON_CONSTANTS_KEY_CLASSIFIER_MAIN_TYPE,
311 0 : data_classifier_get_main_type( classifier_ptr ),
312 : true
313 : );
314 :
315 : /* stereotype */
316 0 : if ( data_classifier_has_stereotype( classifier_ptr ) )
317 : {
318 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
319 : 4,
320 : JSON_CONSTANTS_KEY_CLASSIFIER_STEREOTYPE,
321 0 : data_classifier_get_stereotype_const( classifier_ptr ),
322 : true
323 : );
324 : }
325 :
326 : /* name */
327 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
328 : 4,
329 : JSON_CONSTANTS_KEY_CLASSIFIER_NAME,
330 0 : data_classifier_get_name_const( classifier_ptr ),
331 : true
332 : );
333 :
334 : /* description */
335 0 : out_err |= json_writer_write_member_string_array( &((*this_).json_writer) ,
336 : 4,
337 : JSON_CONSTANTS_KEY_CLASSIFIER_DESCRIPTION,
338 0 : data_classifier_get_description_const( classifier_ptr ),
339 : true
340 : );
341 :
342 : /* x_order */
343 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
344 : 4,
345 : JSON_CONSTANTS_KEY_CLASSIFIER_X_ORDER,
346 0 : data_classifier_get_x_order( classifier_ptr ),
347 : true
348 : );
349 :
350 : /* y_order */
351 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
352 : 4,
353 : JSON_CONSTANTS_KEY_CLASSIFIER_Y_ORDER,
354 0 : data_classifier_get_y_order( classifier_ptr ),
355 : true
356 : );
357 :
358 : /* list_order */
359 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
360 : 4,
361 : JSON_CONSTANTS_KEY_CLASSIFIER_LIST_ORDER,
362 0 : data_classifier_get_list_order( classifier_ptr ),
363 : true
364 : );
365 :
366 : /* uuid */
367 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
368 : 4,
369 : JSON_CONSTANTS_KEY_UUID,
370 0 : data_classifier_get_uuid_const( classifier_ptr ),
371 : true
372 : );
373 :
374 : /* array of features */
375 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
376 : JSON_CONSTANTS_TAB
377 : JSON_CONSTANTS_TAB
378 : JSON_CONSTANTS_TAB
379 : JSON_CONSTANTS_TAB
380 : JSON_CONSTANTS_QUOTE
381 : JSON_CONSTANTS_KEY_CLASSIFIER_FEATURES
382 : JSON_CONSTANTS_QUOTE
383 : JSON_CONSTANTS_DEF_NL
384 : JSON_CONSTANTS_TAB
385 : JSON_CONSTANTS_TAB
386 : JSON_CONSTANTS_TAB
387 : JSON_CONSTANTS_TAB
388 : JSON_CONSTANTS_BEGIN_ARRAY
389 : );
390 :
391 0 : (*this_).in_inner_array = true;
392 0 : (*this_).is_inner_first = true;
393 :
394 : /* update export statistics */
395 0 : data_stat_inc_count ( (*this_).export_stat, DATA_STAT_TABLE_CLASSIFIER, DATA_STAT_SERIES_EXPORTED );
396 : }
397 :
398 0 : U8_TRACE_END_ERR(out_err);
399 0 : return out_err;
400 : }
401 :
402 0 : u8_error_t json_element_writer_end_classifier( json_element_writer_t *this_,
403 : data_classifier_type_t host_type,
404 : const data_classifier_t *classifier_ptr )
405 : {
406 0 : U8_TRACE_BEGIN();
407 0 : assert( classifier_ptr != NULL );
408 0 : u8_error_t out_err = U8_ERROR_NONE;
409 :
410 0 : if ( (*this_).mode == JSON_WRITER_PASS_NODES )
411 : {
412 0 : assert( (*this_).in_outer_array == true );
413 0 : assert( (*this_).in_inner_array == true );
414 0 : (*this_).in_inner_array = false;
415 0 : (*this_).is_inner_first = false;
416 :
417 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
418 : JSON_CONSTANTS_NL
419 : );
420 :
421 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
422 : JSON_CONSTANTS_TAB
423 : JSON_CONSTANTS_TAB
424 : JSON_CONSTANTS_TAB
425 : JSON_CONSTANTS_TAB
426 : JSON_CONSTANTS_END_ARRAY
427 : JSON_CONSTANTS_NL
428 : );
429 :
430 : /* end classifier */
431 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
432 : JSON_CONSTANTS_TAB
433 : JSON_CONSTANTS_TAB
434 : JSON_CONSTANTS_TAB
435 : JSON_CONSTANTS_END_OBJECT_NL
436 : JSON_CONSTANTS_TAB
437 : JSON_CONSTANTS_TAB
438 : JSON_CONSTANTS_END_OBJECT
439 : );
440 :
441 0 : if ( out_err != 0 )
442 : {
443 0 : U8_LOG_ERROR( "output buffer exceeded." );
444 : }
445 : }
446 :
447 0 : U8_TRACE_END_ERR(out_err);
448 0 : return out_err;
449 : }
450 :
451 0 : u8_error_t json_element_writer_start_feature( json_element_writer_t *this_,
452 : data_classifier_type_t parent_type,
453 : const data_feature_t *feature_ptr )
454 : {
455 0 : U8_TRACE_BEGIN();
456 0 : assert( feature_ptr != NULL );
457 0 : u8_error_t out_err = U8_ERROR_NONE;
458 :
459 0 : if ( (*this_).mode == JSON_WRITER_PASS_NODES )
460 : {
461 : /* separate objects in array if not first */
462 0 : if ( (*this_).is_inner_first )
463 : {
464 0 : (*this_).is_inner_first = false;
465 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
466 : JSON_CONSTANTS_NL
467 : );
468 : }
469 : else
470 : {
471 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
472 : JSON_CONSTANTS_NEXT_NL
473 : );
474 : }
475 :
476 : /* begin feature */
477 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
478 : JSON_CONSTANTS_TAB
479 : JSON_CONSTANTS_TAB
480 : JSON_CONSTANTS_TAB
481 : JSON_CONSTANTS_TAB
482 : JSON_CONSTANTS_TAB
483 : JSON_CONSTANTS_BEGIN_OBJECT_NL
484 : );
485 : }
486 :
487 0 : U8_TRACE_END_ERR(out_err);
488 0 : return out_err;
489 : }
490 :
491 0 : u8_error_t json_element_writer_assemble_feature( json_element_writer_t *this_,
492 : const data_classifier_t *parent,
493 : const data_feature_t *feature_ptr )
494 : {
495 0 : U8_TRACE_BEGIN();
496 0 : assert( feature_ptr != NULL );
497 0 : assert( parent != NULL );
498 0 : u8_error_t out_err = U8_ERROR_NONE;
499 :
500 0 : if ( (*this_).mode == JSON_WRITER_PASS_NODES )
501 : {
502 0 : assert( (*this_).in_outer_array == true );
503 0 : assert( (*this_).in_inner_array == true );
504 :
505 : /* id */
506 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
507 : 6,
508 : JSON_CONSTANTS_KEY_FEATURE_ID,
509 0 : data_feature_get_row_id( feature_ptr ),
510 : true
511 : );
512 :
513 : /* type */
514 : const char *const type_name
515 0 : = json_type_name_map_get_feature_type( &((*this_).type_map),
516 : data_feature_get_main_type( feature_ptr )
517 : );
518 0 : out_err |= json_writer_write_member_enum( &((*this_).json_writer),
519 : 6,
520 : JSON_CONSTANTS_KEY_FEATURE_MAIN_TYPE_NAME,
521 : type_name,
522 : JSON_CONSTANTS_KEY_FEATURE_MAIN_TYPE,
523 0 : data_feature_get_main_type( feature_ptr ),
524 : true
525 : );
526 :
527 : /* key */
528 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
529 : 6,
530 : JSON_CONSTANTS_KEY_FEATURE_KEY,
531 0 : data_feature_get_key_const( feature_ptr ),
532 : true
533 : );
534 :
535 : /* value */
536 0 : if ( data_feature_has_value( feature_ptr ) )
537 : {
538 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
539 : 6,
540 : JSON_CONSTANTS_KEY_FEATURE_VALUE,
541 0 : data_feature_get_value_const( feature_ptr ),
542 : true
543 : );
544 : }
545 :
546 : /* description */
547 0 : out_err |= json_writer_write_member_string_array( &((*this_).json_writer) ,
548 : 6,
549 : JSON_CONSTANTS_KEY_FEATURE_DESCRIPTION,
550 0 : data_feature_get_description_const( feature_ptr ),
551 : true
552 : );
553 :
554 : /* list_order */
555 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
556 : 6,
557 : JSON_CONSTANTS_KEY_FEATURE_LIST_ORDER,
558 0 : data_feature_get_list_order( feature_ptr ),
559 : true
560 : );
561 :
562 : /* uuid */
563 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
564 : 6,
565 : JSON_CONSTANTS_KEY_UUID,
566 0 : data_feature_get_uuid_const( feature_ptr ),
567 : false /* LAST, no NEXT */
568 : );
569 :
570 : /* update export statistics */
571 0 : const data_feature_type_t feat_type = data_feature_get_main_type( feature_ptr );
572 0 : const data_stat_table_t feat_or_lifeline
573 0 : = ( feat_type == DATA_FEATURE_TYPE_LIFELINE ) ? DATA_STAT_TABLE_LIFELINE : DATA_STAT_TABLE_FEATURE;
574 0 : data_stat_inc_count ( (*this_).export_stat, feat_or_lifeline, DATA_STAT_SERIES_EXPORTED );
575 : }
576 :
577 0 : U8_TRACE_END_ERR(out_err);
578 0 : return out_err;
579 : }
580 :
581 0 : u8_error_t json_element_writer_end_feature( json_element_writer_t *this_,
582 : data_classifier_type_t parent_type,
583 : const data_feature_t *feature_ptr )
584 : {
585 0 : U8_TRACE_BEGIN();
586 0 : assert( feature_ptr != NULL );
587 0 : u8_error_t out_err = U8_ERROR_NONE;
588 :
589 0 : if ( (*this_).mode == JSON_WRITER_PASS_NODES )
590 : {
591 : /* end feature */
592 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
593 : JSON_CONSTANTS_TAB
594 : JSON_CONSTANTS_TAB
595 : JSON_CONSTANTS_TAB
596 : JSON_CONSTANTS_TAB
597 : JSON_CONSTANTS_TAB
598 : JSON_CONSTANTS_END_OBJECT
599 : );
600 :
601 0 : if ( out_err != 0 )
602 : {
603 0 : U8_LOG_ERROR( "output buffer exceeded." );
604 : }
605 : }
606 :
607 0 : U8_TRACE_END_ERR(out_err);
608 0 : return out_err;
609 : }
610 :
611 0 : u8_error_t json_element_writer_start_relationship( json_element_writer_t *this_,
612 : data_classifier_type_t host_type,
613 : const data_relationship_t *relation_ptr )
614 : {
615 0 : U8_TRACE_BEGIN();
616 0 : assert( relation_ptr != NULL );
617 0 : u8_error_t out_err = U8_ERROR_NONE;
618 :
619 0 : if ( (*this_).mode == JSON_WRITER_PASS_EDGES )
620 : {
621 : /* separate objects if not first */
622 0 : if ( (*this_).is_outer_first )
623 : {
624 0 : (*this_).is_outer_first = false;
625 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
626 : JSON_CONSTANTS_NL
627 : );
628 : }
629 : else
630 : {
631 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
632 : JSON_CONSTANTS_NEXT_NL
633 : );
634 : }
635 :
636 : /* begin relationship */
637 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
638 : JSON_CONSTANTS_TAB
639 : JSON_CONSTANTS_TAB
640 : JSON_CONSTANTS_BEGIN_OBJECT
641 : JSON_CONSTANTS_NL
642 : JSON_CONSTANTS_TAB
643 : JSON_CONSTANTS_TAB
644 : JSON_CONSTANTS_TAB
645 : JSON_CONSTANTS_QUOTE
646 : JSON_CONSTANTS_KEY_RELATIONSHIP
647 : JSON_CONSTANTS_QUOTE
648 : JSON_CONSTANTS_DEF
649 : JSON_CONSTANTS_BEGIN_OBJECT_NL
650 : );
651 : }
652 :
653 0 : U8_TRACE_END_ERR(out_err);
654 0 : return out_err;
655 : }
656 :
657 0 : u8_error_t json_element_writer_assemble_relationship( json_element_writer_t *this_,
658 : const data_classifier_t *host,
659 : const data_relationship_t *relation_ptr,
660 : const data_classifier_t *from_c,
661 : const data_feature_t *from_f,
662 : const data_classifier_t *to_c,
663 : const data_feature_t *to_f )
664 : {
665 0 : U8_TRACE_BEGIN();
666 0 : assert( relation_ptr != NULL );
667 0 : u8_error_t out_err = U8_ERROR_NONE;
668 :
669 0 : if ( (*this_).mode == JSON_WRITER_PASS_EDGES )
670 : {
671 0 : assert( from_c != NULL );
672 0 : assert( to_c != NULL );
673 0 : assert( (*this_).in_outer_array == true );
674 0 : assert( (*this_).in_inner_array == false );
675 :
676 0 : const bool from_f_valid = ( from_f == NULL ) ? false : data_feature_is_valid( from_f );
677 0 : const bool from_c_valid = ( from_c == NULL ) ? false : data_classifier_is_valid( from_c );
678 0 : const bool to_f_valid = ( to_f == NULL ) ? false : data_feature_is_valid( to_f );
679 0 : const bool to_c_valid = ( to_c == NULL ) ? false : data_classifier_is_valid( to_c );
680 :
681 : /* id */
682 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
683 : 4,
684 : JSON_CONSTANTS_KEY_RELATIONSHIP_ID,
685 0 : data_relationship_get_row_id( relation_ptr ),
686 : true
687 : );
688 :
689 : /* type */
690 : const char *const type_name
691 0 : = json_type_name_map_get_relationship_type( &((*this_).type_map),
692 : data_relationship_get_main_type( relation_ptr )
693 : );
694 0 : out_err |= json_writer_write_member_enum( &((*this_).json_writer),
695 : 4,
696 : JSON_CONSTANTS_KEY_RELATIONSHIP_MAIN_TYPE_NAME,
697 : type_name,
698 : JSON_CONSTANTS_KEY_RELATIONSHIP_MAIN_TYPE,
699 0 : data_relationship_get_main_type( relation_ptr ),
700 : true
701 : );
702 :
703 : /* stereotype */
704 0 : if ( data_relationship_has_stereotype( relation_ptr ) )
705 : {
706 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
707 : 4,
708 : JSON_CONSTANTS_KEY_RELATIONSHIP_STEREOTYPE,
709 0 : data_relationship_get_stereotype_const( relation_ptr ),
710 : true
711 : );
712 : }
713 :
714 : /* name */
715 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
716 : 4,
717 : JSON_CONSTANTS_KEY_RELATIONSHIP_NAME,
718 0 : data_relationship_get_name_const( relation_ptr ),
719 : true
720 : );
721 :
722 : /* description */
723 0 : out_err |= json_writer_write_member_string_array( &((*this_).json_writer) ,
724 : 4,
725 : JSON_CONSTANTS_KEY_RELATIONSHIP_DESCRIPTION,
726 0 : data_relationship_get_description_const( relation_ptr ),
727 : true
728 : );
729 :
730 : /* list_order */
731 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
732 : 4,
733 : JSON_CONSTANTS_KEY_RELATIONSHIP_LIST_ORDER,
734 0 : data_relationship_get_list_order( relation_ptr ),
735 : true
736 : );
737 :
738 : /* from_classifier_name */
739 0 : const char *const from_c_name = from_c_valid ? data_classifier_get_name_const( from_c ) : "";
740 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
741 : JSON_CONSTANTS_TAB
742 : JSON_CONSTANTS_TAB
743 : JSON_CONSTANTS_TAB
744 : JSON_CONSTANTS_TAB
745 : JSON_CONSTANTS_QUOTE
746 : JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_CLASSIFIER_NAME
747 : JSON_CONSTANTS_QUOTE
748 : JSON_CONSTANTS_DEF
749 : JSON_CONSTANTS_QUOTE
750 : );
751 0 : out_err |= json_writer_write_string_enc( &((*this_).json_writer), from_c_name );
752 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
753 : JSON_CONSTANTS_QUOTE
754 : JSON_CONSTANTS_NEXT_NL
755 : );
756 :
757 : /* from_feature_key */
758 0 : if ( from_f_valid )
759 : {
760 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
761 : JSON_CONSTANTS_TAB
762 : JSON_CONSTANTS_TAB
763 : JSON_CONSTANTS_TAB
764 : JSON_CONSTANTS_TAB
765 : JSON_CONSTANTS_QUOTE
766 : JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_FEATURE_KEY
767 : JSON_CONSTANTS_QUOTE
768 : JSON_CONSTANTS_DEF
769 : JSON_CONSTANTS_QUOTE
770 : );
771 0 : out_err |= json_writer_write_string_enc( &((*this_).json_writer),
772 0 : data_feature_get_key_const( from_f )
773 : );
774 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
775 : JSON_CONSTANTS_QUOTE
776 : JSON_CONSTANTS_NEXT_NL
777 : );
778 : }
779 :
780 : /* to_classifier_name */
781 0 : const char *const to_c_name = to_c_valid ? data_classifier_get_name_const( to_c ) : "";
782 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
783 : JSON_CONSTANTS_TAB
784 : JSON_CONSTANTS_TAB
785 : JSON_CONSTANTS_TAB
786 : JSON_CONSTANTS_TAB
787 : JSON_CONSTANTS_QUOTE
788 : JSON_CONSTANTS_KEY_RELATIONSHIP_TO_CLASSIFIER_NAME
789 : JSON_CONSTANTS_QUOTE
790 : JSON_CONSTANTS_DEF
791 : JSON_CONSTANTS_QUOTE
792 : );
793 0 : out_err |= json_writer_write_string_enc( &((*this_).json_writer), to_c_name );
794 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
795 : JSON_CONSTANTS_QUOTE
796 : JSON_CONSTANTS_NEXT_NL
797 : );
798 :
799 : /* to_feature_key */
800 0 : if ( to_f_valid )
801 : {
802 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
803 : JSON_CONSTANTS_TAB
804 : JSON_CONSTANTS_TAB
805 : JSON_CONSTANTS_TAB
806 : JSON_CONSTANTS_TAB
807 : JSON_CONSTANTS_QUOTE
808 : JSON_CONSTANTS_KEY_RELATIONSHIP_TO_FEATURE_KEY
809 : JSON_CONSTANTS_QUOTE
810 : JSON_CONSTANTS_DEF
811 : JSON_CONSTANTS_QUOTE
812 : );
813 0 : out_err |= json_writer_write_string_enc( &((*this_).json_writer),
814 0 : data_feature_get_key_const( to_f )
815 : );
816 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
817 : JSON_CONSTANTS_QUOTE
818 : JSON_CONSTANTS_NEXT_NL
819 : );
820 : }
821 :
822 : /* from node ref_uuid */
823 0 : const char *const from_node_ref
824 : = ( from_f_valid )
825 0 : ? data_feature_get_uuid_const( from_f )
826 0 : : ( from_c_valid )
827 0 : ? data_classifier_get_uuid_const( from_c )
828 : : "";
829 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
830 : 4,
831 : JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE,
832 : from_node_ref,
833 : true
834 : );
835 :
836 : /* to node ref_uuid */
837 0 : const char *const to_node_ref
838 : = ( to_f_valid )
839 0 : ? data_feature_get_uuid_const( to_f )
840 0 : : ( to_c_valid )
841 0 : ? data_classifier_get_uuid_const( to_c )
842 : : "";
843 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
844 : 4,
845 : JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE,
846 : to_node_ref,
847 : true
848 : );
849 :
850 : /* uuid */
851 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
852 : 4,
853 : JSON_CONSTANTS_KEY_UUID,
854 0 : data_relationship_get_uuid_const( relation_ptr ),
855 : false /* LAST, no NEXT */
856 : );
857 :
858 : /* update export statistics */
859 0 : data_stat_inc_count ( (*this_).export_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_EXPORTED );
860 : }
861 :
862 0 : U8_TRACE_END_ERR(out_err);
863 0 : return out_err;
864 : }
865 :
866 0 : u8_error_t json_element_writer_end_relationship( json_element_writer_t *this_,
867 : data_classifier_type_t host_type,
868 : const data_relationship_t *relation_ptr )
869 : {
870 0 : U8_TRACE_BEGIN();
871 0 : assert( relation_ptr != NULL );
872 0 : u8_error_t out_err = U8_ERROR_NONE;
873 :
874 0 : if ( (*this_).mode == JSON_WRITER_PASS_EDGES )
875 : {
876 : /* end relationship */
877 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
878 : JSON_CONSTANTS_TAB
879 : JSON_CONSTANTS_TAB
880 : JSON_CONSTANTS_TAB
881 : JSON_CONSTANTS_END_OBJECT_NL
882 : JSON_CONSTANTS_TAB
883 : JSON_CONSTANTS_TAB
884 : JSON_CONSTANTS_END_OBJECT
885 : );
886 :
887 0 : if ( out_err != 0 )
888 : {
889 0 : U8_LOG_ERROR( "output buffer exceeded." );
890 : }
891 : }
892 :
893 0 : U8_TRACE_END_ERR(out_err);
894 0 : return out_err;
895 : }
896 :
897 0 : u8_error_t json_element_writer_start_diagram( json_element_writer_t *this_, const data_diagram_t *diag_ptr )
898 : {
899 0 : U8_TRACE_BEGIN();
900 0 : assert( diag_ptr != NULL );
901 0 : u8_error_t out_err = U8_ERROR_NONE;
902 :
903 0 : if ( (*this_).mode == JSON_WRITER_PASS_VIEWS )
904 : {
905 : /* separate objects if not first */
906 0 : if ( (*this_).is_outer_first )
907 : {
908 0 : (*this_).is_outer_first = false;
909 0 : out_err |= json_writer_write_plain( &((*this_).json_writer), JSON_CONSTANTS_NL );
910 : }
911 : else
912 : {
913 : /* print diagram end here because the official end requires hierarcical diagram containments */
914 0 : out_err |= json_element_writer_private_end_diagram( this_ );
915 :
916 0 : out_err |= json_writer_write_plain( &((*this_).json_writer), JSON_CONSTANTS_NEXT_NL );
917 : }
918 :
919 0 : assert( (*this_).in_outer_array == true );
920 0 : assert( (*this_).in_inner_array == false );
921 :
922 : /* begin diagram */
923 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
924 : JSON_CONSTANTS_TAB
925 : JSON_CONSTANTS_TAB
926 : JSON_CONSTANTS_BEGIN_OBJECT
927 : JSON_CONSTANTS_NL
928 : JSON_CONSTANTS_TAB
929 : JSON_CONSTANTS_TAB
930 : JSON_CONSTANTS_TAB
931 : JSON_CONSTANTS_QUOTE
932 : JSON_CONSTANTS_KEY_DIAGRAM
933 : JSON_CONSTANTS_QUOTE
934 : JSON_CONSTANTS_DEF
935 : JSON_CONSTANTS_BEGIN_OBJECT_NL
936 : );
937 : }
938 :
939 0 : U8_TRACE_END_ERR(out_err);
940 0 : return out_err;
941 : }
942 :
943 0 : u8_error_t json_element_writer_assemble_diagram( json_element_writer_t *this_,
944 : const data_diagram_t *parent,
945 : const data_diagram_t *diag_ptr,
946 : const char *diagram_file_base_name )
947 : {
948 0 : U8_TRACE_BEGIN();
949 0 : assert( diag_ptr != NULL );
950 0 : assert( diagram_file_base_name != NULL );
951 0 : u8_error_t out_err = U8_ERROR_NONE;
952 :
953 0 : if ( (*this_).mode == JSON_WRITER_PASS_VIEWS )
954 : {
955 : /* id */
956 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
957 : 4,
958 : JSON_CONSTANTS_KEY_DIAGRAM_ID,
959 0 : data_diagram_get_row_id( diag_ptr ),
960 : true
961 : );
962 :
963 : /* diagram type */
964 : const char *const type_name
965 0 : = json_type_name_map_get_diagram_type( &((*this_).type_map),
966 : data_diagram_get_diagram_type( diag_ptr )
967 : );
968 0 : out_err |= json_writer_write_member_enum( &((*this_).json_writer),
969 : 4,
970 : JSON_CONSTANTS_KEY_DIAGRAM_DIAGRAM_TYPE_NAME,
971 : type_name,
972 : JSON_CONSTANTS_KEY_DIAGRAM_DIAGRAM_TYPE,
973 0 : data_diagram_get_diagram_type( diag_ptr ),
974 : true
975 : );
976 :
977 : /* stereotype */
978 0 : if ( data_diagram_has_stereotype( diag_ptr ) )
979 : {
980 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
981 : 4,
982 : JSON_CONSTANTS_KEY_DIAGRAM_STEREOTYPE,
983 0 : data_diagram_get_stereotype_const( diag_ptr ),
984 : true
985 : );
986 : }
987 :
988 : /* name */
989 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
990 : 4,
991 : JSON_CONSTANTS_KEY_DIAGRAM_NAME,
992 0 : data_diagram_get_name_const( diag_ptr ),
993 : true
994 : );
995 :
996 : /* description */
997 0 : out_err |= json_writer_write_member_string_array( &((*this_).json_writer) ,
998 : 4,
999 : JSON_CONSTANTS_KEY_DIAGRAM_DESCRIPTION,
1000 0 : data_diagram_get_description_const( diag_ptr ),
1001 : true
1002 : );
1003 :
1004 : /* list_order */
1005 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
1006 : 4,
1007 : JSON_CONSTANTS_KEY_DIAGRAM_LIST_ORDER,
1008 0 : data_diagram_get_list_order( diag_ptr ),
1009 : true
1010 : );
1011 :
1012 : /* display_tags (flag names) + display_flags */
1013 0 : if ( data_diagram_get_display_flags( diag_ptr ) != DATA_DIAGRAM_FLAG_NONE )
1014 : {
1015 : const char *const tag_names
1016 0 : = json_type_name_map_get_diagram_tags( &((*this_).type_map),
1017 : data_diagram_get_display_flags( diag_ptr )
1018 : );
1019 :
1020 0 : out_err |= json_writer_write_member_enum( &((*this_).json_writer),
1021 : 4,
1022 : JSON_CONSTANTS_KEY_DIAGRAM_DISPLAY_FLAG_NAMES,
1023 : tag_names,
1024 : JSON_CONSTANTS_KEY_DIAGRAM_DISPLAY_FLAGS,
1025 0 : data_diagram_get_display_flags( diag_ptr ),
1026 : true
1027 : );
1028 : }
1029 :
1030 0 : const bool parent_valid = ( parent == NULL ) ? false : data_diagram_is_valid( parent );
1031 :
1032 : /* parent_name */
1033 0 : if( parent_valid )
1034 : {
1035 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
1036 : 4,
1037 : JSON_CONSTANTS_KEY_DIAGRAM_PARENT_NAME,
1038 0 : data_diagram_get_name_const( parent ),
1039 : true
1040 : );
1041 : }
1042 :
1043 : /* parent uuid */
1044 0 : if ( parent_valid )
1045 : {
1046 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
1047 : 4,
1048 : JSON_CONSTANTS_KEY_DIAGRAM_PARENT,
1049 0 : data_diagram_get_uuid_const( parent ),
1050 : true
1051 : );
1052 : }
1053 :
1054 : /* uuid */
1055 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
1056 : 4,
1057 : JSON_CONSTANTS_KEY_UUID,
1058 0 : data_diagram_get_uuid_const( diag_ptr ),
1059 : true /* NEXT, not LAST */
1060 : );
1061 :
1062 : /* array of features */
1063 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1064 : JSON_CONSTANTS_TAB
1065 : JSON_CONSTANTS_TAB
1066 : JSON_CONSTANTS_TAB
1067 : JSON_CONSTANTS_TAB
1068 : JSON_CONSTANTS_QUOTE
1069 : JSON_CONSTANTS_KEY_DIAGRAM_ELEMENTS
1070 : JSON_CONSTANTS_QUOTE
1071 : JSON_CONSTANTS_DEF_NL
1072 : JSON_CONSTANTS_TAB
1073 : JSON_CONSTANTS_TAB
1074 : JSON_CONSTANTS_TAB
1075 : JSON_CONSTANTS_TAB
1076 : JSON_CONSTANTS_BEGIN_ARRAY
1077 : );
1078 :
1079 0 : (*this_).in_inner_array = true;
1080 0 : (*this_).is_inner_first = true;
1081 :
1082 : /* update export statistics */
1083 0 : data_stat_inc_count ( (*this_).export_stat, DATA_STAT_TABLE_DIAGRAM, DATA_STAT_SERIES_EXPORTED );
1084 : }
1085 :
1086 0 : U8_TRACE_END_ERR(out_err);
1087 0 : return out_err;
1088 : }
1089 :
1090 0 : u8_error_t json_element_writer_descend_diagram( json_element_writer_t *this_, const data_diagram_t *diag_ptr )
1091 : {
1092 0 : U8_TRACE_BEGIN();
1093 0 : assert( diag_ptr != NULL );
1094 0 : u8_error_t out_err = U8_ERROR_NONE;
1095 :
1096 0 : U8_TRACE_END_ERR(out_err);
1097 0 : return out_err;
1098 : }
1099 :
1100 0 : u8_error_t json_element_writer_end_diagram_fake( json_element_writer_t *this_, const data_diagram_t *diag_ptr )
1101 : {
1102 0 : U8_TRACE_BEGIN();
1103 0 : assert( diag_ptr != NULL );
1104 0 : u8_error_t out_err = U8_ERROR_NONE;
1105 :
1106 : /* The JSON export does not encapsulate one diagram into another. */
1107 : /* Therefore, diagrams are ended already when the next starts. */
1108 :
1109 0 : U8_TRACE_END_ERR(out_err);
1110 0 : return out_err;
1111 : }
1112 :
1113 0 : u8_error_t json_element_writer_private_end_diagram( json_element_writer_t *this_ )
1114 : {
1115 0 : U8_TRACE_BEGIN();
1116 0 : u8_error_t out_err = U8_ERROR_NONE;
1117 :
1118 0 : if ( (*this_).mode == JSON_WRITER_PASS_VIEWS )
1119 : {
1120 0 : (*this_).in_inner_array = false;
1121 0 : (*this_).is_inner_first = false;
1122 :
1123 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1124 : JSON_CONSTANTS_NL
1125 : );
1126 :
1127 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1128 : JSON_CONSTANTS_TAB
1129 : JSON_CONSTANTS_TAB
1130 : JSON_CONSTANTS_TAB
1131 : JSON_CONSTANTS_TAB
1132 : JSON_CONSTANTS_END_ARRAY
1133 : JSON_CONSTANTS_NL
1134 : );
1135 :
1136 : /* end diagram */
1137 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1138 : JSON_CONSTANTS_TAB
1139 : JSON_CONSTANTS_TAB
1140 : JSON_CONSTANTS_TAB
1141 : JSON_CONSTANTS_END_OBJECT_NL
1142 : JSON_CONSTANTS_TAB
1143 : JSON_CONSTANTS_TAB
1144 : JSON_CONSTANTS_END_OBJECT
1145 : );
1146 : }
1147 :
1148 0 : U8_TRACE_END_ERR(out_err);
1149 0 : return out_err;
1150 : }
1151 :
1152 0 : u8_error_t json_element_writer_start_diagramelement( json_element_writer_t *this_,
1153 : const data_diagram_t *parent,
1154 : const data_diagramelement_t *diagramelement_ptr )
1155 : {
1156 0 : U8_TRACE_BEGIN();
1157 0 : assert( diagramelement_ptr != NULL );
1158 0 : assert( parent != NULL );
1159 0 : u8_error_t out_err = U8_ERROR_NONE;
1160 :
1161 0 : if ( (*this_).mode == JSON_WRITER_PASS_VIEWS )
1162 : {
1163 : /* separate objects in array if not first */
1164 0 : if ( (*this_).is_inner_first )
1165 : {
1166 0 : (*this_).is_inner_first = false;
1167 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1168 : JSON_CONSTANTS_NL
1169 : );
1170 : }
1171 : else
1172 : {
1173 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1174 : JSON_CONSTANTS_NEXT_NL
1175 : );
1176 : }
1177 :
1178 : /* begin diagramelement */
1179 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1180 : JSON_CONSTANTS_TAB
1181 : JSON_CONSTANTS_TAB
1182 : JSON_CONSTANTS_TAB
1183 : JSON_CONSTANTS_TAB
1184 : JSON_CONSTANTS_TAB
1185 : JSON_CONSTANTS_BEGIN_OBJECT_NL
1186 : );
1187 :
1188 0 : if ( out_err != 0 )
1189 : {
1190 0 : U8_LOG_ERROR( "output buffer exceeded." );
1191 : }
1192 : }
1193 :
1194 0 : U8_TRACE_END_ERR(out_err);
1195 0 : return out_err;
1196 : }
1197 :
1198 0 : u8_error_t json_element_writer_assemble_diagramelement( json_element_writer_t *this_,
1199 : const data_diagram_t *parent,
1200 : const data_diagramelement_t *diagramelement_ptr,
1201 : const data_classifier_t *occurrence,
1202 : const data_feature_t *feat_occur )
1203 : {
1204 0 : U8_TRACE_BEGIN();
1205 0 : assert( parent != NULL );
1206 0 : assert( diagramelement_ptr != NULL );
1207 0 : assert( occurrence != NULL );
1208 : /* feat_occur may be NULL */
1209 0 : u8_error_t out_err = U8_ERROR_NONE;
1210 :
1211 0 : if ( (*this_).mode == JSON_WRITER_PASS_VIEWS )
1212 : {
1213 0 : assert( (*this_).in_outer_array == true );
1214 0 : assert( (*this_).in_inner_array == true );
1215 :
1216 : /* id */
1217 0 : out_err |= json_writer_write_member_int( &((*this_).json_writer),
1218 : 6,
1219 : JSON_CONSTANTS_KEY_DIAGRAMELEMENT_ID,
1220 0 : data_diagramelement_get_row_id( diagramelement_ptr ),
1221 : true
1222 : );
1223 :
1224 : /* display_tags (flag names) + display_flags */
1225 0 : if ( data_diagramelement_get_display_flags( diagramelement_ptr ) != DATA_DIAGRAMELEMENT_FLAG_NONE )
1226 : {
1227 : const char *const tag_names
1228 0 : = json_type_name_map_get_diagramelement_tags( &((*this_).type_map),
1229 : data_diagramelement_get_display_flags( diagramelement_ptr )
1230 : );
1231 0 : out_err |= json_writer_write_member_enum( &((*this_).json_writer),
1232 : 6,
1233 : JSON_CONSTANTS_KEY_DIAGRAMELEMENT_DISPLAY_FLAG_NAMES,
1234 : tag_names,
1235 : JSON_CONSTANTS_KEY_DIAGRAMELEMENT_DISPLAY_FLAGS,
1236 0 : data_diagramelement_get_display_flags( diagramelement_ptr ),
1237 : true
1238 : );
1239 : }
1240 :
1241 : /* classifier_name */
1242 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
1243 : 6,
1244 : JSON_CONSTANTS_KEY_DIAGRAMELEMENT_CLASSIFIER_NAME,
1245 0 : data_classifier_get_name_const( occurrence ),
1246 : true
1247 : );
1248 :
1249 : /* focused_feature_name */
1250 : /* note that focused features are always lifelines and these never have names */
1251 :
1252 : /* ref_uuid */
1253 0 : const bool feat_valid = ( feat_occur == NULL ) ? false : data_feature_is_valid( feat_occur );
1254 0 : const bool clas_valid = data_classifier_is_valid( occurrence );
1255 0 : const char *const node_ref
1256 : = ( feat_valid )
1257 0 : ? data_feature_get_uuid_const( feat_occur )
1258 0 : : ( clas_valid )
1259 0 : ? data_classifier_get_uuid_const( occurrence )
1260 : : "";
1261 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
1262 : 6,
1263 : JSON_CONSTANTS_KEY_DIAGRAMELEMENT_NODE,
1264 : node_ref,
1265 : true
1266 : );
1267 :
1268 : /* uuid */
1269 0 : out_err |= json_writer_write_member_string( &((*this_).json_writer),
1270 : 6,
1271 : JSON_CONSTANTS_KEY_UUID,
1272 0 : data_diagramelement_get_uuid_const( diagramelement_ptr ),
1273 : false /* LAST, no NEXT */
1274 : );
1275 :
1276 : /* update export statistics */
1277 0 : data_stat_inc_count ( (*this_).export_stat, DATA_STAT_TABLE_DIAGRAMELEMENT, DATA_STAT_SERIES_EXPORTED );
1278 : }
1279 :
1280 0 : U8_TRACE_END_ERR(out_err);
1281 0 : return out_err;
1282 : }
1283 :
1284 0 : u8_error_t json_element_writer_end_diagramelement( json_element_writer_t *this_,
1285 : const data_diagram_t *parent,
1286 : const data_diagramelement_t *diagramelement_ptr )
1287 : {
1288 0 : U8_TRACE_BEGIN();
1289 0 : assert( diagramelement_ptr != NULL );
1290 0 : assert( parent != NULL );
1291 0 : u8_error_t out_err = U8_ERROR_NONE;
1292 :
1293 0 : if ( (*this_).mode == JSON_WRITER_PASS_VIEWS )
1294 : {
1295 : /* end diagramelement */
1296 0 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1297 : JSON_CONSTANTS_TAB
1298 : JSON_CONSTANTS_TAB
1299 : JSON_CONSTANTS_TAB
1300 : JSON_CONSTANTS_TAB
1301 : JSON_CONSTANTS_TAB
1302 : JSON_CONSTANTS_END_OBJECT
1303 : );
1304 :
1305 0 : if ( out_err != 0 )
1306 : {
1307 0 : U8_LOG_ERROR( "output buffer exceeded." );
1308 : }
1309 : }
1310 :
1311 0 : U8_TRACE_END_ERR(out_err);
1312 0 : return out_err;
1313 : }
1314 :
1315 6 : u8_error_t json_element_writer_end_main( json_element_writer_t *this_ )
1316 : {
1317 6 : U8_TRACE_BEGIN();
1318 6 : u8_error_t out_err = U8_ERROR_NONE;
1319 :
1320 : /* print diagram end here because the official end requires hierarcical diagram containments */
1321 6 : if ( (*this_).mode == JSON_WRITER_PASS_VIEWS )
1322 : {
1323 2 : if ( ! (*this_).is_outer_first )
1324 : {
1325 0 : out_err |= json_element_writer_private_end_diagram( this_ );
1326 : }
1327 : }
1328 :
1329 6 : assert( (*this_).in_outer_array == true );
1330 6 : assert( (*this_).in_inner_array == false );
1331 6 : (*this_).in_outer_array = false;
1332 6 : (*this_).is_outer_first = false;
1333 :
1334 6 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1335 : JSON_CONSTANTS_NL
1336 : JSON_CONSTANTS_TAB
1337 : JSON_CONSTANTS_END_ARRAY
1338 : JSON_CONSTANTS_NL
1339 : );
1340 :
1341 6 : if ( out_err != 0 )
1342 : {
1343 0 : U8_LOG_ERROR( "output buffer exceeded." );
1344 : }
1345 :
1346 6 : U8_TRACE_END_ERR(out_err);
1347 6 : return out_err;
1348 : }
1349 :
1350 2 : u8_error_t json_element_writer_write_footer( json_element_writer_t *this_ )
1351 : {
1352 2 : U8_TRACE_BEGIN();
1353 2 : assert( (*this_).in_outer_array == false );
1354 2 : assert( (*this_).in_inner_array == false );
1355 2 : u8_error_t out_err = U8_ERROR_NONE;
1356 :
1357 2 : out_err |= json_writer_write_plain( &((*this_).json_writer),
1358 : JSON_CONSTANTS_END_OBJECT_NL
1359 : );
1360 :
1361 2 : if ( out_err != 0 )
1362 : {
1363 0 : U8_LOG_ERROR( "output buffer exceeded." );
1364 : }
1365 :
1366 2 : U8_TRACE_END_ERR(out_err);
1367 2 : return out_err;
1368 : }
1369 :
1370 :
1371 : /*
1372 : Copyright 2016-2025 Andreas Warnke
1373 :
1374 : Licensed under the Apache License, Version 2.0 (the "License");
1375 : you may not use this file except in compliance with the License.
1376 : You may obtain a copy of the License at
1377 :
1378 : http://www.apache.org/licenses/LICENSE-2.0
1379 :
1380 : Unless required by applicable law or agreed to in writing, software
1381 : distributed under the License is distributed on an "AS IS" BASIS,
1382 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1383 : See the License for the specific language governing permissions and
1384 : limitations under the License.
1385 : */
|