LCOV - code coverage report
Current view: top level - data/include/set - data_profile_part.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 49 53 92.5 %
Date: 2024-10-26 21:44:38 Functions: 5 5 100.0 %

          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          34 : 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          34 :     assert( NULL != stereotype_name );
      11          34 :     assert( NULL != db_reader );
      12          34 :     u8_error_t result = U8_ERROR_NONE;
      13             : 
      14          34 :     const utf8stringview_t stereotype_name_view = UTF8STRINGVIEW_STR( stereotype_name );
      15             : 
      16          34 :     const bool already_loaded
      17          34 :         = ( NULL != data_profile_part_get_stereotype_by_name_const( this_, &stereotype_name_view ) );
      18          34 :     if ( ! already_loaded )  /* filter duplicates */
      19             :     {
      20          32 :         if ( (*this_).stereotype_count < DATA_PROFILE_PART_MAX_STEREOTYPES )
      21             :         {
      22             :             const u8_error_t db_err
      23          31 :                 = data_database_reader_get_classifier_by_name( db_reader,
      24             :                                                                stereotype_name,  /* : name */
      25          31 :                                                                &((*this_).stereotypes[(*this_).stereotype_count])
      26             :                                                              );
      27             :             const data_classifier_type_t c_type
      28          31 :                 = data_classifier_get_main_type( &((*this_).stereotypes[(*this_).stereotype_count]) );
      29             : 
      30          31 :             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          31 :             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          26 :             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          26 :             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          25 :                 (*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          34 :     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         292 : 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         292 :     assert( (*this_).stereotype_count <= DATA_PROFILE_PART_MAX_STEREOTYPES );
      97         292 :     const data_classifier_t *result = NULL;
      98             : 
      99             :     /* iterate over all visible classifiers */
     100         598 :     for ( uint32_t index = 0; ( index < (*this_).stereotype_count ) && ( result == NULL ); index ++ )
     101             :     {
     102         306 :         const data_classifier_t *const stereotype = &((*this_).stereotypes[index]);
     103         306 :         assert ( data_classifier_is_valid( stereotype ) );
     104             : 
     105         306 :         if ( utf8stringview_equals_str( stereotype_name, data_classifier_get_name_const( stereotype ) ) )
     106             :         {
     107           4 :             result = stereotype;
     108             :         }
     109             :     }
     110             : 
     111         292 :     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-2024 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 1.16