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.57.0_covts Lines: 35 46 76.1 %
Date: 2024-04-07 11:14:42 Functions: 3 4 75.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          32 : 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          32 :     assert( NULL != stereotype_name );
      11          32 :     assert( NULL != db_reader );
      12          32 :     u8_error_t result = U8_ERROR_NONE;
      13             : 
      14          32 :     const utf8stringview_t stereotype_name_view = UTF8STRINGVIEW_STR( stereotype_name );
      15             : 
      16          32 :     const bool already_loaded
      17          32 :         = ( NULL != data_profile_part_get_stereotype_by_name_const( this_, &stereotype_name_view ) );
      18          32 :     if ( ! already_loaded )  /* filter duplicates */
      19             :     {
      20          30 :         if ( (*this_).stereotype_count < DATA_PROFILE_PART_MAX_STEREOTYPES )
      21             :         {
      22             :             const u8_error_t db_err
      23          29 :                 = data_database_reader_get_classifier_by_name( db_reader,
      24             :                                                                stereotype_name,  /* : name */
      25          29 :                                                                &((*this_).stereotypes[(*this_).stereotype_count])
      26             :                                                              );
      27             :             const data_classifier_type_t c_type
      28          29 :                 = data_classifier_get_main_type( &((*this_).stereotypes[(*this_).stereotype_count]) );
      29             : 
      30          29 :             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          29 :             if ( u8_error_contains( db_err, U8_ERROR_NOT_FOUND ) )
      35             :             {
      36             :                 /* no entry found. */
      37           3 :                 U8_LOG_EVENT( "A stereotype does not exist." );
      38           3 :                 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          32 :     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             : static inline const data_classifier_t *data_profile_part_get_stereotype_const ( const data_profile_part_t *this_, uint32_t index )
      76             : {
      77             :     assert( (*this_).stereotype_count <= DATA_PROFILE_PART_MAX_STEREOTYPES );
      78             : 
      79             :     const data_classifier_t *result;
      80             :     if ( index < (*this_).stereotype_count )
      81             :     {
      82             :         result = &((*this_).stereotypes[index]);
      83             :     }
      84             :     else
      85             :     {
      86             :         result = NULL;
      87             :         U8_LOG_ERROR_INT( "index out of bounds (>=(*this_).stereotype_count)", index );
      88             :     }
      89             : 
      90             :     return result;
      91             : }
      92             : 
      93         290 : 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         290 :     assert( (*this_).stereotype_count <= DATA_PROFILE_PART_MAX_STEREOTYPES );
      97         290 :     const data_classifier_t *result = NULL;
      98             : 
      99             :     /* iterate over all visible classifiers */
     100         594 :     for ( uint32_t index = 0; ( index < (*this_).stereotype_count ) && ( result == NULL ); index ++ )
     101             :     {
     102         304 :         const data_classifier_t *const stereotype = &((*this_).stereotypes[index]);
     103         304 :         assert ( data_classifier_is_valid( stereotype ) );
     104             : 
     105         304 :         if ( utf8stringview_equals_str( stereotype_name, data_classifier_get_name_const( stereotype ) ) )
     106             :         {
     107           4 :             result = stereotype;
     108             :         }
     109             :     }
     110             : 
     111         290 :     return result;
     112             : }
     113             : 
     114           0 : static inline void data_profile_part_trace ( const data_profile_part_t *this_ )
     115             : {
     116           0 :     U8_TRACE_INFO_INT( "data_profile_part_t: [length]", (*this_).stereotype_count );
     117           0 :     for ( uint32_t index = 0; index < (*this_).stereotype_count; index ++ )
     118             :     {
     119           0 :         const data_classifier_t *const stereotype = &((*this_).stereotypes[index]);
     120           0 :         assert ( data_classifier_is_valid( stereotype ) );
     121           0 :         U8_TRACE_INFO_STR( "-", data_classifier_get_name_const( stereotype ) );
     122             :     }
     123           0 : }
     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