LCOV - code coverage report
Current view: top level - sc/inc - bigrange.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 76 0.0 %
Date: 2012-08-25 Functions: 0 31 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 80 0.0 %

           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_BIGRANGE_HXX
      30                 :            : #define SC_BIGRANGE_HXX
      31                 :            : 
      32                 :            : 
      33                 :            : #include "global.hxx"
      34                 :            : #include "document.hxx"
      35                 :            : 
      36                 :            : 
      37                 :            : static const sal_Int32 nInt32Min = 0x80000000;
      38                 :            : static const sal_Int32 nInt32Max = 0x7fffffff;
      39                 :            : 
      40                 :            : 
      41                 :            : class ScBigAddress
      42                 :            : {
      43                 :            :     sal_Int32   nRow;
      44                 :            :     sal_Int32   nCol;
      45                 :            :     sal_Int32   nTab;
      46                 :            : 
      47                 :            : public:
      48                 :          0 :             ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
      49                 :            :             ScBigAddress( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
      50                 :            :                 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
      51                 :          0 :             ScBigAddress( const ScBigAddress& r )
      52                 :          0 :                 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
      53                 :          0 :             ScBigAddress( const ScAddress& r )
      54                 :          0 :                 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
      55                 :            : 
      56                 :          0 :     sal_Int32   Col() const { return nCol; }
      57                 :          0 :     sal_Int32   Row() const { return nRow; }
      58                 :          0 :     sal_Int32   Tab() const { return nTab; }
      59                 :            : 
      60                 :          0 :     void    Set( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
      61                 :          0 :                 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
      62                 :          0 :     void    SetCol( sal_Int32 nColP ) { nCol = nColP; }
      63                 :          0 :     void    SetRow( sal_Int32 nRowP ) { nRow = nRowP; }
      64                 :          0 :     void    SetTab( sal_Int32 nTabP ) { nTab = nTabP; }
      65                 :          0 :     void    IncCol( sal_Int32 n = 1 ) { nCol += n; }
      66                 :          0 :     void    IncRow( sal_Int32 n = 1 ) { nRow += n; }
      67                 :          0 :     void    IncTab( sal_Int32 n = 1 ) { nTab += n; }
      68                 :            : 
      69                 :          0 :     void    GetVars( sal_Int32& nColP, sal_Int32& nRowP, sal_Int32& nTabP ) const
      70                 :          0 :                 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
      71                 :            : 
      72                 :            :     inline void     PutInOrder( ScBigAddress& r );
      73                 :            :     inline sal_Bool     IsValid( const ScDocument* ) const;
      74                 :            :     inline ScAddress    MakeAddress() const;
      75                 :            : 
      76                 :          0 :     ScBigAddress&   operator=( const ScBigAddress& r )
      77                 :          0 :                     { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
      78                 :            :     ScBigAddress&   operator=( const ScAddress& r )
      79                 :            :                     { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
      80                 :          0 :     int             operator==( const ScBigAddress& r ) const
      81 [ #  # ][ #  # ]:          0 :                     { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
                 [ #  # ]
      82                 :            :     int             operator!=( const ScBigAddress& r ) const
      83                 :            :                     { return !operator==( r ); }
      84                 :            : 
      85                 :            :     friend inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr );
      86                 :            :     friend inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr );
      87                 :            : };
      88                 :            : 
      89                 :            : 
      90                 :            : inline void ScBigAddress::PutInOrder( ScBigAddress& r )
      91                 :            : {
      92                 :            :     sal_Int32 nTmp;
      93                 :            :     if ( r.nCol < nCol )
      94                 :            :     {
      95                 :            :         nTmp = r.nCol;
      96                 :            :         r.nCol = nCol;
      97                 :            :         nCol = nTmp;
      98                 :            :     }
      99                 :            :     if ( r.nRow < nRow )
     100                 :            :     {
     101                 :            :         nTmp = r.nRow;
     102                 :            :         r.nRow = nRow;
     103                 :            :         nRow = nTmp;
     104                 :            :     }
     105                 :            :     if ( r.nTab < nTab )
     106                 :            :     {
     107                 :            :         nTmp = r.nTab;
     108                 :            :         r.nTab = nTab;
     109                 :            :         nTab = nTmp;
     110                 :            :     }
     111                 :            : }
     112                 :            : 
     113                 :            : 
     114                 :          0 : inline sal_Bool ScBigAddress::IsValid( const ScDocument* pDoc ) const
     115                 :            : {   // min/max interval bounds define whole col/row/tab
     116                 :            :     return
     117                 :            :         ((0 <= nCol && nCol <= MAXCOL)
     118                 :            :             || nCol == nInt32Min || nCol == nInt32Max) &&
     119                 :            :         ((0 <= nRow && nRow <= MAXROW)
     120                 :            :             || nRow == nInt32Min || nRow == nInt32Max) &&
     121                 :          0 :         ((0 <= nTab && nTab < pDoc->GetTableCount())
     122 [ #  # ][ #  # ]:          0 :             || nTab == nInt32Min || nTab == nInt32Max)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
         [ #  # ][ #  # ]
     123                 :            :         ;
     124                 :            : }
     125                 :            : 
     126                 :            : 
     127                 :          0 : inline ScAddress ScBigAddress::MakeAddress() const
     128                 :            : {
     129                 :            :     SCCOL nColA;
     130                 :            :     SCROW nRowA;
     131                 :            :     SCTAB nTabA;
     132                 :            : 
     133         [ #  # ]:          0 :     if ( nCol < 0 )
     134                 :          0 :         nColA = 0;
     135         [ #  # ]:          0 :     else if ( nCol > MAXCOL )
     136                 :          0 :         nColA = MAXCOL;
     137                 :            :     else
     138                 :          0 :         nColA = (SCCOL) nCol;
     139                 :            : 
     140         [ #  # ]:          0 :     if ( nRow < 0 )
     141                 :          0 :         nRowA = 0;
     142         [ #  # ]:          0 :     else if ( nRow > MAXROW )
     143                 :          0 :         nRowA = MAXROW;
     144                 :            :     else
     145                 :          0 :         nRowA = (SCROW) nRow;
     146                 :            : 
     147         [ #  # ]:          0 :     if ( nTab < 0 )
     148                 :          0 :         nTabA = 0;
     149         [ #  # ]:          0 :     else if ( nTab > MAXTAB )
     150                 :          0 :         nTabA = MAXTAB;
     151                 :            :     else
     152                 :          0 :         nTabA = (SCTAB) nTab;
     153                 :            : 
     154                 :          0 :     return ScAddress( nColA, nRowA, nTabA );
     155                 :            : }
     156                 :            : 
     157                 :            : 
     158                 :            : inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr )
     159                 :            : {
     160                 :            :     rStream << rAdr.nCol << rAdr.nRow << rAdr.nTab;
     161                 :            :     return rStream;
     162                 :            : }
     163                 :            : 
     164                 :            : 
     165                 :            : inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr )
     166                 :            : {
     167                 :            :     rStream >> rAdr.nCol >> rAdr.nRow >> rAdr.nTab;
     168                 :            :     return rStream;
     169                 :            : }
     170                 :            : 
     171                 :            : 
     172                 :            : class ScBigRange
     173                 :            : {
     174                 :            : public:
     175                 :            : 
     176                 :            :     ScBigAddress    aStart;
     177                 :            :     ScBigAddress    aEnd;
     178                 :            : 
     179                 :          0 :                     ScBigRange() : aStart(), aEnd() {}
     180                 :            :                     ScBigRange( const ScBigAddress& s, const ScBigAddress& e )
     181                 :            :                         : aStart( s ), aEnd( e ) { aStart.PutInOrder( aEnd ); }
     182                 :          0 :                     ScBigRange( const ScBigRange& r )
     183                 :          0 :                         : aStart( r.aStart ), aEnd( r.aEnd ) {}
     184                 :          0 :                     ScBigRange( const ScRange& r )
     185                 :          0 :                         : aStart( r.aStart ), aEnd( r.aEnd ) {}
     186                 :            :                     ScBigRange( const ScBigAddress& r )
     187                 :            :                         : aStart( r ), aEnd( r ) {}
     188                 :            :                     ScBigRange( const ScAddress& r )
     189                 :            :                         : aStart( r ), aEnd( r ) {}
     190                 :            :                     ScBigRange( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nTab )
     191                 :            :                         : aStart( nCol, nRow, nTab ), aEnd( aStart ) {}
     192                 :            :                     ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
     193                 :            :                             sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
     194                 :            :                         : aStart( nCol1, nRow1, nTab1 ),
     195                 :            :                         aEnd( nCol2, nRow2, nTab2 ) {}
     196                 :            : 
     197                 :          0 :     void    Set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
     198                 :            :                      sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
     199                 :          0 :                 { aStart.Set( nCol1, nRow1, nTab1 );
     200                 :          0 :                     aEnd.Set( nCol2, nRow2, nTab2 ); }
     201                 :            : 
     202                 :          0 :     void    GetVars( sal_Int32& nCol1, sal_Int32& nRow1, sal_Int32& nTab1,
     203                 :            :                      sal_Int32& nCol2, sal_Int32& nRow2, sal_Int32& nTab2 ) const
     204                 :          0 :                 { aStart.GetVars( nCol1, nRow1, nTab1 );
     205                 :          0 :                     aEnd.GetVars( nCol2, nRow2, nTab2 ); }
     206                 :            : 
     207                 :          0 :     sal_Bool    IsValid( const ScDocument* pDoc ) const
     208 [ #  # ][ #  # ]:          0 :                 { return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
     209                 :          0 :     inline ScRange  MakeRange() const
     210                 :            :                     { return ScRange( aStart.MakeAddress(),
     211                 :          0 :                         aEnd.MakeAddress() ); }
     212                 :            : 
     213                 :            :     inline sal_Bool In( const ScBigAddress& ) const;    // is Address& in range?
     214                 :            :     inline sal_Bool In( const ScBigRange& ) const;      // is Range& in range?
     215                 :            :     inline sal_Bool Intersects( const ScBigRange& ) const;  // do two ranges overlap?
     216                 :            : 
     217                 :          0 :     ScBigRange&     operator=( const ScBigRange& r )
     218                 :          0 :                         { aStart = r.aStart; aEnd = r.aEnd; return *this; }
     219                 :          0 :     int             operator==( const ScBigRange& r ) const
     220 [ #  # ][ #  # ]:          0 :                         { return (aStart == r.aStart) && (aEnd == r.aEnd); }
     221                 :          0 :     int             operator!=( const ScBigRange& r ) const
     222                 :          0 :                         { return !operator==( r ); }
     223                 :            : 
     224                 :            :     friend inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange );
     225                 :            :     friend inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange );
     226                 :            : };
     227                 :            : 
     228                 :            : 
     229                 :          0 : inline sal_Bool ScBigRange::In( const ScBigAddress& rAddr ) const
     230                 :            : {
     231                 :            :     return
     232                 :          0 :         aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
     233                 :          0 :         aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
     234 [ #  # ][ #  # ]:          0 :         aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
           [ #  #  #  #  
             #  #  #  # ]
     235                 :            : }
     236                 :            : 
     237                 :            : 
     238                 :          0 : inline sal_Bool ScBigRange::In( const ScBigRange& r ) const
     239                 :            : {
     240                 :            :     return
     241                 :          0 :         aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
     242                 :          0 :         aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
     243 [ #  # ][ #  # ]:          0 :         aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
           [ #  #  #  #  
             #  #  #  # ]
     244                 :            : }
     245                 :            : 
     246                 :            : 
     247                 :          0 : inline sal_Bool ScBigRange::Intersects( const ScBigRange& r ) const
     248                 :            : {
     249                 :            :     return !(
     250                 :          0 :         Min( aEnd.Col(), r.aEnd.Col() ) < Max( aStart.Col(), r.aStart.Col() )
     251                 :          0 :      || Min( aEnd.Row(), r.aEnd.Row() ) < Max( aStart.Row(), r.aStart.Row() )
     252                 :          0 :      || Min( aEnd.Tab(), r.aEnd.Tab() ) < Max( aStart.Tab(), r.aStart.Tab() )
     253   [ #  #  #  #  :          0 :         );
                   #  # ]
     254                 :            : }
     255                 :            : 
     256                 :            : 
     257                 :            : inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange )
     258                 :            : {
     259                 :            :     rStream << rRange.aStart;
     260                 :            :     rStream << rRange.aEnd;
     261                 :            :     return rStream;
     262                 :            : }
     263                 :            : 
     264                 :            : 
     265                 :            : inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange )
     266                 :            : {
     267                 :            :     rStream >> rRange.aStart;
     268                 :            :     rStream >> rRange.aEnd;
     269                 :            :     return rStream;
     270                 :            : }
     271                 :            : 
     272                 :            : 
     273                 :            : 
     274                 :            : #endif
     275                 :            : 
     276                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10