differential code coverage report with master
Current view: top level - source/styles - format.cpp (source / functions) Coverage Total Hit UBC CBC
Current: coverage.info Lines: 85.2 % 108 92 16 92
Current Date: 2025-12-15 23:01:28 Functions: 84.8 % 33 28 5 28
Baseline: coverage_master.info Branches: 75.4 % 57 43 28 86
Baseline Date: 2025-12-15 23:01:27

             Branch data    TLA  Line data    Source code
       1                 :                : // Copyright (c) 2014-2022 Thomas Fussell
       2                 :                : // Copyright (c) 2010-2015 openpyxl
       3                 :                : // Copyright (c) 2024-2025 xlnt-community
       4                 :                : //
       5                 :                : // Permission is hereby granted, free of charge, to any person obtaining a copy
       6                 :                : // of this software and associated documentation files (the "Software"), to deal
       7                 :                : // in the Software without restriction, including without limitation the rights
       8                 :                : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9                 :                : // copies of the Software, and to permit persons to whom the Software is
      10                 :                : // furnished to do so, subject to the following conditions:
      11                 :                : //
      12                 :                : // The above copyright notice and this permission notice shall be included in
      13                 :                : // all copies or substantial portions of the Software.
      14                 :                : //
      15                 :                : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16                 :                : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17                 :                : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18                 :                : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19                 :                : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20                 :                : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21                 :                : // THE SOFTWARE
      22                 :                : //
      23                 :                : // @license: http://www.opensource.org/licenses/mit-license.php
      24                 :                : // @author: see AUTHORS file
      25                 :                : 
      26                 :                : // detail imports must come first in this file.
      27                 :                : #include <detail/implementations/format_impl.hpp>
      28                 :                : #include <detail/implementations/stylesheet.hpp>
      29                 :                : 
      30                 :                : #include <xlnt/styles/format.hpp>
      31                 :                : #include <xlnt/styles/style.hpp>
      32                 :                : 
      33                 :                : namespace xlnt {
      34                 :                : 
      35                 :CBC        1598 : format::format(detail::format_impl_ptr d)
      36                 :           1598 :     : d_(std::move(d))
      37                 :                : {
      38                 :           1598 : }
      39                 :                : 
      40                 :              2 : void format::clear_style()
      41                 :                : {
      42                 :              2 :     d_->style.clear();
      43                 :              2 : }
      44                 :                : 
      45                 :              5 : format& format::style(const xlnt::style &new_style)
      46                 :                : {
      47      [ +  +  + ]:              5 :     d_ = d_->parent->find_or_create_with(d_, new_style.name());
      48                 :              5 :     return *this;
      49                 :                : }
      50                 :                : 
      51                 :            257 : format& format::style(const std::string &new_style)
      52                 :                : {
      53                 :            257 :     d_->style = new_style;
      54                 :            257 :     return *this;
      55                 :                : }
      56                 :                : 
      57                 :             17 : bool format::has_style() const
      58                 :                : {
      59                 :             17 :     return d_->style.is_set();
      60                 :                : }
      61                 :                : 
      62                 :              6 : style format::style()
      63                 :                : {
      64         [ -  + ]:              6 :     if (!has_style())
      65                 :                :     {
      66            [ # ]:UBC           0 :         throw invalid_attribute();
      67                 :                :     }
      68                 :                : 
      69                 :CBC           6 :     return d_->parent->style(d_->style.get());
      70                 :                : }
      71                 :                : 
      72                 :UBC           0 : const style format::style() const
      73                 :                : {
      74         [ #  # ]:              0 :     if (!has_style())
      75                 :                :     {
      76            [ # ]:              0 :         throw invalid_attribute();
      77                 :                :     }
      78                 :                : 
      79                 :              0 :     return d_->parent->style(d_->style.get());
      80                 :                : }
      81                 :                : 
      82                 :CBC           1 : xlnt::alignment format::alignment() const
      83                 :                : {
      84                 :              1 :     return d_->parent->alignments.at(d_->alignment_id.get());
      85                 :                : }
      86                 :                : 
      87                 :              1 : format& format::alignment(const xlnt::alignment &new_alignment, optional<bool> applied)
      88                 :                : {
      89         [ +  + ]:              1 :     d_ = d_->parent->find_or_create_with(d_, new_alignment, applied);
      90                 :              1 :     return *this;
      91                 :                : }
      92                 :                : 
      93                 :              1 : xlnt::border format::border() const
      94                 :                : {
      95                 :              1 :     return d_->parent->borders.at(d_->border_id.get());
      96                 :                : }
      97                 :                : 
      98                 :            262 : format& format::border(const xlnt::border &new_border, optional<bool> applied)
      99                 :                : {
     100         [ +  + ]:            262 :     d_ = d_->parent->find_or_create_with(d_, new_border, applied);
     101                 :            262 :     return *this;
     102                 :                : }
     103                 :                : 
     104                 :              5 : xlnt::fill format::fill() const
     105                 :                : {
     106                 :              5 :     return d_->parent->fills.at(d_->fill_id.get());
     107                 :                : }
     108                 :                : 
     109                 :            274 : format& format::fill(const xlnt::fill &new_fill, optional<bool> applied)
     110                 :                : {
     111         [ +  + ]:            274 :     d_ = d_->parent->find_or_create_with(d_, new_fill, applied);
     112                 :            274 :     return *this;
     113                 :                : }
     114                 :                : 
     115                 :              7 : xlnt::font format::font() const
     116                 :                : {
     117                 :              7 :     return d_->parent->fonts.at(d_->font_id.get());
     118                 :                : }
     119                 :                : 
     120                 :            286 : format& format::font(const xlnt::font &new_font, optional<bool> applied)
     121                 :                : {
     122         [ +  + ]:            286 :     d_ = d_->parent->find_or_create_with(d_, new_font, applied);
     123                 :            286 :     return *this;
     124                 :                : }
     125                 :                : 
     126                 :             17 : xlnt::number_format format::number_format() const
     127                 :                : {
     128         [ +  - ]:             17 :     if (d_->number_format_id.is_set())
     129                 :                :     {
     130            [ + ]:             17 :         const auto number_format_id = d_->number_format_id.get();
     131                 :                : 
     132      [ +  +  + ]:             17 :         if (number_format::is_builtin_format(number_format_id))
     133                 :                :         {
     134         [ +  + ]:             19 :             return number_format::from_builtin_id(number_format_id);
     135                 :                :         }
     136                 :                : 
     137            [ + ]:             15 :         const auto it = std::find_if(d_->parent->number_formats.begin(),
     138                 :             15 :                                      d_->parent->number_formats.end(),
     139                 :             34 :                                      [number_format_id](const xlnt::number_format &nf)
     140                 :                :                                      {
     141                 :             34 :                                          return nf.id() == number_format_id;
     142                 :                :                                      });
     143         [ +  - ]:             15 :         if (it != d_->parent->number_formats.end())
     144                 :                :         {
     145            [ + ]:             15 :             return *it;
     146                 :                :         }
     147                 :                :     }
     148                 :                : 
     149                 :UBC           0 :     return xlnt::number_format();
     150                 :                : }
     151                 :                : 
     152                 :CBC         282 : format& format::number_format(const xlnt::number_format &new_number_format, optional<bool> applied)
     153                 :                : {
     154         [ +  + ]:            282 :     d_ = d_->parent->find_or_create_with(d_, new_number_format, applied);
     155                 :            282 :     return *this;
     156                 :                : }
     157                 :                : 
     158                 :              1 : xlnt::protection format::protection() const
     159                 :                : {
     160                 :              1 :     return d_->parent->protections.at(d_->protection_id.get());
     161                 :                : }
     162                 :                : 
     163                 :              1 : format& format::protection(const xlnt::protection &new_protection, optional<bool> applied)
     164                 :                : {
     165         [ +  + ]:              1 :     d_ = d_->parent->find_or_create_with(d_, new_protection, applied);
     166                 :              1 :     return *this;
     167                 :                : }
     168                 :                : 
     169                 :              1 : bool format::alignment_applied() const
     170                 :                : {
     171                 :              1 :     return d_->alignment_applied.is_set()
     172         [ +  - ]:              1 :         ? d_->alignment_applied.get()
     173                 :              1 :         : d_->alignment_id.is_set();
     174                 :                : }
     175                 :                : 
     176                 :              1 : bool format::border_applied() const
     177                 :                : {
     178                 :              1 :     return d_->border_applied.is_set()
     179         [ +  - ]:              1 :         ? d_->border_applied.get()
     180                 :              1 :         : d_->border_id.is_set();
     181                 :                : }
     182                 :                : 
     183                 :              5 : bool format::fill_applied() const
     184                 :                : {
     185                 :              5 :     return d_->fill_applied.is_set()
     186         [ +  - ]:              5 :         ? d_->fill_applied.get()
     187                 :              5 :         : d_->fill_id.is_set();
     188                 :                : }
     189                 :                : 
     190                 :              1 : bool format::font_applied() const
     191                 :                : {
     192                 :              1 :     return d_->font_applied.is_set()
     193         [ +  - ]:              1 :         ? d_->font_applied.get()
     194                 :              1 :         : d_->font_id.is_set();
     195                 :                : }
     196                 :                : 
     197                 :              1 : bool format::number_format_applied() const
     198                 :                : {
     199                 :              1 :     return d_->number_format_applied.is_set()
     200         [ +  - ]:              1 :         ? d_->number_format_applied.get()
     201                 :              1 :         : d_->number_format_id.is_set();
     202                 :                : }
     203                 :                : 
     204                 :              1 : bool format::protection_applied() const
     205                 :                : {
     206                 :              1 :     return d_->protection_applied.is_set()
     207         [ +  - ]:              1 :         ? d_->protection_applied.get()
     208                 :              1 :         : d_->protection_id.is_set();
     209                 :                : }
     210                 :                : 
     211                 :UBC           0 : bool format::pivot_button() const
     212                 :                : {
     213                 :              0 :     return d_->pivot_button_;
     214                 :                : }
     215                 :                : 
     216                 :              0 : void format::pivot_button(bool show)
     217                 :                : {
     218                 :              0 :     d_->pivot_button_ = show;
     219                 :              0 : }
     220                 :                : 
     221                 :              0 : bool format::quote_prefix() const
     222                 :                : {
     223                 :              0 :     return d_->quote_prefix_;
     224                 :                : }
     225                 :                : 
     226                 :              0 : void format::quote_prefix(bool quote)
     227                 :                : {
     228                 :              0 :     d_->quote_prefix_ = quote;
     229                 :              0 : }
     230                 :                : 
     231                 :CBC        4694 : void detail::format_impl_ptr::increment()
     232                 :                : {
     233         [ +  + ]:           4694 :   if (format_)
     234                 :           3403 :     ++format_->references;
     235                 :           4694 : }
     236                 :                : 
     237                 :          12405 : void detail::format_impl_ptr::decrement()
     238                 :                : {
     239   [ +  +  +  +  :          12405 :     if (format_ && --format_->references == 0)
                   +  + ]
     240                 :                :     {
     241         [ +  + ]:            654 :         if (format_->parent)
     242                 :            323 :             format_->parent->garbage_collect();
     243                 :                :         else
     244         [ +  - ]:            331 :             delete format_;
     245                 :                :     }
     246                 :          12405 : }
     247                 :                : 
     248                 :              7 : std::size_t detail::format_impl_ptr::use_count () const
     249                 :                : {
     250                 :              7 :   return format_->references;
     251                 :                : }
     252                 :                : 
     253                 :                : } // namespace xlnt
        

Generated by: LCOV version 2.3.1-beta