LCOV - code coverage report
Current view: top level - sc/inc - refdata.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 65 66.2 %
Date: 2012-08-25 Functions: 27 33 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 26 64 40.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef SC_REFDATA_HXX
      30                 :            : #define SC_REFDATA_HXX
      31                 :            : 
      32                 :            : #include "global.hxx"
      33                 :            : #include "address.hxx"
      34                 :            : #include "scdllapi.h"
      35                 :            : 
      36                 :            : 
      37                 :            : // Ref-Flags for old (until release 3.1) documents
      38                 :            : 
      39                 :            : struct OldSingleRefBools
      40                 :            : {
      41                 :            :     sal_uInt8    bRelCol;    // Flag values (see further down), 2 bits each in file format
      42                 :            :     sal_uInt8    bRelRow;
      43                 :            :     sal_uInt8    bRelTab;
      44                 :            :     sal_uInt8    bOldFlag3D; // two sal_Bool flags (see further down)
      45                 :            : };
      46                 :            : 
      47                 :            : struct SC_DLLPUBLIC ScSingleRefData        // Single reference (one address) into the sheet
      48                 :            : {
      49                 :            :     SCsCOL  nCol;       // Absolute values
      50                 :            :     SCsROW  nRow;
      51                 :            :     SCsTAB  nTab;
      52                 :            :     SCsCOL  nRelCol;    // Values relative to the position
      53                 :            :     SCsROW  nRelRow;
      54                 :            :     SCsTAB  nRelTab;
      55                 :            : 
      56                 :            :     union
      57                 :            :     {
      58                 :            :         sal_Bool bFlags;
      59                 :            :         struct
      60                 :            :         {
      61                 :            :             sal_Bool    bColRel     :1;
      62                 :            :             sal_Bool    bColDeleted :1;
      63                 :            :             sal_Bool    bRowRel     :1;
      64                 :            :             sal_Bool    bRowDeleted :1;
      65                 :            :             sal_Bool    bTabRel     :1;
      66                 :            :             sal_Bool    bTabDeleted :1;
      67                 :            :             sal_Bool    bFlag3D     :1;     // 3D-Ref
      68                 :            :             sal_Bool    bRelName    :1;     // Reference derived from RangeName with relative values
      69                 :            :         }Flags;
      70                 :            :     };
      71                 :            : 
      72                 :            :     // No default ctor, because used in ScRawToken union, set InitFlags!
      73                 :     110858 :     inline  void InitFlags() { bFlags = 0; }    // all FALSE
      74                 :            :     // InitAddress: InitFlags and set address
      75                 :            :     inline  void InitAddress( const ScAddress& rAdr );
      76                 :            :     inline  void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
      77                 :            :     // InitAddressRel: InitFlags and set address, everything relative to rPos
      78                 :            :     inline  void InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos );
      79         [ +  + ]:      29203 :     inline  void SetColRel( sal_Bool bVal ) { Flags.bColRel = (bVal ? sal_True : false ); }
      80                 :      42502 :     inline  sal_Bool IsColRel() const       { return Flags.bColRel; }
      81         [ +  + ]:      29203 :     inline  void SetRowRel( sal_Bool bVal ) { Flags.bRowRel = (bVal ? sal_True : false ); }
      82                 :      42466 :     inline  sal_Bool IsRowRel() const       { return Flags.bRowRel; }
      83         [ +  + ]:      29203 :     inline  void SetTabRel( sal_Bool bVal ) { Flags.bTabRel = (bVal ? sal_True : false ); }
      84                 :      43937 :     inline  sal_Bool IsTabRel() const       { return Flags.bTabRel; }
      85                 :            : 
      86         [ -  + ]:        102 :     inline  void SetColDeleted( sal_Bool bVal ) { Flags.bColDeleted = (bVal ? sal_True : false ); }
      87                 :      42202 :     inline  sal_Bool IsColDeleted() const       { return Flags.bColDeleted; }
      88         [ -  + ]:        102 :     inline  void SetRowDeleted( sal_Bool bVal ) { Flags.bRowDeleted = (bVal ? sal_True : false ); }
      89                 :      42202 :     inline  sal_Bool IsRowDeleted() const       { return Flags.bRowDeleted; }
      90         [ +  + ]:        111 :     inline  void SetTabDeleted( sal_Bool bVal ) { Flags.bTabDeleted = (bVal ? sal_True : false ); }
      91                 :      29417 :     inline  sal_Bool IsTabDeleted() const       { return Flags.bTabDeleted; }
      92 [ +  - ][ +  - ]:        475 :     inline  sal_Bool IsDeleted() const          { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); }
                 [ -  + ]
      93                 :            : 
      94         [ +  + ]:      55595 :     inline  void SetFlag3D( sal_Bool bVal ) { Flags.bFlag3D = (bVal ? sal_True : false ); }
      95                 :      46242 :     inline  sal_Bool IsFlag3D() const       { return Flags.bFlag3D; }
      96         [ +  + ]:        123 :     inline  void SetRelName( sal_Bool bVal )    { Flags.bRelName = (bVal ? sal_True : false ); }
      97                 :        266 :     inline  sal_Bool IsRelName() const          { return Flags.bRelName; }
      98                 :            : 
      99                 :            :     inline  sal_Bool Valid() const;
     100                 :            :     /// In external references nTab is -1
     101                 :            :     inline  bool ValidExternal() const;
     102                 :            : 
     103                 :            :             void SmartRelAbs( const ScAddress& rPos );
     104                 :            :             void CalcRelFromAbs( const ScAddress& rPos );
     105                 :            :             void CalcAbsIfRel( const ScAddress& rPos );
     106                 :            :             sal_Bool operator==( const ScSingleRefData& ) const;
     107                 :            :             bool operator!=( const ScSingleRefData& ) const;
     108                 :            : };
     109                 :            : 
     110                 :       5386 : inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP )
     111                 :            : {
     112                 :       5386 :     InitFlags();
     113                 :       5386 :     nCol = nColP;
     114                 :       5386 :     nRow = nRowP;
     115                 :       5386 :     nTab = nTabP;
     116                 :       5386 : }
     117                 :            : 
     118                 :       5386 : inline void ScSingleRefData::InitAddress( const ScAddress& rAdr )
     119                 :            : {
     120                 :       5386 :     InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
     121                 :       5386 : }
     122                 :            : 
     123                 :          0 : inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr,
     124                 :            :                                             const ScAddress& rPos )
     125                 :            : {
     126                 :          0 :     InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
     127                 :          0 :     SetColRel( sal_True );
     128                 :          0 :     SetRowRel( sal_True );
     129                 :          0 :     SetTabRel( sal_True );
     130                 :          0 :     CalcRelFromAbs( rPos );
     131                 :          0 : }
     132                 :            : 
     133                 :      25285 : inline sal_Bool ScSingleRefData::Valid() const
     134                 :            : {
     135                 :            :     return  nCol >= 0 && nCol <= MAXCOL &&
     136                 :            :             nRow >= 0 && nRow <= MAXROW &&
     137 [ +  - ][ +  - ]:      25285 :             nTab >= 0 && nTab <= MAXTAB;
         [ +  - ][ +  - ]
         [ +  - ][ +  + ]
     138                 :            : }
     139                 :            : 
     140                 :          0 : inline bool ScSingleRefData::ValidExternal() const
     141                 :            : {
     142                 :            :     return  nCol >= 0 && nCol <= MAXCOL &&
     143                 :            :             nRow >= 0 && nRow <= MAXROW &&
     144 [ #  # ][ #  # ]:          0 :             nTab == -1;
         [ #  # ][ #  # ]
                 [ #  # ]
     145                 :            : }
     146                 :            : 
     147                 :            : 
     148                 :            : struct ScComplexRefData         // Complex reference (a range) into the sheet
     149                 :            : {
     150                 :            :     ScSingleRefData Ref1;
     151                 :            :     ScSingleRefData Ref2;
     152                 :            : 
     153                 :      31879 :     inline  void InitFlags()
     154                 :      31879 :         { Ref1.InitFlags(); Ref2.InitFlags(); }
     155                 :       1806 :     inline  void InitRange( const ScRange& rRange )
     156                 :            :         {
     157                 :       1806 :             Ref1.InitAddress( rRange.aStart );
     158                 :       1806 :             Ref2.InitAddress( rRange.aEnd );
     159                 :       1806 :         }
     160                 :          0 :     inline  void InitRangeRel( const ScRange& rRange, const ScAddress& rPos )
     161                 :            :         {
     162                 :          0 :             Ref1.InitAddressRel( rRange.aStart, rPos );
     163                 :          0 :             Ref2.InitAddressRel( rRange.aEnd, rPos );
     164                 :          0 :         }
     165                 :          0 :     inline  void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
     166                 :            :                             SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
     167                 :            :         {
     168                 :          0 :             Ref1.InitAddress( nCol1, nRow1, nTab1 );
     169                 :          0 :             Ref2.InitAddress( nCol2, nRow2, nTab2 );
     170                 :          0 :         }
     171                 :         16 :     inline  void SmartRelAbs( const ScAddress& rPos )
     172                 :         16 :         { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); }
     173                 :       2051 :     inline  void CalcRelFromAbs( const ScAddress& rPos )
     174                 :       2051 :         { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); }
     175                 :       5844 :     inline  void CalcAbsIfRel( const ScAddress& rPos )
     176                 :       5844 :         { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); }
     177                 :            :     inline  sal_Bool IsDeleted() const
     178                 :            :         { return Ref1.IsDeleted() || Ref2.IsDeleted(); }
     179                 :       2998 :     inline  sal_Bool Valid() const
     180 [ +  - ][ +  - ]:       2998 :         { return Ref1.Valid() && Ref2.Valid(); }
     181                 :            :     /** In external references nTab is -1 for the start tab and -1 for the end
     182                 :            :         tab if one sheet, or >=0 if more than one sheets. */
     183                 :            :     inline  bool ValidExternal() const;
     184                 :            : 
     185                 :            :     /// Absolute references have to be up-to-date when calling this!
     186                 :            :     void PutInOrder();
     187                 :          0 :     inline  sal_Bool operator==( const ScComplexRefData& r ) const
     188 [ #  # ][ #  # ]:          0 :         { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
     189                 :            :     /** Enlarge range if reference passed is not within existing range.
     190                 :            :         ScAddress position is used to calculate absolute references from
     191                 :            :         relative references. */
     192                 :            :     ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos );
     193                 :            :     ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos );
     194                 :            : };
     195                 :            : 
     196                 :          0 : inline bool ScComplexRefData::ValidExternal() const
     197                 :            : {
     198                 :          0 :     return Ref1.ValidExternal() &&
     199                 :            :         Ref2.nCol >= 0 && Ref2.nCol <= MAXCOL &&
     200                 :            :         Ref2.nRow >= 0 && Ref2.nRow <= MAXROW &&
     201 [ #  # ][ #  # ]:          0 :         Ref2.nTab >= Ref1.nTab;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     202                 :            : }
     203                 :            : 
     204                 :            : #endif
     205                 :            : 
     206                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10