LCOV - code coverage report
Current view: top level - ctrl/source/consistency - consistency_feature.c (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.70.2_covts Lines: 100.0 % 65 65
Test Date: 2026-05-03 11:56:31 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /* File: consistency_feature.c; Copyright and License: see below */
       2              : 
       3              : #include "consistency/consistency_feature.h"
       4              : #include "ctrl_classifier_controller.h"
       5              : #include "ctrl_diagram_controller.h"
       6              : #include "u8/u8_trace.h"
       7              : #include "u8/u8_log.h"
       8              : 
       9           47 : void consistency_feature_init( consistency_feature_t *this_,
      10              :                                data_database_reader_t *db_reader,
      11              :                                struct ctrl_classifier_controller_struct *clfy_ctrl )
      12              : {
      13           47 :     U8_TRACE_BEGIN();
      14           47 :     assert( NULL != db_reader );
      15           47 :     assert( NULL != clfy_ctrl );
      16              : 
      17           47 :     (*this_).db_reader = db_reader;
      18           47 :     (*this_).clfy_ctrl = clfy_ctrl;
      19           47 :     data_rules_init( &((*this_).rules) );
      20              : 
      21           47 :     U8_TRACE_END();
      22           47 : }
      23              : 
      24           47 : void consistency_feature_destroy( consistency_feature_t *this_ )
      25              : {
      26           47 :     U8_TRACE_BEGIN();
      27              : 
      28           47 :     (*this_).db_reader = NULL;
      29           47 :     (*this_).clfy_ctrl = NULL;
      30           47 :     data_rules_destroy( &((*this_).rules) );
      31              : 
      32           47 :     U8_TRACE_END();
      33           47 : }
      34              : 
      35            9 : u8_error_t consistency_feature_delete_invisibles_in_diagram( consistency_feature_t *this_,
      36              :                                                              const data_diagram_t *updated_diagram,
      37              :                                                              consistency_stat_t *io_stat )
      38              : {
      39            9 :     U8_TRACE_BEGIN();
      40            9 :     assert( updated_diagram != NULL );
      41            9 :     assert( io_stat != NULL );
      42            9 :     u8_error_t result = U8_ERROR_NONE;
      43              : 
      44            9 :     const data_diagram_type_t new_diagram_type = data_diagram_get_diagram_type( updated_diagram );
      45            9 :     const bool new_diagram_shows_feature = data_rules_diagram_shows_uncond_features( &((*this_).rules), new_diagram_type );
      46              :     /*
      47              :     const bool new_diagram_is_scenario = data_rules_diagram_is_scenario( &((*this_).rules), new_diagram_type );
      48              :     const bool new_diagram_shows_lifeline = data_rules_diagram_shows_scenario_features( &((*this_).rules), new_diagram_type );
      49              :     assert( new_diagram_is_scenario == new_diagram_shows_lifeline );
      50              :     */
      51              : 
      52            9 :     if ( ! new_diagram_shows_feature )
      53              :     {
      54            6 :         const data_row_t diagram_id = data_diagram_get_row( updated_diagram );
      55              :         data_diagramelement_iterator_t diagramelement_iterator;
      56            6 :         data_diagramelement_iterator_init_empty( &diagramelement_iterator );
      57            6 :         result |= data_database_reader_get_diagramelements_by_diagram_id( (*this_).db_reader,
      58              :                                                                           diagram_id,
      59              :                                                                           &diagramelement_iterator
      60              :                                                                         );
      61            6 :         if ( result == U8_ERROR_NONE )
      62              :         {
      63           15 :             while ( data_diagramelement_iterator_has_next( &diagramelement_iterator ) )
      64              :             {
      65            9 :                 result |= data_diagramelement_iterator_next( &diagramelement_iterator, &((*this_).temp_diagramelement_buf) );
      66            9 :                 const data_row_t classifier_id = data_diagramelement_get_classifier_row( &((*this_).temp_diagramelement_buf) );
      67            9 :                 result |= consistency_feature_delete_invisibles_of_classifier( this_, classifier_id, io_stat );
      68              :             }
      69              :         }
      70            6 :         result |= data_diagramelement_iterator_destroy( &diagramelement_iterator );
      71              :     }
      72              :     else
      73              :     {
      74            3 :         U8_TRACE_INFO("All unconditional features are visible, no need to check for invisibility.");
      75              :     }
      76              : 
      77            9 :     U8_TRACE_END_ERR( result );
      78            9 :     return result;
      79              : }
      80              : 
      81           39 : u8_error_t consistency_feature_delete_invisibles_of_classifier( consistency_feature_t *this_,
      82              :                                                                 data_row_t classifier_id,
      83              :                                                                 consistency_stat_t *io_stat )
      84              : {
      85           39 :     U8_TRACE_BEGIN();
      86           39 :     assert( classifier_id != DATA_ROW_VOID );
      87           39 :     assert( io_stat != NULL );
      88           39 :     u8_error_t result = U8_ERROR_NONE;
      89              : 
      90           39 :     bool a_diagram_shows_uncond_feature = false;  /* tells if a diagram is found where unconditional features of a classifier are visible */
      91              :     {
      92              :         data_diagram_iterator_t diagram_iterator;
      93           39 :         data_diagram_iterator_init_empty( &diagram_iterator );
      94           39 :         result |= data_database_reader_get_diagrams_by_classifier_id( (*this_).db_reader,
      95              :                                                                       classifier_id,
      96              :                                                                       &diagram_iterator
      97              :                                                                     );
      98           39 :         if ( result == U8_ERROR_NONE )
      99              :         {
     100          101 :             while ( data_diagram_iterator_has_next( &diagram_iterator ) )
     101              :             {
     102           62 :                 result |= data_diagram_iterator_next( &diagram_iterator, &((*this_).temp_diagram_buf) );
     103           62 :                 const data_diagram_type_t diagram_type = data_diagram_get_diagram_type( &((*this_).temp_diagram_buf) );
     104           62 :                 a_diagram_shows_uncond_feature |= data_rules_diagram_shows_uncond_features( &((*this_).rules), diagram_type );
     105              :                 /* this function does not care on visibility of scenario based features, this is handled in consistency_lifeline */
     106              :             }
     107              :         }
     108           39 :         result |= data_diagram_iterator_destroy( &diagram_iterator );
     109              :     }
     110              : 
     111           39 :     if ( ! a_diagram_shows_uncond_feature )
     112              :     {
     113              :         data_feature_iterator_t feature_iterator;
     114           10 :         data_feature_iterator_init_empty( &feature_iterator );
     115           10 :         result |= data_database_reader_get_features_by_classifier_id( (*this_).db_reader,
     116              :                                                                       classifier_id,
     117              :                                                                       &feature_iterator
     118              :                                                                     );
     119           10 :         if ( result == U8_ERROR_NONE )
     120              :         {
     121           29 :             while ( data_feature_iterator_has_next( &feature_iterator ) )
     122              :             {
     123            9 :                 result |= data_feature_iterator_next( &feature_iterator, &((*this_).temp_feature_buf) );
     124            9 :                 const data_feature_type_t feature_type = data_feature_get_main_type( &((*this_).temp_feature_buf) );
     125            9 :                 const bool feature_is_scenario = data_rules_feature_is_scenario_cond( &((*this_).rules), feature_type );
     126            9 :                 if ( ! feature_is_scenario )
     127              :                 {
     128            3 :                     const data_row_t feature_id = data_feature_get_row( &((*this_).temp_feature_buf) );
     129            3 :                     result |= ctrl_classifier_controller_delete_feature( (*this_).clfy_ctrl,
     130              :                                                                          feature_id,
     131              :                                                                          CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND,
     132              :                                                                          io_stat
     133              :                                                                        );
     134              :                 }
     135              :             }
     136              :         }
     137           10 :         result |= data_feature_iterator_destroy( &feature_iterator );
     138              :     }
     139              :     else
     140              :     {
     141           29 :         U8_TRACE_INFO("Unconditional features are visible, no deletion of unconditional features.");
     142              :     }
     143              : 
     144           39 :     U8_TRACE_END_ERR( result );
     145           39 :     return result;
     146              : }
     147              : 
     148              : 
     149              : /*
     150              : Copyright 2026-2026 Andreas Warnke
     151              : 
     152              : Licensed under the Apache License, Version 2.0 (the "License");
     153              : you may not use this file except in compliance with the License.
     154              : You may obtain a copy of the License at
     155              : 
     156              :     http://www.apache.org/licenses/LICENSE-2.0
     157              : 
     158              : Unless required by applicable law or agreed to in writing, software
     159              : distributed under the License is distributed on an "AS IS" BASIS,
     160              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     161              : See the License for the specific language governing permissions and
     162              : limitations under the License.
     163              : */
        

Generated by: LCOV version 2.0-1