differential code coverage report with master
Current view: top level - source/worksheet - cell_iterator.cpp (source / functions) Coverage Total Hit UBC CBC
Current: coverage.info Lines: 93.2 % 118 110 8 110
Current Date: 2025-12-07 02:01:22 Functions: 94.7 % 19 18 1 18
Baseline: coverage_master.info Branches: 71.0 % 210 149 122 298
Baseline Date: 2025-12-07 02:01:21

             Branch data    TLA  Line data    Source code
       1                 :                : // Copyright (c) 2014-2022 Thomas Fussell
       2                 :                : // Copyright (c) 2024-2025 xlnt-community
       3                 :                : //
       4                 :                : // Permission is hereby granted, free of charge, to any person obtaining a copy
       5                 :                : // of this software and associated documentation files (the "Software"), to deal
       6                 :                : // in the Software without restriction, including without limitation the rights
       7                 :                : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8                 :                : // copies of the Software, and to permit persons to whom the Software is
       9                 :                : // furnished to do so, subject to the following conditions:
      10                 :                : //
      11                 :                : // The above copyright notice and this permission notice shall be included in
      12                 :                : // all copies or substantial portions of the Software.
      13                 :                : //
      14                 :                : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15                 :                : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16                 :                : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17                 :                : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18                 :                : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19                 :                : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20                 :                : // THE SOFTWARE
      21                 :                : //
      22                 :                : // @license: http://www.opensource.org/licenses/mit-license.php
      23                 :                : // @author: see AUTHORS file
      24                 :                : 
      25                 :                : #include <xlnt/cell/cell.hpp>
      26                 :                : #include <xlnt/cell/cell_reference.hpp>
      27                 :                : #include <xlnt/worksheet/cell_iterator.hpp>
      28                 :                : #include <xlnt/worksheet/major_order.hpp>
      29                 :                : 
      30                 :                : namespace xlnt {
      31                 :                : 
      32                 :CBC         434 : cell_iterator::cell_iterator(worksheet ws, const cell_reference &cursor,
      33                 :            434 :     const range_reference &bounds, major_order order, bool skip_null, bool wrap)
      34                 :            434 :     : skip_null_(skip_null),
      35                 :            434 :       wrap_(wrap),
      36                 :            434 :       order_(order),
      37                 :            434 :       ws_(ws),
      38                 :            434 :       cursor_(cursor),
      39                 :            434 :       bounds_(bounds)
      40                 :                : {
      41   [ +  +  +  +  :            434 :     if (skip_null && !ws.has_cell(cursor_))
                   +  + ]
      42                 :                :     {
      43            [ + ]:            148 :         (*this)++; // move to the next non-empty cell or one past the end if none exists
      44                 :                :     }
      45                 :            434 : }
      46                 :                : 
      47                 :            568 : const_cell_iterator::const_cell_iterator(worksheet ws, const cell_reference &cursor,
      48                 :            568 :     const range_reference &bounds, major_order order, bool skip_null, bool wrap)
      49                 :            568 :     : skip_null_(skip_null),
      50                 :            568 :       wrap_(wrap),
      51                 :            568 :       order_(order),
      52                 :            568 :       ws_(ws),
      53                 :            568 :       cursor_(cursor),
      54                 :            568 :       bounds_(bounds)
      55                 :                : {
      56   [ +  +  +  +  :            568 :     if (skip_null && !ws.has_cell(cursor_))
                   +  + ]
      57                 :                :     {
      58            [ + ]:            426 :         (*this)++; // move to the next non-empty cell or one past the end if none exists
      59                 :                :     }
      60                 :            568 : }
      61                 :                : 
      62                 :           1495 : bool cell_iterator::operator==(const cell_iterator &other) const
      63                 :                : {
      64                 :           1495 :     return ws_ == other.ws_
      65         [ +  + ]:           1495 :         && cursor_ == other.cursor_
      66         [ +  - ]:            205 :         && bounds_ == other.bounds_
      67         [ +  - ]:            205 :         && order_ == other.order_
      68         [ +  - ]:            205 :         && skip_null_ == other.skip_null_
      69   [ +  -  +  - ]:           2990 :         && wrap_ == other.wrap_;
      70                 :                : }
      71                 :                : 
      72                 :            297 : bool const_cell_iterator::operator==(const const_cell_iterator &other) const
      73                 :                : {
      74                 :            297 :     return ws_ == other.ws_
      75         [ +  + ]:            297 :         && cursor_ == other.cursor_
      76         [ +  - ]:            121 :         && bounds_ == other.bounds_
      77         [ +  - ]:            121 :         && order_ == other.order_
      78         [ +  - ]:            121 :         && skip_null_ == other.skip_null_
      79   [ +  -  +  - ]:            594 :         && wrap_ == other.wrap_;
      80                 :                : }
      81                 :                : 
      82                 :           1485 : bool cell_iterator::operator!=(const cell_iterator &other) const
      83                 :                : {
      84                 :           1485 :     return !(*this == other);
      85                 :                : }
      86                 :                : 
      87                 :             17 : bool const_cell_iterator::operator!=(const const_cell_iterator &other) const
      88                 :                : {
      89                 :             17 :     return !(*this == other);
      90                 :                : }
      91                 :                : 
      92                 :             26 : cell_iterator &cell_iterator::operator--()
      93                 :                : {
      94         [ +  + ]:             26 :     if (order_ == major_order::row)
      95                 :                :     {
      96   [ +  +  +  +  :              4 :         if (cursor_.column() > bounds_.top_left().column())
                   +  - ]
      97                 :                :         {
      98      [ +  +  + ]:              4 :             cursor_.column_index(cursor_.column_index() - 1);
      99                 :                :         }
     100                 :                : 
     101         [ -  + ]:              4 :         if (skip_null_)
     102                 :                :         {
     103   [ #  #  #  #  :UBC           0 :             while (!ws_.has_cell(cursor_) && cursor_.column() > bounds_.top_left().column())
          #  #  #  #  #  
                   #  # ]
     104                 :                :             {
     105      [ #  #  # ]:              0 :                 cursor_.column_index(cursor_.column_index() - 1);
     106                 :                :             }
     107                 :                :         }
     108                 :                :     }
     109                 :                :     else
     110                 :                :     {
     111   [ +  +  +  - ]:CBC          22 :         if (cursor_.row() > bounds_.top_left().row())
     112                 :                :         {
     113                 :             22 :             cursor_.row(cursor_.row() - 1);
     114                 :                :         }
     115                 :                : 
     116         [ +  + ]:             22 :         if (skip_null_)
     117                 :                :         {
     118   [ +  -  +  -  :             20 :             while (!ws_.has_cell(cursor_) && cursor_.row() > bounds_.top_left().row())
          -  -  -  -  -  
                      + ]
     119                 :                :             {
     120                 :UBC           0 :                 cursor_.row(cursor_.row() - 1);
     121                 :                :             }
     122                 :                :         }
     123                 :                :     }
     124                 :                : 
     125                 :CBC          26 :     return *this;
     126                 :                : }
     127                 :                : 
     128                 :             34 : const_cell_iterator &const_cell_iterator::operator--()
     129                 :                : {
     130         [ +  + ]:             34 :     if (order_ == major_order::row)
     131                 :                :     {
     132   [ +  +  +  +  :             15 :         if (cursor_.column() > bounds_.top_left().column())
                   +  - ]
     133                 :                :         {
     134      [ +  +  + ]:             15 :             cursor_.column_index(cursor_.column_index() - 1);
     135                 :                :         }
     136                 :                : 
     137         [ +  - ]:             15 :         if (skip_null_)
     138                 :                :         {
     139   [ +  -  +  -  :             15 :             while (!ws_.has_cell(cursor_) && cursor_.column() > bounds_.top_left().column())
          -  -  -  -  -  
                   -  + ]
     140                 :                :             {
     141      [ #  #  # ]:UBC           0 :                 cursor_.column_index(cursor_.column_index() - 1);
     142                 :                :             }
     143                 :                :         }
     144                 :                :     }
     145                 :                :     else
     146                 :                :     {
     147   [ +  +  +  - ]:CBC          19 :         if (cursor_.row() > bounds_.top_left().row())
     148                 :                :         {
     149                 :             19 :             cursor_.row(cursor_.row() - 1);
     150                 :                :         }
     151                 :                : 
     152         [ +  - ]:             19 :         if (skip_null_)
     153                 :                :         {
     154   [ +  -  +  -  :             19 :             while (!ws_.has_cell(cursor_) && cursor_.row() > bounds_.top_left().row())
          -  -  -  -  -  
                      + ]
     155                 :                :             {
     156                 :UBC           0 :                 cursor_.row(cursor_.row() - 1);
     157                 :                :             }
     158                 :                :         }
     159                 :                :     }
     160                 :                : 
     161                 :CBC          34 :     return *this;
     162                 :                : }
     163                 :                : 
     164                 :              3 : cell_iterator cell_iterator::operator--(int)
     165                 :                : {
     166                 :              3 :     cell_iterator old = *this;
     167                 :              3 :     --*this;
     168                 :                : 
     169                 :              3 :     return old;
     170                 :                : }
     171                 :                : 
     172                 :              2 : const_cell_iterator const_cell_iterator::operator--(int)
     173                 :                : {
     174                 :              2 :     const_cell_iterator old = *this;
     175                 :              2 :     --*this;
     176                 :                : 
     177                 :              2 :     return old;
     178                 :                : }
     179                 :                : 
     180                 :           1436 : cell_iterator &cell_iterator::operator++()
     181                 :                : {
     182         [ +  + ]:           1436 :     if (order_ == major_order::row)
     183                 :                :     {
     184   [ +  +  +  +  :           1418 :         if (cursor_.column() <= bounds_.bottom_right().column())
                   +  + ]
     185                 :                :         {
     186      [ +  +  + ]:           1319 :             cursor_.column_index(cursor_.column_index() + 1);
     187                 :                :         }
     188                 :                : 
     189         [ +  + ]:           1418 :         if (skip_null_)
     190                 :                :         {
     191   [ +  +  +  +  :            942 :             while (!ws_.has_cell(cursor_) && cursor_.column() <= bounds_.bottom_right().column())
          +  +  +  +  +  
                   +  + ]
     192                 :                :             {
     193      [ +  +  + ]:            344 :                 cursor_.column_index(cursor_.column_index() + 1);
     194                 :                :             }
     195                 :                :         }
     196                 :                :     }
     197                 :                :     else
     198                 :                :     {
     199   [ +  +  +  + ]:             18 :         if (cursor_.row() <= bounds_.bottom_right().row())
     200                 :                :         {
     201                 :              9 :             cursor_.row(cursor_.row() + 1);
     202                 :                :         }
     203                 :                : 
     204         [ +  - ]:             18 :         if (skip_null_)
     205                 :                :         {
     206   [ +  +  +  +  :             18 :             while (!ws_.has_cell(cursor_) && cursor_.row() <= bounds_.bottom_right().row())
          +  +  -  +  -  
                      + ]
     207                 :                :             {
     208                 :UBC           0 :                 cursor_.row(cursor_.row() + 1);
     209                 :                :             }
     210                 :                :         }
     211                 :                :     }
     212                 :                : 
     213                 :CBC        1436 :     return *this;
     214                 :                : }
     215                 :                : 
     216                 :            442 : const_cell_iterator &const_cell_iterator::operator++()
     217                 :                : {
     218         [ +  + ]:            442 :     if (order_ == major_order::row)
     219                 :                :     {
     220   [ +  +  +  +  :            351 :         if (cursor_.column() <= bounds_.bottom_right().column())
                   +  + ]
     221                 :                :         {
     222      [ +  +  + ]:            139 :             cursor_.column_index(cursor_.column_index() + 1);
     223                 :                :         }
     224                 :                : 
     225         [ +  - ]:            351 :         if (skip_null_)
     226                 :                :         {
     227   [ +  +  +  +  :           1035 :             while (!ws_.has_cell(cursor_) && cursor_.column() <= bounds_.bottom_right().column())
          +  +  +  +  +  
                   +  + ]
     228                 :                :             {
     229      [ +  +  + ]:            684 :                 cursor_.column_index(cursor_.column_index() + 1);
     230                 :                :             }
     231                 :                :         }
     232                 :                :     }
     233                 :                :     else
     234                 :                :     {
     235   [ +  +  +  + ]:             91 :         if (cursor_.row() <= bounds_.bottom_right().row())
     236                 :                :         {
     237                 :             27 :             cursor_.row(cursor_.row() + 1);
     238                 :                :         }
     239                 :                : 
     240         [ +  - ]:             91 :         if (skip_null_)
     241                 :                :         {
     242   [ +  +  +  +  :            109 :             while (!ws_.has_cell(cursor_) && cursor_.row() <= bounds_.bottom_right().row())
          +  +  +  +  +  
                      + ]
     243                 :                :             {
     244                 :             18 :                 cursor_.row(cursor_.row() + 1);
     245                 :                :             }
     246                 :                :         }
     247                 :                :     }
     248                 :                : 
     249                 :            442 :     return *this;
     250                 :                : }
     251                 :                : 
     252                 :            150 : cell_iterator cell_iterator::operator++(int)
     253                 :                : {
     254                 :            150 :     cell_iterator old = *this;
     255                 :            150 :     ++*this;
     256                 :                : 
     257                 :            150 :     return old;
     258                 :                : }
     259                 :                : 
     260                 :            427 : const_cell_iterator const_cell_iterator::operator++(int)
     261                 :                : {
     262                 :            427 :     const_cell_iterator old = *this;
     263                 :            427 :     ++*this;
     264                 :                : 
     265                 :            427 :     return old;
     266                 :                : }
     267                 :                : 
     268                 :           1316 : cell_iterator::reference cell_iterator::operator*()
     269                 :                : {
     270                 :           1316 :     return ws_.cell(cursor_);
     271                 :                : }
     272                 :                : 
     273                 :UBC           0 : const cell_iterator::reference cell_iterator::operator*() const
     274                 :                : {
     275                 :              0 :     return ws_.cell(cursor_);
     276                 :                : }
     277                 :                : 
     278                 :CBC          36 : const const_cell_iterator::reference const_cell_iterator::operator*() const
     279                 :                : {
     280                 :             36 :     return ws_.cell(cursor_);
     281                 :                : }
     282                 :                : 
     283                 :              4 : bool cell_iterator::has_value() const{
     284                 :              4 :     return ws_.has_cell(cursor_);
     285                 :                : }
     286                 :                : 
     287                 :              4 : bool const_cell_iterator::has_value() const{
     288                 :              4 :     return ws_.has_cell(cursor_);
     289                 :                : }
     290                 :                : } // namespace xlnt
        

Generated by: LCOV version 2.3.1-beta