LCOV - code coverage report
Current view: top level - io/source/document - document_link_provider.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.65.6_covts Lines: 0 55 0.0 %
Date: 2025-09-25 21:07:53 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* File: document_link_provider.c; Copyright and License: see below */
       2             : 
       3             : #include "document/document_link_provider.h"
       4             : #include "utf8stringbuf/utf8stringview.h"
       5             : #include "u8/u8_trace.h"
       6             : #include "u8/u8_log.h"
       7             : #include <stdio.h>
       8             : #include <stdbool.h>
       9             : #include <assert.h>
      10             : 
      11           0 : void document_link_provider_init( document_link_provider_t *this_,
      12             :                                   data_database_reader_t *db_reader,
      13             :                                   const char * tag_xref_separator,
      14             :                                   const char * tag_xref_start,
      15             :                                   const char * tag_xref_middle,
      16             :                                   const char * tag_xref_end,
      17             :                                   io_xml_writer_t *xml_writer )
      18             : {
      19           0 :     U8_TRACE_BEGIN();
      20           0 :     assert( NULL != db_reader );
      21           0 :     assert( NULL != tag_xref_separator );
      22           0 :     assert( NULL != tag_xref_start );
      23           0 :     assert( NULL != tag_xref_middle );
      24           0 :     assert( NULL != tag_xref_end );
      25           0 :     assert( NULL != xml_writer );
      26             : 
      27           0 :     (*this_).db_reader = db_reader;
      28           0 :     (*this_).tag_xref_separator = tag_xref_separator;
      29           0 :     (*this_).tag_xref_start = tag_xref_start;
      30           0 :     (*this_).tag_xref_middle = tag_xref_middle;
      31           0 :     (*this_).tag_xref_end = tag_xref_end;
      32           0 :     (*this_).xml_writer = xml_writer;
      33             : 
      34           0 :     (*this_).current_diagram = DATA_ID_VOID;
      35             : 
      36           0 :     U8_TRACE_END();
      37           0 : }
      38             : 
      39           0 : void document_link_provider_destroy( document_link_provider_t *this_ )
      40             : {
      41           0 :     U8_TRACE_BEGIN();
      42             : 
      43           0 :     (*this_).current_diagram = DATA_ID_VOID;
      44             : 
      45           0 :     (*this_).db_reader = NULL;
      46           0 :     (*this_).xml_writer = NULL;
      47             : 
      48           0 :     U8_TRACE_END();
      49           0 : }
      50             : 
      51           0 : u8_error_t document_link_provider_write_occurrences( document_link_provider_t *this_,
      52             :                                                      data_id_t classifier_id )
      53             : {
      54           0 :     U8_TRACE_BEGIN();
      55           0 :     assert ( NULL != (*this_).db_reader );
      56           0 :     assert ( DATA_TABLE_CLASSIFIER == data_id_get_table( &classifier_id ) );
      57           0 :     u8_error_t db_err = U8_ERROR_NONE;
      58           0 :     u8_error_t export_err = U8_ERROR_NONE;
      59             : 
      60             :     /* read from database */
      61             :     data_diagram_iterator_t diagram_iterator;
      62           0 :     db_err |= data_diagram_iterator_init_empty( &diagram_iterator );
      63           0 :     db_err |= data_database_reader_get_diagrams_by_classifier_id( (*this_).db_reader,
      64             :                                                                   data_id_get_row_id( &classifier_id ),
      65             :                                                                   &diagram_iterator
      66             :                                                                 );
      67           0 :     bool is_first = true;
      68           0 :     while( data_diagram_iterator_has_next( &diagram_iterator ) )
      69             :     {
      70           0 :         db_err |= data_diagram_iterator_next( &diagram_iterator, &((*this_).temp_diagram) );
      71             : 
      72             :         /* write to sink */
      73           0 :         if ( is_first )
      74             :         {
      75           0 :             is_first = false;
      76             :         }
      77             :         else
      78             :         {
      79           0 :             export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_separator );
      80             :         }
      81           0 :         const data_id_t diag_ref_id = data_diagram_get_data_id( &((*this_).temp_diagram) );
      82           0 :         const char *const diag_ref_name = data_diagram_get_name_const( &((*this_).temp_diagram) );
      83           0 :         if ( data_id_equals( &diag_ref_id, &((*this_).current_diagram) ) )
      84             :         {
      85           0 :             export_err |= io_xml_writer_write_xml_enc( (*this_).xml_writer, diag_ref_name );
      86             :         }
      87             :         else
      88             :         {
      89           0 :             export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_start );
      90           0 :             export_err |= io_xml_writer_write_plain_id( (*this_).xml_writer, diag_ref_id );
      91           0 :             export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_middle );
      92           0 :             export_err |= io_xml_writer_write_xml_enc( (*this_).xml_writer, diag_ref_name );
      93           0 :             export_err |= io_xml_writer_write_plain ( (*this_).xml_writer, (*this_).tag_xref_end );
      94             :         }
      95             :     }
      96           0 :     db_err |= data_diagram_iterator_destroy( &diagram_iterator );
      97             : 
      98           0 :     U8_TRACE_END_ERR( db_err || export_err );
      99           0 :     return ( db_err || export_err );
     100             : }
     101             : 
     102           0 : void document_link_provider_set_current_diagram( document_link_provider_t *this_, const data_id_t *current_diagram )
     103             : {
     104           0 :     U8_TRACE_BEGIN();
     105             : 
     106           0 :     (*this_).current_diagram = *current_diagram;
     107             : 
     108           0 :     U8_TRACE_END();
     109           0 : }
     110             : 
     111             : 
     112             : /*
     113             : Copyright 2023-2025 Andreas Warnke
     114             : 
     115             : Licensed under the Apache License, Version 2.0 (the "License");
     116             : you may not use this file except in compliance with the License.
     117             : You may obtain a copy of the License at
     118             : 
     119             :     http://www.apache.org/licenses/LICENSE-2.0
     120             : 
     121             : Unless required by applicable law or agreed to in writing, software
     122             : distributed under the License is distributed on an "AS IS" BASIS,
     123             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     124             : See the License for the specific language governing permissions and
     125             : limitations under the License.
     126             : */

Generated by: LCOV version 1.16