LCOV - code coverage report
Current view: top level - data/include/set - data_visible_set.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.71.2_covts Lines: 95.5 % 223 213
Test Date: 2026-08-22 19:47:36 Functions: 100.0 % 33 33

            Line data    Source code
       1              : /* File: data_visible_set.inl; Copyright and License: see below */
       2              : 
       3              : #include "u8/u8_log.h"
       4              : #include "u8/u8_trace.h"
       5              : #include <assert.h>
       6              : 
       7              : /* ================================ diagram ================================ */
       8              : 
       9          770 : static inline const data_diagram_t *data_visible_set_get_diagram_const ( const data_visible_set_t *this_ )
      10              : {
      11          770 :     return &((*this_).diagram);
      12              : }
      13              : 
      14            2 : static inline data_diagram_t *data_visible_set_get_diagram_ptr ( data_visible_set_t *this_ )
      15              : {
      16            2 :     return &((*this_).diagram);
      17              : }
      18              : 
      19            1 : static inline u8_error_t data_visible_set_replace_diagram( data_visible_set_t *this_, const data_diagram_t *new_diagram )
      20              : {
      21            1 :     assert( NULL != new_diagram );
      22            1 :     data_diagram_replace( &((*this_).diagram), new_diagram );
      23            1 :     return U8_ERROR_NONE;
      24              : }
      25              : 
      26              : /* ================================ classifiers ================================ */
      27              : 
      28           41 : static inline uint32_t data_visible_set_get_visible_classifier_count ( const data_visible_set_t *this_ )
      29              : {
      30           41 :     return (*this_).visible_classifier_count;
      31              : }
      32              : 
      33         2287 : static inline const data_visible_classifier_t *data_visible_set_get_visible_classifier_const ( const data_visible_set_t *this_, uint32_t index )
      34              : {
      35         2287 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
      36              : 
      37              :     const data_visible_classifier_t *result;
      38         2287 :     if ( index < (*this_).visible_classifier_count )
      39              :     {
      40         2287 :         result = &((*this_).visible_classifiers[index]);
      41              :     }
      42              :     else
      43              :     {
      44            0 :         result = NULL;
      45            0 :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).visible_classifier_count)", index );
      46              :     }
      47              : 
      48         2287 :     return result;
      49              : }
      50              : 
      51              : static inline data_visible_classifier_t *data_visible_set_get_visible_classifier_ptr ( data_visible_set_t *this_, uint32_t index )
      52              : {
      53              :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
      54              : 
      55              :     data_visible_classifier_t *result;
      56              :     if ( index < (*this_).visible_classifier_count )
      57              :     {
      58              :         result = &((*this_).visible_classifiers[index]);
      59              :     }
      60              :     else
      61              :     {
      62              :         result = NULL;
      63              :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).visible_classifier_count)", index );
      64              :     }
      65              : 
      66              :     return result;
      67              : }
      68              : 
      69            1 : static inline const data_visible_classifier_t *data_visible_set_get_visible_classifier_by_id_const ( const data_visible_set_t *this_, data_row_t diagramelement_id )
      70              : {
      71            1 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
      72            1 :     const data_visible_classifier_t *result = NULL;
      73              : 
      74              :     /* iterate over all visible classifiers */
      75            2 :     for ( uint32_t index = 0; index < (*this_).visible_classifier_count; index ++ )
      76              :     {
      77              :         const data_visible_classifier_t *visible_classifier;
      78            2 :         visible_classifier = &((*this_).visible_classifiers[index]);
      79            2 :         assert ( data_visible_classifier_is_valid( visible_classifier ) );
      80              : 
      81              :         const data_diagramelement_t *diagramelement;
      82            2 :         diagramelement = data_visible_classifier_get_diagramelement_const( visible_classifier );
      83            2 :         if ( data_diagramelement_get_row( diagramelement ) == diagramelement_id )
      84              :         {
      85            1 :             result = visible_classifier;
      86            1 :             break;
      87              :         }
      88              :     }
      89              : 
      90            1 :     return result;
      91              : }
      92              : 
      93            1 : static inline data_visible_classifier_t *data_visible_set_get_visible_classifier_by_id_ptr ( data_visible_set_t *this_, data_row_t diagramelement_id )
      94              : {
      95            1 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
      96            1 :     data_visible_classifier_t *result = NULL;
      97              : 
      98              :     /* iterate over all visible classifiers */
      99            1 :     for ( uint32_t index = 0; index < (*this_).visible_classifier_count; index ++ )
     100              :     {
     101              :         data_visible_classifier_t *visible_classifier;
     102            1 :         visible_classifier = &((*this_).visible_classifiers[index]);
     103            1 :         assert ( data_visible_classifier_is_valid( visible_classifier ) );
     104              : 
     105              :         data_diagramelement_t *diagramelement;
     106            1 :         diagramelement = data_visible_classifier_get_diagramelement_ptr( visible_classifier );
     107            1 :         if ( data_diagramelement_get_row( diagramelement ) == diagramelement_id )
     108              :         {
     109            1 :             result = visible_classifier;
     110            1 :             break;
     111              :         }
     112              :     }
     113              : 
     114            1 :     return result;
     115              : }
     116              : 
     117          889 : static inline const data_classifier_t *data_visible_set_get_classifier_by_id_const ( const data_visible_set_t *this_, data_row_t row )
     118              : {
     119          889 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     120          889 :     const data_classifier_t *result = NULL;
     121              : 
     122        42582 :     for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
     123              :     {
     124              :         const data_visible_classifier_t *visible_classifier;
     125        42559 :         visible_classifier = &((*this_).visible_classifiers[index]);
     126        42559 :         assert ( data_visible_classifier_is_valid( visible_classifier ) );
     127              : 
     128              :         const data_classifier_t *probe;
     129        42559 :         probe = data_visible_classifier_get_classifier_const( visible_classifier );
     130        42559 :         if ( row == data_classifier_get_row( probe ) )
     131              :         {
     132          866 :             result = probe;
     133          866 :             break;
     134              :         }
     135              :     }
     136              : 
     137          889 :     return result;
     138              : }
     139              : 
     140            1 : static inline data_classifier_t *data_visible_set_get_classifier_by_id_ptr ( data_visible_set_t *this_, data_row_t row )
     141              : {
     142            1 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     143            1 :     data_classifier_t *result = NULL;
     144              : 
     145            1 :     for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
     146              :     {
     147              :         data_visible_classifier_t *visible_classifier;
     148            1 :         visible_classifier = &((*this_).visible_classifiers[index]);
     149            1 :         assert ( data_visible_classifier_is_valid( visible_classifier ) );
     150              : 
     151              :         data_classifier_t *probe;
     152            1 :         probe = data_visible_classifier_get_classifier_ptr( visible_classifier );
     153            1 :         if ( row == data_classifier_get_row( probe ) )
     154              :         {
     155            1 :             result = probe;
     156            1 :             break;
     157              :         }
     158              :     }
     159              : 
     160            1 :     return result;
     161              : }
     162              : 
     163            4 : static inline int32_t data_visible_set_get_classifier_index ( const data_visible_set_t *this_, data_row_t row )
     164              : {
     165            4 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     166            4 :     int32_t result = -1;
     167              : 
     168            6 :     for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
     169              :     {
     170              :         const data_classifier_t *probe;
     171            6 :         probe = data_visible_classifier_get_classifier_const( &((*this_).visible_classifiers[index]) );
     172            6 :         if ( row == data_classifier_get_row( probe ) )
     173              :         {
     174            4 :             result = index;
     175            4 :             break;
     176              :         }
     177              :     }
     178              : 
     179            4 :     return result;
     180              : }
     181              : 
     182            1 : static inline uint32_t data_visible_set_get_classifier_index_from_pointer ( const data_visible_set_t *this_,
     183              :                                                                             const data_visible_classifier_t *vis_classifier_ptr )
     184              : {
     185            1 :     assert ( NULL != vis_classifier_ptr );  /* input parameters test */
     186            1 :     assert ( vis_classifier_ptr >= &((*this_).visible_classifiers[0]) );  /* input parameters test */
     187            1 :     assert ( vis_classifier_ptr < &((*this_).visible_classifiers[DATA_VISIBLE_SET_MAX_CLASSIFIERS]) );  /* input parameters test */
     188              :     assert ( 3 == &((*this_).visible_classifiers[3]) - (*this_).visible_classifiers );  /* compiler test */
     189            1 :     return ( vis_classifier_ptr - (*this_).visible_classifiers );
     190              : }
     191              : 
     192          129 : static inline u8_error_t data_visible_set_append_classifier( data_visible_set_t *this_, const data_visible_classifier_t *new_classifier )
     193              : {
     194          129 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     195          129 :     assert( NULL != new_classifier );
     196          129 :     u8_error_t result = U8_ERROR_NONE;
     197              :     
     198          129 :     const uint32_t new_index = (*this_).visible_classifier_count;
     199          129 :     if ( new_index < DATA_VISIBLE_SET_MAX_CLASSIFIERS )
     200              :     {
     201          128 :         data_visible_classifier_copy( &((*this_).visible_classifiers[new_index]), new_classifier );
     202          128 :         (*this_).visible_classifier_count ++;
     203              :     }
     204              :     else
     205              :     {
     206            1 :         result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
     207              :     }
     208              :     
     209          129 :     return result;
     210              : }
     211              : 
     212              : /* ================================ features ================================ */
     213              : 
     214           14 : static inline uint32_t data_visible_set_get_feature_count ( const data_visible_set_t *this_ )
     215              : {
     216           14 :     return (*this_).feature_count;
     217              : }
     218              : 
     219          559 : static inline const data_feature_t *data_visible_set_get_feature_const ( const data_visible_set_t *this_, uint32_t index )
     220              : {
     221          559 :     assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
     222              : 
     223              :     const data_feature_t *result;
     224          559 :     if ( index < (*this_).feature_count )
     225              :     {
     226          559 :         result = &((*this_).features[index]);
     227              :     }
     228              :     else
     229              :     {
     230            0 :         result = NULL;
     231            0 :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).feature_count)", index );
     232              :     }
     233              : 
     234          559 :     return result;
     235              : }
     236              : 
     237            2 : static inline data_feature_t *data_visible_set_get_feature_ptr ( data_visible_set_t *this_, uint32_t index )
     238              : {
     239            2 :     assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
     240              : 
     241              :     data_feature_t *result;
     242            2 :     if ( index < (*this_).feature_count )
     243              :     {
     244            2 :         result = &((*this_).features[index]);
     245              :     }
     246              :     else
     247              :     {
     248            0 :         result = NULL;
     249            0 :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).feature_count)", index );
     250              :     }
     251              : 
     252            2 :     return result;
     253              : }
     254              : 
     255         1180 : static inline const data_feature_t *data_visible_set_get_feature_by_id_const ( const data_visible_set_t *this_, data_row_t row )
     256              : {
     257         1180 :     assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
     258         1180 :     const data_feature_t *result = NULL;
     259              : 
     260       238203 :     for ( int index = 0; index < (*this_).feature_count; index ++ )
     261              :     {
     262              :         const data_feature_t *probe;
     263       237372 :         probe = &((*this_).features[index]);
     264       237372 :         if ( row == data_feature_get_row( probe ) )
     265              :         {
     266          349 :             result = probe;
     267          349 :             break;
     268              :         }
     269              :     }
     270              : 
     271         1180 :     return result;
     272              : }
     273              : 
     274            1 : static inline data_feature_t *data_visible_set_get_feature_by_id_ptr ( data_visible_set_t *this_, data_row_t row )
     275              : {
     276            1 :     assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
     277            1 :     data_feature_t *result = NULL;
     278              : 
     279            1 :     for ( int index = 0; index < (*this_).feature_count; index ++ )
     280              :     {
     281              :         data_feature_t *probe;
     282            1 :         probe = &((*this_).features[index]);
     283            1 :         if ( row == data_feature_get_row( probe ) )
     284              :         {
     285            1 :             result = probe;
     286            1 :             break;
     287              :         }
     288              :     }
     289              : 
     290            1 :     return result;
     291              : }
     292              : 
     293            1 : static inline data_feature_t *data_visible_set_get_feature_list_ptr ( data_visible_set_t *this_ )
     294              : {
     295            1 :     assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
     296            1 :     return (*this_).features;
     297              : }
     298              : 
     299          257 : static inline u8_error_t data_visible_set_append_feature( data_visible_set_t *this_, const data_feature_t *new_feature )
     300              : {
     301          257 :     assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
     302          257 :     assert( NULL != new_feature );
     303          257 :     u8_error_t result = U8_ERROR_NONE;
     304              :     
     305          257 :     const uint32_t new_index = (*this_).feature_count;
     306          257 :     if ( new_index < DATA_VISIBLE_SET_MAX_FEATURES )
     307              :     {
     308          256 :         data_feature_copy( &((*this_).features[new_index]), new_feature );
     309          256 :         (*this_).feature_count ++;
     310              :     }
     311              :     else
     312              :     {
     313            1 :         result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
     314              :     }
     315              :     
     316          257 :     return result;
     317              : }
     318              : 
     319              : /* ================================ relationships ================================ */
     320              : 
     321           14 : static inline uint32_t data_visible_set_get_relationship_count ( const data_visible_set_t *this_ )
     322              : {
     323           14 :     return (*this_).relationship_count;
     324              : }
     325              : 
     326          805 : static inline const data_relationship_t *data_visible_set_get_relationship_const ( const data_visible_set_t *this_, uint32_t index )
     327              : {
     328          805 :     assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
     329              : 
     330              :     const data_relationship_t *result;
     331          805 :     if ( index < (*this_).relationship_count )
     332              :     {
     333          805 :         result = &((*this_).relationships[index]);
     334              :     }
     335              :     else
     336              :     {
     337            0 :         result = NULL;
     338            0 :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).relationship_count)", index );
     339              :     }
     340              : 
     341          805 :     return result;
     342              : }
     343              : 
     344            5 : static inline data_relationship_t *data_visible_set_get_relationship_ptr ( data_visible_set_t *this_, uint32_t index )
     345              : {
     346            5 :     assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
     347              : 
     348              :     data_relationship_t *result;
     349            5 :     if ( index < (*this_).relationship_count )
     350              :     {
     351            5 :         result = &((*this_).relationships[index]);
     352              :     }
     353              :     else
     354              :     {
     355            0 :         result = NULL;
     356            0 :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).relationship_count)", index );
     357              :     }
     358              : 
     359            5 :     return result;
     360              : }
     361              : 
     362          449 : static inline const data_relationship_t *data_visible_set_get_relationship_by_id_const ( const data_visible_set_t *this_, data_row_t row )
     363              : {
     364          449 :     assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
     365          449 :     const data_relationship_t *result = NULL;
     366              : 
     367        74679 :     for ( int index = 0; index < (*this_).relationship_count; index ++ )
     368              :     {
     369              :         const data_relationship_t *probe;
     370        74679 :         probe = &((*this_).relationships[index]);
     371        74679 :         if ( row == data_relationship_get_row( probe ) )
     372              :         {
     373          449 :             result = probe;
     374          449 :             break;
     375              :         }
     376              :     }
     377              : 
     378          449 :     return result;
     379              : }
     380              : 
     381            1 : static inline data_relationship_t *data_visible_set_get_relationship_by_id_ptr ( data_visible_set_t *this_, data_row_t row )
     382              : {
     383            1 :     assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
     384            1 :     data_relationship_t *result = NULL;
     385              : 
     386            2 :     for ( int index = 0; index < (*this_).relationship_count; index ++ )
     387              :     {
     388              :         data_relationship_t *probe;
     389            2 :         probe = &((*this_).relationships[index]);
     390            2 :         if ( row == data_relationship_get_row( probe ) )
     391              :         {
     392            1 :             result = probe;
     393            1 :             break;
     394              :         }
     395              :     }
     396              : 
     397            1 :     return result;
     398              : }
     399              : 
     400            4 : static inline bool data_visible_set_is_ancestor_by_index ( const data_visible_set_t *this_, uint32_t ancestor_index, uint32_t descendant_index )
     401              : {
     402            4 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     403            4 :     assert( ancestor_index < (*this_).visible_classifier_count );
     404            4 :     assert( descendant_index < (*this_).visible_classifier_count );
     405              : 
     406            4 :     const bool result = (*this_).containment_cache[ancestor_index][descendant_index];
     407            4 :     if ( result )
     408              :     {
     409            1 :         U8_TRACE_INFO_INT_INT( "ancestor has decendant:", ancestor_index, descendant_index );
     410              :     }
     411            4 :     return result;
     412              : }
     413              : 
     414            1 : static inline uint32_t data_visible_set_count_ancestors_of_index ( const data_visible_set_t *this_, uint32_t classifier_index )
     415              : {
     416            1 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     417            1 :     assert( classifier_index < (*this_).visible_classifier_count );
     418              : 
     419            1 :     uint32_t result = 0;
     420              : 
     421            3 :     for ( uint32_t ancestor_index = 0; ancestor_index < (*this_).visible_classifier_count; ancestor_index ++ )
     422              :     {
     423            2 :         if ( (*this_).containment_cache[ancestor_index][classifier_index] )
     424              :         {
     425            1 :             result ++;
     426              :         }
     427              :     }
     428              : 
     429            1 :     return result;
     430              : }
     431              : 
     432            1 : static inline uint32_t data_visible_set_count_descendants_of_index ( const data_visible_set_t *this_, uint32_t classifier_index )
     433              : {
     434            1 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     435            1 :     assert( classifier_index < (*this_).visible_classifier_count );
     436              : 
     437            1 :     uint32_t result = 0;
     438              : 
     439            3 :     for ( uint32_t descendant_index = 0; descendant_index < (*this_).visible_classifier_count; descendant_index ++ )
     440              :     {
     441            2 :         if ( (*this_).containment_cache[classifier_index][descendant_index] )
     442              :         {
     443            1 :             result ++;
     444              :         }
     445              :     }
     446              : 
     447            1 :     return result;
     448              : }
     449              : 
     450          385 : static inline u8_error_t data_visible_set_append_relationship( data_visible_set_t *this_, const data_relationship_t *new_relationship )
     451              : {
     452          385 :     assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
     453          385 :     assert( NULL != new_relationship );
     454          385 :     u8_error_t result = U8_ERROR_NONE;
     455              :     
     456          385 :     const uint32_t new_index = (*this_).relationship_count;
     457          385 :     if ( new_index < DATA_VISIBLE_SET_MAX_RELATIONSHIPS )
     458              :     {
     459          384 :         data_relationship_copy( &((*this_).relationships[new_index]), new_relationship );
     460          384 :         (*this_).relationship_count ++;
     461              :     }
     462              :     else
     463              :     {
     464            1 :         result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
     465              :     }
     466              :     
     467          385 :     return result;
     468              : }
     469              : 
     470              : /* ================================ misc ================================ */
     471              : 
     472           30 : static inline bool data_visible_set_is_valid ( const data_visible_set_t *this_ )
     473              : {
     474           30 :     return data_diagram_is_valid( &((*this_).diagram) );
     475              : }
     476              : 
     477            1 : static inline void data_visible_set_invalidate ( data_visible_set_t *this_ )
     478              : {
     479            1 :     data_visible_set_reinit( this_ );
     480            1 : }
     481              : 
     482           16 : static inline void data_visible_set_private_destroy_visible_classifiers( data_visible_set_t *this_ )
     483              : {
     484           16 :     assert( (*this_).visible_classifier_count <= DATA_VISIBLE_SET_MAX_CLASSIFIERS );
     485              : 
     486          201 :     for ( int index = 0; index < (*this_).visible_classifier_count; index ++ )
     487              :     {
     488          185 :         data_visible_classifier_destroy ( &((*this_).visible_classifiers[index]) );
     489              :     }
     490              : 
     491           16 :     (*this_).visible_classifier_count = 0;
     492           16 : }
     493              : 
     494           16 : static inline void data_visible_set_private_destroy_features( data_visible_set_t *this_ )
     495              : {
     496           16 :     assert( (*this_).feature_count <= DATA_VISIBLE_SET_MAX_FEATURES );
     497              : 
     498          277 :     for ( int index = 0; index < (*this_).feature_count; index ++ )
     499              :     {
     500          261 :         data_feature_destroy ( &((*this_).features[index]) );
     501              :     }
     502              : 
     503           16 :     (*this_).feature_count = 0;
     504           16 : }
     505              : 
     506           16 : static inline void data_visible_set_private_destroy_relationships( data_visible_set_t *this_ )
     507              : {
     508           16 :     assert( (*this_).relationship_count <= DATA_VISIBLE_SET_MAX_RELATIONSHIPS );
     509              : 
     510          407 :     for ( int index = 0; index < (*this_).relationship_count; index ++ )
     511              :     {
     512          391 :         data_relationship_destroy ( &((*this_).relationships[index]) );
     513              :     }
     514              : 
     515           16 :     (*this_).relationship_count = 0;
     516           16 : }
     517              : 
     518              : 
     519              : /*
     520              : Copyright 2016-2026 Andreas Warnke
     521              : 
     522              : Licensed under the Apache License, Version 2.0 (the "License");
     523              : you may not use this file except in compliance with the License.
     524              : You may obtain a copy of the License at
     525              : 
     526              :     http://www.apache.org/licenses/LICENSE-2.0
     527              : 
     528              : Unless required by applicable law or agreed to in writing, software
     529              : distributed under the License is distributed on an "AS IS" BASIS,
     530              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     531              : See the License for the specific language governing permissions and
     532              : limitations under the License.
     533              : */
        

Generated by: LCOV version 2.0-1