LCOV - code coverage report
Current view: top level - data/include/set - data_profile_part.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 92.5 % 53 49
Test Date: 2025-05-01 10:10:14 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /* File: data_profile_part.inl; Copyright and License: see below */
       2              : 
       3              : #include "u8/u8_log.h"
       4              : #include <assert.h>
       5              : 
       6           58 : static inline u8_error_t data_profile_part_private_load_stereotype ( data_profile_part_t *this_,
       7              :                                                                      const char *stereotype_name,
       8              :                                                                      data_database_reader_t *db_reader )
       9              : {
      10           58 :     assert( NULL != stereotype_name );
      11           58 :     assert( NULL != db_reader );
      12           58 :     u8_error_t result = U8_ERROR_NONE;
      13              : 
      14           58 :     const utf8stringview_t stereotype_name_view = UTF8STRINGVIEW_STR( stereotype_name );
      15              : 
      16           58 :     const bool already_loaded
      17           58 :         = ( NULL != data_profile_part_get_stereotype_by_name_const( this_, &stereotype_name_view ) );
      18           58 :     if ( ! already_loaded )  /* filter duplicates */
      19              :     {
      20           56 :         if ( (*this_).stereotype_count < DATA_PROFILE_PART_MAX_STEREOTYPES )
      21              :         {
      22              :             const u8_error_t db_err
      23           55 :                 = data_database_reader_get_classifier_by_name( db_reader,
      24              :                                                                stereotype_name,  /* : name */
      25           55 :                                                                &((*this_).stereotypes[(*this_).stereotype_count])
      26              :                                                              );
      27              :             const data_classifier_type_t c_type
      28           55 :                 = data_classifier_get_main_type( &((*this_).stereotypes[(*this_).stereotype_count]) );
      29              : 
      30           55 :             if ( u8_error_contains( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
      31              :             {
      32            0 :                 U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading stereotypes of a diagram" );
      33              :             }
      34           55 :             if ( u8_error_contains( db_err, U8_ERROR_NOT_FOUND ) )
      35              :             {
      36              :                 /* no entry found. */
      37            5 :                 U8_LOG_EVENT( "A stereotype does not exist." );
      38            5 :                 U8_TRACE_INFO_STR( "stereotype does not exist:", stereotype_name );
      39              :             }
      40           50 :             else if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
      41              :             {
      42              :                 /* error at loading */
      43            0 :                 U8_LOG_ERROR( "A stereotype could not be loaded!" );
      44            0 :                 U8_TRACE_INFO_STR( "stereotype could not be loaded:", stereotype_name );
      45            0 :                 result |= db_err;  /* collect error flags */
      46              :             }
      47           50 :             else if ( DATA_CLASSIFIER_TYPE_STEREOTYPE != c_type )
      48              :             {
      49              :                 /* wrong-typed entry found. */
      50            1 :                 U8_LOG_EVENT( "A stereotype was found but is not of type stereotype." );
      51            1 :                 U8_TRACE_INFO_STR( "loaded stereotype is not of type stereotype:", stereotype_name );
      52              :             }
      53              :             else
      54              :             {
      55              :                 /* success */
      56           49 :                 (*this_).stereotype_count ++;
      57              :             }
      58              :         }
      59              :         else
      60              :         {
      61              :             /* there is another stereotype to be loaded but no more space left */
      62            1 :             U8_LOG_ERROR( "U8_ERROR_ARRAY_BUFFER_EXCEEDED at loading stereotypes of a diagram" );
      63            1 :             result |= U8_ERROR_ARRAY_BUFFER_EXCEEDED;
      64              :         }
      65              :     }
      66              : 
      67           58 :     return result;
      68              : }
      69              : 
      70            3 : static inline uint32_t data_profile_part_get_stereotype_count ( const data_profile_part_t *this_ )
      71              : {
      72            3 :     return (*this_).stereotype_count;
      73              : }
      74              : 
      75            2 : static inline const data_classifier_t *data_profile_part_get_stereotype_const ( const data_profile_part_t *this_, uint32_t index )
      76              : {
      77            2 :     assert( (*this_).stereotype_count <= DATA_PROFILE_PART_MAX_STEREOTYPES );
      78              : 
      79              :     const data_classifier_t *result;
      80            2 :     if ( index < (*this_).stereotype_count )
      81              :     {
      82            1 :         result = &((*this_).stereotypes[index]);
      83              :     }
      84              :     else
      85              :     {
      86            1 :         result = NULL;
      87            1 :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).stereotype_count)", index );
      88              :     }
      89              : 
      90            2 :     return result;
      91              : }
      92              : 
      93          316 : static inline const data_classifier_t *data_profile_part_get_stereotype_by_name_const ( const data_profile_part_t *this_,
      94              :                                                                                         const utf8stringview_t *stereotype_name )
      95              : {
      96          316 :     assert( (*this_).stereotype_count <= DATA_PROFILE_PART_MAX_STEREOTYPES );
      97          316 :     const data_classifier_t *result = NULL;
      98              : 
      99              :     /* iterate over all visible classifiers */
     100         1498 :     for ( uint32_t index = 0; ( index < (*this_).stereotype_count ) && ( result == NULL ); index ++ )
     101              :     {
     102         1182 :         const data_classifier_t *const stereotype = &((*this_).stereotypes[index]);
     103         1182 :         assert ( data_classifier_is_valid( stereotype ) );
     104              : 
     105         1182 :         if ( utf8stringview_equals_str( stereotype_name, data_classifier_get_name_const( stereotype ) ) )
     106              :         {
     107            4 :             result = stereotype;
     108              :         }
     109              :     }
     110              : 
     111          316 :     return result;
     112              : }
     113              : 
     114            1 : static inline void data_profile_part_trace ( const data_profile_part_t *this_ )
     115              : {
     116            1 :     U8_TRACE_INFO_INT( "data_profile_part_t: [length]", (*this_).stereotype_count );
     117            2 :     for ( uint32_t index = 0; index < (*this_).stereotype_count; index ++ )
     118              :     {
     119            1 :         const data_classifier_t *const stereotype = &((*this_).stereotypes[index]);
     120            1 :         assert ( data_classifier_is_valid( stereotype ) );
     121            1 :         U8_TRACE_INFO_STR( "-", data_classifier_get_name_const( stereotype ) );
     122              :     }
     123            1 : }
     124              : 
     125              : 
     126              : /*
     127              : Copyright 2023-2025 Andreas Warnke
     128              : 
     129              : Licensed under the Apache License, Version 2.0 (the "License");
     130              : you may not use this file except in compliance with the License.
     131              : You may obtain a copy of the License at
     132              : 
     133              :     http://www.apache.org/licenses/LICENSE-2.0
     134              : 
     135              : Unless required by applicable law or agreed to in writing, software
     136              : distributed under the License is distributed on an "AS IS" BASIS,
     137              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     138              : See the License for the specific language governing permissions and
     139              : limitations under the License.
     140              : */
        

Generated by: LCOV version 2.0-1