LCOV - code coverage report
Current view: top level - data/include/entity - data_id.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.63.2_covts Lines: 100.0 % 162 162
Test Date: 2025-05-01 10:10:14 Functions: 100.0 % 18 18

            Line data    Source code
       1              : /* File: data_id.inl; Copyright and License: see below */
       2              : 
       3              : #include "u8/u8_trace.h"
       4              : #include "u8/u8_log.h"
       5              : #include "utf8stringbuf/utf8string.h"
       6              : 
       7         4398 : static inline void data_id_init ( data_id_t *this_, data_table_t table, data_row_t row_id )
       8              : {
       9         4398 :     (*this_).table = table;
      10         4398 :     (*this_).row_id = row_id;
      11         4398 : }
      12              : 
      13            8 : static inline void data_id_init_by_string ( data_id_t *this_, const char* string_to_parse )
      14              : {
      15            8 :     assert( string_to_parse != NULL );
      16              : 
      17              :     utf8stringview_t parse_me;
      18            8 :     utf8stringview_t ignore_me = UTF8STRINGVIEW_EMPTY;
      19            8 :     utf8stringview_init_str( &parse_me, string_to_parse );
      20            8 :     data_id_init_by_stringview( this_, &parse_me, &ignore_me );
      21            8 :     if ( utf8stringview_get_length( &ignore_me ) != 0 )
      22              :     {
      23              :         /* error: there are additional characters */
      24            4 :         data_id_reinit_void( this_ );
      25              :     }
      26            8 :     utf8stringview_destroy( &parse_me );
      27            8 :     utf8stringview_destroy( &ignore_me );
      28            8 : }
      29              : 
      30           26 : static inline void data_id_init_by_stringview ( data_id_t *this_,
      31              :                                                 const utf8stringview_t* string_to_parse,
      32              :                                                 utf8stringview_t *out_remainder )
      33              : 
      34              : 
      35              : 
      36              : {
      37           26 :     assert( string_to_parse != NULL );
      38           26 :     assert( out_remainder != NULL );
      39              : 
      40           26 :     if ( utf8stringview_get_length( string_to_parse ) == 0 )
      41              :     {
      42            2 :         (*this_).table = DATA_TABLE_VOID;
      43            2 :         (*this_).row_id = DATA_ROW_VOID;
      44            2 :         *out_remainder = UTF8STRINGVIEW_EMPTY;
      45              :     }
      46              :     else
      47              :     {
      48           24 :         const char start = *utf8stringview_get_start( string_to_parse );
      49           24 :         switch ( start )
      50              :         {
      51            1 :             case DATA_TABLE_ALPHANUM_CLASSIFIER:
      52              :             {
      53            1 :                 (*this_).table = DATA_TABLE_CLASSIFIER;
      54              :             }
      55            1 :             break;
      56              : 
      57            1 :             case DATA_TABLE_ALPHANUM_FEATURE:
      58              :             {
      59            1 :                 (*this_).table = DATA_TABLE_FEATURE;
      60              :             }
      61            1 :             break;
      62              : 
      63            1 :             case DATA_TABLE_ALPHANUM_RELATIONSHIP:
      64              :             {
      65            1 :                 (*this_).table = DATA_TABLE_RELATIONSHIP;
      66              :             }
      67            1 :             break;
      68              : 
      69            1 :             case DATA_TABLE_ALPHANUM_DIAGRAMELEMENT:
      70              :             {
      71            1 :                 (*this_).table = DATA_TABLE_DIAGRAMELEMENT;
      72              :             }
      73            1 :             break;
      74              : 
      75           19 :             case DATA_TABLE_ALPHANUM_DIAGRAM:
      76              :             {
      77           19 :                 (*this_).table = DATA_TABLE_DIAGRAM;
      78              :             }
      79           19 :             break;
      80              : 
      81            1 :             default:
      82              :             {
      83            1 :                 (*this_).table = DATA_TABLE_VOID;
      84              :             }
      85            1 :             break;
      86              :         }
      87              : 
      88           24 :         if ( (*this_).table == DATA_TABLE_VOID )
      89              :         {
      90            1 :             (*this_).row_id = DATA_ROW_VOID;
      91            1 :             *out_remainder = *string_to_parse;
      92              :         }
      93              :         else
      94              :         {
      95           46 :             const utf8stringview_t int_to_parse
      96           23 :                 = UTF8STRINGVIEW( utf8stringview_get_start( string_to_parse )+1, utf8stringview_get_length( string_to_parse )-1 );
      97              :             int64_t number;
      98           23 :             const utf8error_t int_err = utf8stringview_parse_int( &int_to_parse, &number, out_remainder );
      99           23 :             const size_t byte_length = utf8stringview_get_length( &int_to_parse ) - utf8stringview_get_length( out_remainder );
     100           23 :             if (( int_err == UTF8ERROR_SUCCESS )&&( byte_length >= 4 )) {
     101           13 :                 (*this_).row_id = number;
     102              :             }
     103              :             else {
     104           10 :                 (*this_).table = DATA_TABLE_VOID;
     105           10 :                 (*this_).row_id = DATA_ROW_VOID;
     106           10 :                 *out_remainder = *string_to_parse;
     107              :             }
     108              :         }
     109              :     }
     110           26 : }
     111              : 
     112           12 : static inline void data_id_reinit ( data_id_t *this_, data_table_t table, data_row_t row_id )
     113              : {
     114           12 :     (*this_).table = table;
     115           12 :     (*this_).row_id = row_id;
     116           12 : }
     117              : 
     118           16 : static inline void data_id_init_void ( data_id_t *this_ )
     119              : {
     120           16 :     (*this_).table = DATA_TABLE_VOID;
     121           16 :     (*this_).row_id = DATA_ROW_VOID;
     122           16 : }
     123              : 
     124           25 : static inline void data_id_reinit_void ( data_id_t *this_ )
     125              : {
     126           25 :     (*this_).table = DATA_TABLE_VOID;
     127           25 :     (*this_).row_id = DATA_ROW_VOID;
     128           25 : }
     129              : 
     130            3 : static inline void data_id_copy ( data_id_t *this_, const data_id_t *that )
     131              : {
     132            3 :     (*this_) = (*that);
     133            3 : }
     134              : 
     135            3 : static inline void data_id_replace ( data_id_t *this_, const data_id_t *that )
     136              : {
     137            3 :     (*this_) = (*that);
     138            3 : }
     139              : 
     140         4220 : static inline void data_id_destroy ( data_id_t *this_ )
     141              : {
     142         4220 :     (*this_).table = DATA_TABLE_VOID;
     143         4220 :     (*this_).row_id = DATA_ROW_VOID;
     144         4220 : }
     145              : 
     146          148 : static inline data_table_t data_id_get_table ( const data_id_t *this_ )
     147              : {
     148          148 :     return (*this_).table;
     149              : }
     150              : 
     151          189 : static inline data_row_t data_id_get_row_id ( const data_id_t *this_ )
     152              : {
     153          189 :     return (*this_).row_id;
     154              : }
     155              : 
     156         3939 : static inline void data_id_trace ( const data_id_t *this_ )
     157              : {
     158         3939 :     const char prefix[] = "data_id_t: ";
     159              :     char id_buf[sizeof(prefix)+DATA_ID_MAX_UTF8STRING_LENGTH];
     160         3939 :     utf8stringbuf_t id_str = UTF8STRINGBUF( id_buf );
     161         3939 :     utf8stringbuf_copy_str( &id_str, prefix );
     162         3939 :     data_id_to_utf8stringbuf( this_, id_str );
     163         3939 :     U8_TRACE_INFO( utf8stringbuf_get_string( &id_str ) );
     164         3939 : }
     165              : 
     166        33431 : static inline bool data_id_equals ( const data_id_t *this_, const data_id_t *that )
     167              : {
     168        33427 :     return ( ( DATA_ROW_VOID != (*this_).row_id )&&( DATA_TABLE_VOID != (*this_).table )
     169        66858 :              &&( (*this_).row_id == (*that).row_id )&&( (*this_).table == (*that).table ) );
     170              : }
     171              : 
     172            7 : static inline bool data_id_equals_or_both_void ( const data_id_t *this_, const data_id_t *that )
     173              : {
     174            7 :     const bool one_or_both_valid = data_id_is_valid( this_ ) || data_id_is_valid( that );
     175            7 :     return ( ! one_or_both_valid ) || (( (*this_).row_id == (*that).row_id )&&( (*this_).table == (*that).table ));
     176              : }
     177              : 
     178          292 : static inline bool data_id_is_valid ( const data_id_t *this_ )
     179              : {
     180          292 :     return (( DATA_ROW_VOID != (*this_).row_id )&&( DATA_TABLE_VOID != (*this_).table ));
     181              : }
     182              : 
     183            5 : static inline bool data_id_equals_id ( const data_id_t *this_, data_table_t table, data_row_t row_id )
     184              : {
     185            4 :     return ( ( DATA_ROW_VOID != (*this_).row_id )&&( DATA_TABLE_VOID != (*this_).table )
     186            9 :     &&( (*this_).row_id == row_id )&&( (*this_).table == table ) );
     187              : }
     188              : 
     189         3947 : static inline utf8error_t data_id_to_utf8stringbuf ( const data_id_t *this_, utf8stringbuf_t out_str )
     190              : {
     191              :     assert( (*this_).table >= DATA_TABLE_VOID );
     192         3947 :     assert( (*this_).table <= DATA_TABLE_DIAGRAM );
     193         3947 :     utf8error_t result = UTF8ERROR_SUCCESS;
     194         3947 :     switch ( (*this_).table )
     195              :     {
     196          934 :         default:
     197              :         case DATA_TABLE_VOID:
     198              :         {
     199          934 :             result |= utf8stringbuf_append_str( &out_str, "void" );
     200              :         }
     201          934 :         break;
     202              : 
     203         1029 :         case DATA_TABLE_CLASSIFIER:
     204              :         {
     205         1029 :             result |= utf8stringbuf_append_str( &out_str, "C" );
     206              :         }
     207         1029 :         break;
     208              : 
     209          365 :         case DATA_TABLE_FEATURE:
     210              :         {
     211          365 :             result |= utf8stringbuf_append_str( &out_str, "F" );
     212              :         }
     213          365 :         break;
     214              : 
     215          466 :         case DATA_TABLE_RELATIONSHIP:
     216              :         {
     217          466 :             result |= utf8stringbuf_append_str( &out_str, "R" );
     218              :         }
     219          466 :         break;
     220              : 
     221          305 :         case DATA_TABLE_DIAGRAMELEMENT:
     222              :         {
     223          305 :             result |= utf8stringbuf_append_str( &out_str, "E" );
     224              :         }
     225          305 :         break;
     226              : 
     227          848 :         case DATA_TABLE_DIAGRAM:
     228              :         {
     229          848 :             result |= utf8stringbuf_append_str( &out_str, "D" );
     230              :         }
     231          848 :         break;
     232              :     }
     233              : 
     234         3947 :     if ( (*this_).table != DATA_TABLE_VOID )
     235              :     {
     236         3013 :         if ( 100 > (*this_).row_id )
     237              :         {
     238         1959 :             if ( 10 > (*this_).row_id )
     239              :             {
     240          911 :                 if ( 0 <= (*this_).row_id )
     241              :                 {
     242          847 :                     result |= utf8stringbuf_append_str( &out_str, "000" );
     243              :                 }
     244              :                 else
     245              :                 {
     246              :                     /* row_id is negative */
     247              :                 }
     248              :             }
     249              :             else
     250              :             {
     251         1048 :                 result |= utf8stringbuf_append_str( &out_str, "00" );
     252              :             }
     253              :         }
     254              :         else
     255              :         {
     256         1054 :             if ( 1000 > (*this_).row_id )
     257              :             {
     258         1036 :                 result |= utf8stringbuf_append_str( &out_str, "0" );
     259              :             }
     260              :             else
     261              :             {
     262              :                 /* row_id is greater than 1000 */
     263              :             }
     264              :         }
     265         3013 :         result |= utf8stringbuf_append_int( &out_str, (*this_).row_id );
     266              :     }
     267              : 
     268         3947 :     return result;
     269              : }
     270              : 
     271           12 : static inline u8_error_t data_id_to_utf8_writer ( const data_id_t *this_, utf8stream_writer_t *out_writer )
     272              : {
     273              :     assert( (*this_).table >= DATA_TABLE_VOID );
     274           12 :     assert( (*this_).table <= DATA_TABLE_DIAGRAM );
     275           12 :     u8_error_t result = U8_ERROR_NONE;
     276           12 :     switch ( (*this_).table )
     277              :     {
     278            1 :         default:
     279              :         case DATA_TABLE_VOID:
     280              :         {
     281            1 :             result |= utf8stream_writer_write_str( out_writer, "void" );
     282              :         }
     283            1 :         break;
     284              : 
     285            1 :         case DATA_TABLE_CLASSIFIER:
     286              :         {
     287            1 :             result |= utf8stream_writer_write_str( out_writer, "C" );
     288              :         }
     289            1 :         break;
     290              : 
     291            3 :         case DATA_TABLE_FEATURE:
     292              :         {
     293            3 :             result |= utf8stream_writer_write_str( out_writer, "F" );
     294              :         }
     295            3 :         break;
     296              : 
     297            5 :         case DATA_TABLE_RELATIONSHIP:
     298              :         {
     299            5 :             result |= utf8stream_writer_write_str( out_writer, "R" );
     300              :         }
     301            5 :         break;
     302              : 
     303            1 :         case DATA_TABLE_DIAGRAMELEMENT:
     304              :         {
     305            1 :             result |= utf8stream_writer_write_str( out_writer, "E" );
     306              :         }
     307            1 :         break;
     308              : 
     309            1 :         case DATA_TABLE_DIAGRAM:
     310              :         {
     311            1 :             result |= utf8stream_writer_write_str( out_writer, "D" );
     312              :         }
     313            1 :         break;
     314              :     }
     315              : 
     316           12 :     if ( (*this_).table != DATA_TABLE_VOID )
     317              :     {
     318           11 :         if ( 100 > (*this_).row_id )
     319              :         {
     320            9 :             if ( 10 > (*this_).row_id )
     321              :             {
     322            2 :                 if ( 0 <= (*this_).row_id )
     323              :                 {
     324            1 :                     result |= utf8stream_writer_write_str( out_writer, "000" );
     325              :                 }
     326              :                 else
     327              :                 {
     328              :                     /* row_id is negative */
     329              :                 }
     330              :             }
     331              :             else
     332              :             {
     333            7 :                 result |= utf8stream_writer_write_str( out_writer, "00" );
     334              :             }
     335              :         }
     336              :         else
     337              :         {
     338            2 :             if ( 1000 > (*this_).row_id )
     339              :             {
     340            1 :                 result |= utf8stream_writer_write_str( out_writer, "0" );
     341              :             }
     342              :             else
     343              :             {
     344              :                 /* row_id is greater than 1000 */
     345              :             }
     346              :         }
     347           11 :         result |= utf8stream_writer_write_int( out_writer, (*this_).row_id );
     348              :     }
     349              : 
     350           12 :     return result;
     351              : }
     352              : 
     353              : 
     354              : /*
     355              : Copyright 2016-2025 Andreas Warnke
     356              : 
     357              : Licensed under the Apache License, Version 2.0 (the "License");
     358              : you may not use this file except in compliance with the License.
     359              : You may obtain a copy of the License at
     360              : 
     361              :     http://www.apache.org/licenses/LICENSE-2.0
     362              : 
     363              : Unless required by applicable law or agreed to in writing, software
     364              : distributed under the License is distributed on an "AS IS" BASIS,
     365              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     366              : See the License for the specific language governing permissions and
     367              : limitations under the License.
     368              : */
        

Generated by: LCOV version 2.0-1