LCOV - code coverage report
Current view: top level - ctrl/include - ctrl_undo_redo_list.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.70.2_covts Lines: 99.1 % 107 106
Test Date: 2026-05-03 11:56:31 Functions: 100.0 % 20 20

            Line data    Source code
       1              : /* File: ctrl_undo_redo_list.inl; Copyright and License: see below */
       2              : 
       3              : #include "u8/u8_trace.h"
       4              : #include "u8/u8_log.h"
       5              : #include <assert.h>
       6              : 
       7           47 : static inline void ctrl_undo_redo_list_init ( ctrl_undo_redo_list_t *this_, data_database_reader_t *db_reader, data_database_writer_t *db_writer )
       8              : {
       9           47 :     assert( NULL != db_reader );
      10           47 :     assert( NULL != db_writer );
      11              : 
      12           47 :     (*this_).db_reader = db_reader;
      13           47 :     (*this_).db_writer = db_writer;
      14              : 
      15           47 :     const data_revision_t revision = data_database_reader_get_revision( (*this_).db_reader );
      16           47 :     ctrl_undo_redo_entry_init_boundary( &((*this_).buffer[0]), revision );
      17           47 :     (*this_).start = 0;
      18           47 :     (*this_).length = 1;
      19           47 :     (*this_).current = 1;
      20           47 :     (*this_).buffer_incomplete = false;
      21           47 : }
      22              : 
      23           47 : static inline void ctrl_undo_redo_list_destroy ( ctrl_undo_redo_list_t *this_ )
      24              : {
      25           47 :     ctrl_undo_redo_list_clear( this_ );
      26           47 :     (*this_).db_reader = NULL;
      27           47 :     (*this_).db_writer = NULL;
      28           47 : }
      29              : 
      30           57 : static inline void ctrl_undo_redo_list_clear ( ctrl_undo_redo_list_t *this_ )
      31              : {
      32           57 :     assert( (*this_).start < CTRL_UNDO_REDO_LIST_MAX_SIZE );
      33           57 :     assert( (*this_).length <= CTRL_UNDO_REDO_LIST_MAX_SIZE );
      34           57 :     assert( (*this_).current <= (*this_).length );
      35              : 
      36              :     /* call destructors of elements: */
      37          613 :     for ( uint32_t pos = 0; pos < (*this_).length; pos ++ )
      38              :     {
      39          556 :         uint32_t index = ((*this_).start + pos) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
      40          556 :         ctrl_undo_redo_entry_destroy( &((*this_).buffer[index]) );
      41              :     }
      42              : 
      43              :     /* reset: */
      44           57 :     const data_revision_t revision = data_database_reader_get_revision( (*this_).db_reader );
      45           57 :     ctrl_undo_redo_entry_init_boundary( &((*this_).buffer[0]), revision );
      46           57 :     (*this_).start = 0;
      47           57 :     (*this_).length = 1;
      48           57 :     (*this_).current = 1;
      49           57 :     (*this_).buffer_incomplete = false;
      50           57 : }
      51              : 
      52          437 : static inline u8_error_t ctrl_undo_redo_list_add_boundary ( ctrl_undo_redo_list_t *this_ )
      53              : {
      54          437 :     u8_error_t result = U8_ERROR_NONE;
      55              : 
      56              :     /* add and re-initialize the list entry */
      57          437 :     const data_revision_t revision = data_database_reader_get_revision( (*this_).db_reader );
      58          437 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      59          437 :     ctrl_undo_redo_entry_init_boundary( list_entry, revision );
      60              : 
      61              :     /* check if >=1 complete set of transactions is still in the undo-redo-list */
      62          437 :     if ( 1 == ctrl_undo_redo_list_private_count_boundaries( this_, (*this_).start, (*this_).length ) )
      63              :     {
      64            0 :         result = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
      65              :     }
      66              : 
      67          437 :     return result;
      68              : }
      69              : 
      70              : /* ================================ DIAGRAM ================================ */
      71              : 
      72            2 : static inline void ctrl_undo_redo_list_add_delete_diagram ( ctrl_undo_redo_list_t *this_, const data_diagram_t *old_value )
      73              : {
      74              :     /* add and re-initialize the list entry */
      75            2 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      76            2 :     ctrl_undo_redo_entry_init_delete_diagram( list_entry, old_value );
      77            2 : }
      78              : 
      79           13 : static inline void ctrl_undo_redo_list_add_update_diagram ( ctrl_undo_redo_list_t *this_, const data_diagram_t *old_value, const data_diagram_t *new_value )
      80              : {
      81              :     /* add and re-initialize the list entry */
      82           13 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      83           13 :     ctrl_undo_redo_entry_init_update_diagram( list_entry, old_value, new_value );
      84           13 : }
      85              : 
      86          184 : static inline void ctrl_undo_redo_list_add_create_diagram ( ctrl_undo_redo_list_t *this_, const data_diagram_t *new_value )
      87              : {
      88              :     /* add and re-initialize the list entry */
      89          184 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      90          184 :     ctrl_undo_redo_entry_init_create_diagram( list_entry, new_value );
      91          184 : }
      92              : 
      93              : /* ================================ DIAGRAMELEMENT ================================ */
      94              : 
      95            9 : static inline void ctrl_undo_redo_list_add_delete_diagramelement ( ctrl_undo_redo_list_t *this_, data_diagramelement_t *old_value )
      96              : {
      97              :     /* add and re-initialize the list entry */
      98            9 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      99            9 :     ctrl_undo_redo_entry_init_delete_diagramelement( list_entry, old_value );
     100            9 : }
     101              : 
     102           23 : static inline void ctrl_undo_redo_list_add_update_diagramelement ( ctrl_undo_redo_list_t *this_, data_diagramelement_t *old_value, data_diagramelement_t *new_value )
     103              : {
     104              :     /* add and re-initialize the list entry */
     105           23 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     106           23 :     ctrl_undo_redo_entry_init_update_diagramelement( list_entry, old_value, new_value );
     107           23 : }
     108              : 
     109           62 : static inline void ctrl_undo_redo_list_add_create_diagramelement ( ctrl_undo_redo_list_t *this_, data_diagramelement_t *new_value )
     110              : {
     111              :     /* add and re-initialize the list entry */
     112           62 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     113           62 :     ctrl_undo_redo_entry_init_create_diagramelement( list_entry, new_value );
     114           62 : }
     115              : 
     116              : /* ================================ CLASSIFIER ================================ */
     117              : 
     118            3 : static inline void ctrl_undo_redo_list_add_delete_classifier ( ctrl_undo_redo_list_t *this_, data_classifier_t *old_value )
     119              : {
     120              :     /* add and re-initialize the list entry */
     121            3 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     122            3 :     ctrl_undo_redo_entry_init_delete_classifier( list_entry, old_value );
     123            3 : }
     124              : 
     125            7 : static inline void ctrl_undo_redo_list_add_update_classifier ( ctrl_undo_redo_list_t *this_, data_classifier_t *old_value, data_classifier_t *new_value )
     126              : {
     127              :     /* add and re-initialize the list entry */
     128            7 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     129            7 :     ctrl_undo_redo_entry_init_update_classifier( list_entry, old_value, new_value );
     130            7 : }
     131              : 
     132           40 : static inline void ctrl_undo_redo_list_add_create_classifier ( ctrl_undo_redo_list_t *this_, data_classifier_t *new_value )
     133              : {
     134              :     /* add and re-initialize the list entry */
     135           40 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     136           40 :     ctrl_undo_redo_entry_init_create_classifier( list_entry, new_value );
     137           40 : }
     138              : 
     139              : /* ================================ FEATURE ================================ */
     140              : 
     141           15 : static inline void ctrl_undo_redo_list_add_delete_feature ( ctrl_undo_redo_list_t *this_, data_feature_t *old_value )
     142              : {
     143              :     /* add and re-initialize the list entry */
     144           15 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     145           15 :     ctrl_undo_redo_entry_init_delete_feature( list_entry, old_value );
     146           15 : }
     147              : 
     148            7 : static inline void ctrl_undo_redo_list_add_update_feature ( ctrl_undo_redo_list_t *this_, data_feature_t *old_value, data_feature_t *new_value )
     149              : {
     150              :     /* add and re-initialize the list entry */
     151            7 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     152            7 :     ctrl_undo_redo_entry_init_update_feature( list_entry, old_value, new_value );
     153            7 : }
     154              : 
     155           39 : static inline void ctrl_undo_redo_list_add_create_feature ( ctrl_undo_redo_list_t *this_, data_feature_t *new_value )
     156              : {
     157              :     /* add and re-initialize the list entry */
     158           39 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     159           39 :     ctrl_undo_redo_entry_init_create_feature( list_entry, new_value );
     160           39 : }
     161              : 
     162              : /* ================================ RELATIONSHIP ================================ */
     163              : 
     164            8 : static inline void ctrl_undo_redo_list_add_delete_relationship ( ctrl_undo_redo_list_t *this_, data_relationship_t *old_value )
     165              : {
     166              :     /* add and re-initialize the list entry */
     167            8 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     168            8 :     ctrl_undo_redo_entry_init_delete_relationship( list_entry, old_value );
     169            8 : }
     170              : 
     171            6 : static inline void ctrl_undo_redo_list_add_update_relationship ( ctrl_undo_redo_list_t *this_, data_relationship_t *old_value, data_relationship_t *new_value )
     172              : {
     173              :     /* add and re-initialize the list entry */
     174            6 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     175            6 :     ctrl_undo_redo_entry_init_update_relationship( list_entry, old_value, new_value );
     176            6 : }
     177              : 
     178           19 : static inline void ctrl_undo_redo_list_add_create_relationship ( ctrl_undo_redo_list_t *this_, data_relationship_t *new_value )
     179              : {
     180              :     /* add and re-initialize the list entry */
     181           19 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     182           19 :     ctrl_undo_redo_entry_init_create_relationship( list_entry, new_value );
     183           19 : }
     184              : 
     185              : /* ================================ private ================================ */
     186              : 
     187          583 : static inline uint32_t ctrl_undo_redo_list_private_count_boundaries ( ctrl_undo_redo_list_t *this_, uint32_t start_idx, uint32_t search_len )
     188              : {
     189          583 :     assert( search_len <= CTRL_UNDO_REDO_LIST_MAX_SIZE );
     190              : 
     191          583 :     uint32_t result = 0;
     192        38030 :     for ( uint32_t pos = 0; pos < search_len; pos ++ )
     193              :     {
     194        37447 :         uint32_t index = (start_idx + pos) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
     195        37447 :         if ( CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY == ctrl_undo_redo_entry_get_action_type( &((*this_).buffer[index]) ) )
     196              :         {
     197        18603 :             result ++;
     198              :         }
     199              :     }
     200          583 :     return result;
     201              : }
     202              : 
     203              : 
     204              : /*
     205              : Copyright 2016-2026 Andreas Warnke
     206              : 
     207              : Licensed under the Apache License, Version 2.0 (the "License");
     208              : you may not use this file except in compliance with the License.
     209              : You may obtain a copy of the License at
     210              : 
     211              :     http://www.apache.org/licenses/LICENSE-2.0
     212              : 
     213              : Unless required by applicable law or agreed to in writing, software
     214              : distributed under the License is distributed on an "AS IS" BASIS,
     215              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     216              : See the License for the specific language governing permissions and
     217              : limitations under the License.
     218              : */
        

Generated by: LCOV version 2.0-1