LCOV - code coverage report
Current view: top level - ctrl/include - ctrl_undo_redo_iterator.inl (source / functions) Coverage Total Hit
Test: crystal-facet-uml_v1.70.5_covts Lines: 100.0 % 42 42
Test Date: 2026-05-28 21:31:40 Functions: 100.0 % 7 7

            Line data    Source code
       1              : /* File: ctrl_undo_redo_iterator.inl; Copyright and License: see below */
       2              : 
       3            4 : static inline void ctrl_undo_redo_iterator_init ( ctrl_undo_redo_iterator_t *this_,
       4              :                                                   const ctrl_undo_redo_entry_t (*ring_buf)[],
       5              :                                                   uint32_t ring_buf_size,
       6              :                                                   bool iterate_upwards,
       7              :                                                   uint32_t current,
       8              :                                                   uint32_t length )
       9              : {
      10            4 :     assert( ring_buf != NULL );
      11            4 :     assert( ring_buf_size > 0 );
      12            4 :     assert( current < ring_buf_size );
      13            4 :     assert( length <= ring_buf_size );
      14            4 :     (*this_).ring_buf = ring_buf;
      15            4 :     (*this_).ring_buf_size = ring_buf_size;
      16            4 :     (*this_).iterate_upwards = iterate_upwards;
      17            4 :     (*this_).current = current;
      18            4 :     (*this_).length = length;
      19            4 : }
      20              : 
      21            1 : static inline void ctrl_undo_redo_iterator_reinit ( ctrl_undo_redo_iterator_t *this_,
      22              :                                                     const ctrl_undo_redo_entry_t (*ring_buf)[],
      23              :                                                     uint32_t ring_buf_size,
      24              :                                                     bool iterate_upwards,
      25              :                                                     uint32_t current,
      26              :                                                     uint32_t length )
      27              : {
      28            1 :     ctrl_undo_redo_iterator_init( this_, ring_buf, ring_buf_size, iterate_upwards, current, length );
      29            1 : }
      30              : 
      31            1 : static inline void ctrl_undo_redo_iterator_init_empty ( ctrl_undo_redo_iterator_t *this_ )
      32              : {
      33            1 :     (*this_).ring_buf = NULL;
      34            1 :     (*this_).ring_buf_size = 1;
      35            1 :     (*this_).iterate_upwards = true;
      36            1 :     (*this_).current = 0;
      37            1 :     (*this_).length = 0;
      38            1 : }
      39              : 
      40            4 : static inline void ctrl_undo_redo_iterator_destroy ( ctrl_undo_redo_iterator_t *this_ )
      41              : {
      42            4 :     (*this_).ring_buf = NULL;
      43            4 : }
      44              : 
      45           14 : static inline bool ctrl_undo_redo_iterator_has_next ( const ctrl_undo_redo_iterator_t *this_ )
      46              : {
      47           14 :     return ( (*this_).length != 0 );
      48              : }
      49              : 
      50            9 : static inline const ctrl_undo_redo_entry_t * ctrl_undo_redo_iterator_next ( ctrl_undo_redo_iterator_t *this_ )
      51              : {
      52            9 :     assert( (*this_).length > 0 );
      53              : 
      54            9 :     const ctrl_undo_redo_entry_t * result = NULL;
      55            9 :     if ( (*this_).length > 0 )
      56              :     {
      57            9 :         result = &((*(*this_).ring_buf)[(*this_).current]);
      58            9 :         if ( (*this_).iterate_upwards )
      59              :         {
      60            3 :             (*this_).current = ( (*this_).current + 1 ) % (*this_).ring_buf_size;
      61              :         }
      62              :         else
      63              :         {
      64            6 :             (*this_).current = ( (*this_).current + (*this_).ring_buf_size - 1 ) % (*this_).ring_buf_size;
      65              :         }
      66            9 :         (*this_).length --;
      67              :     }
      68              : 
      69            9 :     return result;
      70              : }
      71              : 
      72            1 : static inline void ctrl_undo_redo_iterator_collect_statistics ( ctrl_undo_redo_iterator_t *this_,
      73              :                                                                 bool undo,
      74              :                                                                 data_stat_t *io_stat )
      75              : {
      76            1 :     assert( io_stat != NULL );
      77            4 :     while ( ctrl_undo_redo_iterator_has_next( this_ ) )
      78              :     {
      79            3 :         const ctrl_undo_redo_entry_t *const current_entry = ctrl_undo_redo_iterator_next( this_ );
      80            3 :         ctrl_undo_redo_entry_to_statistics ( current_entry, undo /*=undo*/, false /*=err*/, io_stat );
      81              :     }
      82            1 : }
      83              : 
      84              : 
      85              : /*
      86              : Copyright 2024-2026 Andreas Warnke
      87              : 
      88              : Licensed under the Apache License, Version 2.0 (the "License");
      89              : you may not use this file except in compliance with the License.
      90              : You may obtain a copy of the License at
      91              : 
      92              :     http://www.apache.org/licenses/LICENSE-2.0
      93              : 
      94              : Unless required by applicable law or agreed to in writing, software
      95              : distributed under the License is distributed on an "AS IS" BASIS,
      96              : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      97              : See the License for the specific language governing permissions and
      98              : limitations under the License.
      99              : */
        

Generated by: LCOV version 2.0-1