LCOV - code coverage report
Current view: top level - data/source - data_rules.c (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 100.0 % 88 88
Test Date: 2025-05-01 10:10:14 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /* File: data_rules.c; Copyright and License: see below */
       2              : 
       3              : #include "data_rules.h"
       4              : #include "u8/u8_trace.h"
       5              : #include "u8/u8_log.h"
       6              : 
       7              : /* ================================ VISIBLE_SET ================================ */
       8              : 
       9          317 : bool data_rules_diagram_shows_feature ( const data_rules_t *this_, const data_visible_set_t *diagram_set, data_row_t feature_id )
      10              : {
      11          317 :     U8_TRACE_BEGIN();
      12          317 :     assert( NULL != diagram_set );
      13          317 :     bool result = false;
      14              : 
      15              :     /* search objects */
      16          317 :     const data_diagram_t *diag_ptr = data_visible_set_get_diagram_const( diagram_set );
      17          317 :     assert( diag_ptr != NULL );
      18          317 :     assert( data_diagram_is_valid( diag_ptr ) );
      19          317 :     const data_diagram_type_t diagram_type = data_diagram_get_diagram_type ( diag_ptr );
      20              : 
      21          317 :     const data_feature_t *feat_ptr = data_visible_set_get_feature_by_id_const ( diagram_set, feature_id );  /* SEARCH */
      22          317 :     assert( feat_ptr != NULL );
      23          317 :     assert( data_feature_is_valid( feat_ptr ) );
      24          317 :     const data_row_t classifier_id = data_feature_get_classifier_row_id( feat_ptr );
      25          317 :     const data_feature_type_t feature_type = data_feature_get_main_type ( feat_ptr );
      26              : 
      27          317 :     const data_classifier_t *classifier_ptr = data_visible_set_get_classifier_by_id_const ( diagram_set, classifier_id );  /* SEARCH */
      28          317 :     if ( classifier_ptr != NULL )
      29              :     {
      30          305 :         assert( data_classifier_is_valid( classifier_ptr ) );
      31          305 :         const data_classifier_type_t classifier_type = data_classifier_get_main_type ( classifier_ptr );
      32          305 :         const bool is_feat_scenario = data_rules_feature_is_scenario_cond ( this_, feature_type );
      33              : 
      34          305 :         if ( is_feat_scenario )
      35              :         {
      36              :             /* a scenario-typed feature(=lifeline) that belongs to a different diagram is always filtered */
      37            9 :             bool is_foreign_scenario = true;
      38            9 :             const uint32_t vc_count = data_visible_set_get_visible_classifier_count ( diagram_set );
      39          414 :             for ( uint32_t vc_idx = 0; vc_idx < vc_count; vc_idx ++ )  /* SEARCH */
      40              :             {
      41          411 :                 const data_visible_classifier_t *vc_probe = data_visible_set_get_visible_classifier_const ( diagram_set, vc_idx );
      42          411 :                 assert ( NULL != vc_probe );
      43          411 :                 const data_diagramelement_t *diag_ele = data_visible_classifier_get_diagramelement_const ( vc_probe );
      44          411 :                 assert ( NULL != diag_ele );
      45          411 :                 const data_row_t diag_ele_feat_id = data_diagramelement_get_focused_feature_row_id( diag_ele );
      46          411 :                 if ( feature_id == diag_ele_feat_id )
      47              :                 {
      48            6 :                     is_foreign_scenario = false;
      49            6 :                     break;
      50              :                 }
      51              :             }
      52              : 
      53              :             /* evaluate filter */
      54            9 :             const bool ok_by_diagram = data_rules_diagram_shows_scenario_features ( this_, diagram_type );
      55            9 :             const bool ok_by_scenario = ! is_foreign_scenario;
      56            9 :             result = ok_by_diagram && ok_by_scenario;
      57              :         }
      58              :         else
      59              :         {
      60              :             /* evaluate filter */
      61          296 :             const bool ok_by_classifier = data_rules_classifier_has_uncond_features ( this_, classifier_type );
      62          296 :             const bool ok_by_diagram = data_rules_diagram_shows_uncond_features ( this_, diagram_type );
      63          296 :             result = ok_by_classifier && ok_by_diagram;
      64              :         }
      65              :     }
      66              :     else
      67              :     {
      68              :         /* maybe the data_visible_set_t was full and the classifier could not be stored? */
      69           12 :         U8_LOG_ANOMALY_INT( "data_visible_set_t contains a feature but not the related classifier.", feature_id );
      70              :     }
      71              : 
      72          317 :     U8_TRACE_END();
      73          317 :     return result;
      74              : }
      75              : 
      76          444 : bool data_rules_diagram_shows_relationship ( const data_rules_t *this_, const data_visible_set_t *diagram_set, data_row_t relationship_id )
      77              : {
      78          444 :     U8_TRACE_BEGIN();
      79          444 :     assert( NULL != diagram_set );
      80          444 :     bool result = false;
      81              : 
      82              :     /* search objects */
      83          444 :     const data_diagram_t *diag_ptr = data_visible_set_get_diagram_const( diagram_set );
      84          444 :     assert( diag_ptr != NULL );
      85          444 :     assert( data_diagram_is_valid( diag_ptr ) );
      86          444 :     const data_diagram_type_t diagram_type = data_diagram_get_diagram_type ( diag_ptr );
      87              : 
      88          444 :     const data_relationship_t *relation_ptr = data_visible_set_get_relationship_by_id_const ( diagram_set, relationship_id );  /* SEARCH */
      89          444 :     assert( relation_ptr != NULL );
      90          444 :     assert( data_relationship_is_valid( relation_ptr ) );
      91          444 :     const data_row_t from_classifier_id = data_relationship_get_from_classifier_row_id( relation_ptr );
      92          444 :     const data_row_t from_feat_id = data_relationship_get_from_feature_row_id( relation_ptr );
      93          444 :     const data_row_t to_classifier_id = data_relationship_get_to_classifier_row_id( relation_ptr );
      94          444 :     const data_row_t to_feat_id = data_relationship_get_to_feature_row_id( relation_ptr );
      95              : 
      96          444 :     const data_classifier_t *from_classifier_or_null = data_visible_set_get_classifier_by_id_const( diagram_set, from_classifier_id );  /* SEARCH */
      97          444 :     const data_classifier_t *to_classifier_or_null = data_visible_set_get_classifier_by_id_const( diagram_set, to_classifier_id );  /* SEARCH */
      98          444 :     if (( from_classifier_or_null != NULL )&&( to_classifier_or_null != NULL ))
      99          431 :     {
     100          431 :         const data_feature_t *from_feat_or_null = data_visible_set_get_feature_by_id_const( diagram_set, from_feat_id );  /* SEARCH */
     101          431 :         const data_feature_t *to_feat_or_null = data_visible_set_get_feature_by_id_const( diagram_set, to_feat_id );  /* SEARCH */
     102          431 :         const data_feature_type_t from_feature_type = (NULL==from_feat_or_null)
     103              :                                                       ? DATA_FEATURE_TYPE_VOID
     104          431 :                                                       : data_feature_get_main_type( from_feat_or_null );
     105          431 :         const data_feature_type_t to_feature_type = (NULL==to_feat_or_null)
     106              :                                                     ? DATA_FEATURE_TYPE_VOID
     107          431 :                                                     : data_feature_get_main_type( to_feat_or_null );
     108          431 :         const bool is_rel_scenario = data_rules_relationship_is_scenario_cond( this_, from_feature_type, to_feature_type);
     109              : 
     110          431 :         if ( is_rel_scenario )
     111              :         {
     112              :             /* a scenario-typed feature that belongs to a different diagram is always filtered */
     113           12 :             bool is_from_foreign_scenario = (NULL!=from_feat_or_null);
     114           12 :             bool is_to_foreign_scenario = (NULL!=to_feat_or_null);
     115           12 :             const uint32_t vc_count = data_visible_set_get_visible_classifier_count ( diagram_set );
     116         1548 :             for ( uint32_t vc_idx = 0; vc_idx < vc_count; vc_idx ++ )  /* SEARCH */
     117              :             {
     118         1536 :                 const data_visible_classifier_t *vc_probe = data_visible_set_get_visible_classifier_const ( diagram_set, vc_idx );
     119         1536 :                 assert ( NULL != vc_probe );
     120         1536 :                 const data_diagramelement_t *diag_ele = data_visible_classifier_get_diagramelement_const ( vc_probe );
     121         1536 :                 assert ( NULL != diag_ele );
     122         1536 :                 const data_row_t diag_ele_feat_id = data_diagramelement_get_focused_feature_row_id( diag_ele );
     123         1536 :                 if ( from_feat_id == diag_ele_feat_id )
     124              :                 {
     125          440 :                     is_from_foreign_scenario = false;
     126              :                 }
     127         1536 :                 if ( to_feat_id == diag_ele_feat_id )
     128              :                 {
     129          440 :                     is_to_foreign_scenario = false;
     130              :                 }
     131              :             }
     132              : 
     133              :             /* evaluate filter */
     134           12 :             const bool ok_by_diagram = data_rules_diagram_shows_scenario_relationships ( this_, diagram_type );
     135           12 :             const bool ok_by_scenario = ( ! is_from_foreign_scenario )&&( ! is_to_foreign_scenario );
     136           12 :             result = ok_by_diagram && ok_by_scenario;
     137              :         }
     138              :         else
     139              :         {
     140              :             /* evaluate filter */
     141          419 :             const bool ok_by_diagram = data_rules_diagram_shows_uncond_relationships ( this_, diagram_type );
     142          419 :             result = ok_by_diagram;
     143              :         }
     144              :     }
     145              :     else
     146              :     {
     147           13 :         if (( from_classifier_or_null == NULL )&&( to_classifier_or_null == NULL ))
     148              :         {
     149              :             /* maybe the data_visible_set_t was full and the classifier could not be stored? */
     150           10 :             U8_LOG_ANOMALY_INT( "data_visible_set_t contains a relationship but no related classifier.", relationship_id );
     151              :         }
     152              :         else
     153              :         {
     154              :             /* it is normal behavior that only one end of the relation is contained in the data_visible_set_t */
     155              :         }
     156              :     }
     157              : 
     158          444 :     U8_TRACE_END();
     159          444 :     return result;
     160              : }
     161              : 
     162              : 
     163              : /*
     164              : Copyright 2019-2025 Andreas Warnke
     165              : 
     166              : Licensed under the Apache License, Version 2.0 (the "License");
     167              : you may not use this file except in compliance with the License.
     168              : You may obtain a copy of the License at
     169              : 
     170              :     http://www.apache.org/licenses/LICENSE-2.0
     171              : 
     172              : Unless required by applicable law or agreed to in writing, software
     173              : distributed under the License is distributed on an "AS IS" BASIS,
     174              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     175              : See the License for the specific language governing permissions and
     176              : limitations under the License.
     177              : */
        

Generated by: LCOV version 2.0-1