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.67.0_covts Lines: 99.1 % 107 106
Test Date: 2025-11-06 17:22:08 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           42 : 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           42 :     assert( NULL != db_reader );
      10           42 :     assert( NULL != db_writer );
      11              : 
      12           42 :     (*this_).db_reader = db_reader;
      13           42 :     (*this_).db_writer = db_writer;
      14              : 
      15           42 :     const data_revision_t revision = data_database_reader_get_revision( (*this_).db_reader );
      16           42 :     ctrl_undo_redo_entry_init_boundary( &((*this_).buffer[0]), revision );
      17           42 :     (*this_).start = 0;
      18           42 :     (*this_).length = 1;
      19           42 :     (*this_).current = 1;
      20           42 :     (*this_).buffer_incomplete = false;
      21           42 : }
      22              : 
      23           42 : static inline void ctrl_undo_redo_list_destroy ( ctrl_undo_redo_list_t *this_ )
      24              : {
      25           42 :     ctrl_undo_redo_list_clear( this_ );
      26           42 :     (*this_).db_reader = NULL;
      27           42 :     (*this_).db_writer = NULL;
      28           42 : }
      29              : 
      30           51 : static inline void ctrl_undo_redo_list_clear ( ctrl_undo_redo_list_t *this_ )
      31              : {
      32           51 :     assert( (*this_).start < CTRL_UNDO_REDO_LIST_MAX_SIZE );
      33           51 :     assert( (*this_).length <= CTRL_UNDO_REDO_LIST_MAX_SIZE );
      34           51 :     assert( (*this_).current <= (*this_).length );
      35              : 
      36              :     /* call destructors of elements: */
      37          427 :     for ( uint32_t pos = 0; pos < (*this_).length; pos ++ )
      38              :     {
      39          376 :         uint32_t index = ((*this_).start + pos) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
      40          376 :         ctrl_undo_redo_entry_destroy( &((*this_).buffer[index]) );
      41              :     }
      42              : 
      43              :     /* reset: */
      44           51 :     const data_revision_t revision = data_database_reader_get_revision( (*this_).db_reader );
      45           51 :     ctrl_undo_redo_entry_init_boundary( &((*this_).buffer[0]), revision );
      46           51 :     (*this_).start = 0;
      47           51 :     (*this_).length = 1;
      48           51 :     (*this_).current = 1;
      49           51 :     (*this_).buffer_incomplete = false;
      50           51 : }
      51              : 
      52          341 : static inline u8_error_t ctrl_undo_redo_list_add_boundary ( ctrl_undo_redo_list_t *this_ )
      53              : {
      54          341 :     u8_error_t result = U8_ERROR_NONE;
      55              : 
      56              :     /* add and re-initialize the list entry */
      57          341 :     const data_revision_t revision = data_database_reader_get_revision( (*this_).db_reader );
      58          341 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      59          341 :     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          341 :     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          341 :     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            9 : 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            9 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      83            9 :     ctrl_undo_redo_entry_init_update_diagram( list_entry, old_value, new_value );
      84            9 : }
      85              : 
      86          162 : 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          162 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      90          162 :     ctrl_undo_redo_entry_init_create_diagram( list_entry, new_value );
      91          162 : }
      92              : 
      93              : /* ================================ DIAGRAMELEMENT ================================ */
      94              : 
      95            5 : 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            5 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
      99            5 :     ctrl_undo_redo_entry_init_delete_diagramelement( list_entry, old_value );
     100            5 : }
     101              : 
     102           22 : 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           22 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     106           22 :     ctrl_undo_redo_entry_init_update_diagramelement( list_entry, old_value, new_value );
     107           22 : }
     108              : 
     109           33 : 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           33 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     113           33 :     ctrl_undo_redo_entry_init_create_diagramelement( list_entry, new_value );
     114           33 : }
     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           26 : 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           26 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     136           26 :     ctrl_undo_redo_entry_init_create_classifier( list_entry, new_value );
     137           26 : }
     138              : 
     139              : /* ================================ FEATURE ================================ */
     140              : 
     141            9 : 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            9 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     145            9 :     ctrl_undo_redo_entry_init_delete_feature( list_entry, old_value );
     146            9 : }
     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           32 : 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           32 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     159           32 :     ctrl_undo_redo_entry_init_create_feature( list_entry, new_value );
     160           32 : }
     161              : 
     162              : /* ================================ RELATIONSHIP ================================ */
     163              : 
     164            5 : 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            5 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     168            5 :     ctrl_undo_redo_entry_init_delete_relationship( list_entry, old_value );
     169            5 : }
     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           13 : 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           13 :     ctrl_undo_redo_entry_t *const list_entry = ctrl_undo_redo_list_private_add_entry_ptr( this_ );
     182           13 :     ctrl_undo_redo_entry_init_create_relationship( list_entry, new_value );
     183           13 : }
     184              : 
     185              : /* ================================ private ================================ */
     186              : 
     187          487 : 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          487 :     assert( search_len <= CTRL_UNDO_REDO_LIST_MAX_SIZE );
     190              : 
     191          487 :     uint32_t result = 0;
     192        36186 :     for ( uint32_t pos = 0; pos < search_len; pos ++ )
     193              :     {
     194        35699 :         uint32_t index = (start_idx + pos) % CTRL_UNDO_REDO_LIST_MAX_SIZE;
     195        35699 :         if ( CTRL_UNDO_REDO_ENTRY_TYPE_BOUNDARY == ctrl_undo_redo_entry_get_action_type( &((*this_).buffer[index]) ) )
     196              :         {
     197        17707 :             result ++;
     198              :         }
     199              :     }
     200          487 :     return result;
     201              : }
     202              : 
     203              : 
     204              : /*
     205              : Copyright 2016-2025 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