LCOV - code coverage report
Current view: top level - libreoffice/sc/inc - bigrange.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 76 0.0 %
Date: 2012-12-27 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef SC_BIGRANGE_HXX
      21             : #define SC_BIGRANGE_HXX
      22             : 
      23             : 
      24             : #include "global.hxx"
      25             : #include "document.hxx"
      26             : 
      27             : 
      28             : static const sal_Int32 nInt32Min = 0x80000000;
      29             : static const sal_Int32 nInt32Max = 0x7fffffff;
      30             : 
      31             : 
      32             : class ScBigAddress
      33             : {
      34             :     sal_Int32   nRow;
      35             :     sal_Int32   nCol;
      36             :     sal_Int32   nTab;
      37             : 
      38             : public:
      39           0 :             ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
      40             :             ScBigAddress( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
      41             :                 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
      42           0 :             ScBigAddress( const ScBigAddress& r )
      43           0 :                 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
      44           0 :             ScBigAddress( const ScAddress& r )
      45           0 :                 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
      46             : 
      47           0 :     sal_Int32   Col() const { return nCol; }
      48           0 :     sal_Int32   Row() const { return nRow; }
      49           0 :     sal_Int32   Tab() const { return nTab; }
      50             : 
      51           0 :     void    Set( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
      52           0 :                 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
      53           0 :     void    SetCol( sal_Int32 nColP ) { nCol = nColP; }
      54           0 :     void    SetRow( sal_Int32 nRowP ) { nRow = nRowP; }
      55           0 :     void    SetTab( sal_Int32 nTabP ) { nTab = nTabP; }
      56           0 :     void    IncCol( sal_Int32 n = 1 ) { nCol += n; }
      57           0 :     void    IncRow( sal_Int32 n = 1 ) { nRow += n; }
      58           0 :     void    IncTab( sal_Int32 n = 1 ) { nTab += n; }
      59             : 
      60           0 :     void    GetVars( sal_Int32& nColP, sal_Int32& nRowP, sal_Int32& nTabP ) const
      61           0 :                 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
      62             : 
      63             :     inline void     PutInOrder( ScBigAddress& r );
      64             :     inline sal_Bool     IsValid( const ScDocument* ) const;
      65             :     inline ScAddress    MakeAddress() const;
      66             : 
      67           0 :     ScBigAddress&   operator=( const ScBigAddress& r )
      68           0 :                     { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
      69             :     ScBigAddress&   operator=( const ScAddress& r )
      70             :                     { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
      71           0 :     int             operator==( const ScBigAddress& r ) const
      72           0 :                     { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
      73             :     int             operator!=( const ScBigAddress& r ) const
      74             :                     { return !operator==( r ); }
      75             : 
      76             :     friend inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr );
      77             :     friend inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr );
      78             : };
      79             : 
      80             : 
      81             : inline void ScBigAddress::PutInOrder( ScBigAddress& r )
      82             : {
      83             :     sal_Int32 nTmp;
      84             :     if ( r.nCol < nCol )
      85             :     {
      86             :         nTmp = r.nCol;
      87             :         r.nCol = nCol;
      88             :         nCol = nTmp;
      89             :     }
      90             :     if ( r.nRow < nRow )
      91             :     {
      92             :         nTmp = r.nRow;
      93             :         r.nRow = nRow;
      94             :         nRow = nTmp;
      95             :     }
      96             :     if ( r.nTab < nTab )
      97             :     {
      98             :         nTmp = r.nTab;
      99             :         r.nTab = nTab;
     100             :         nTab = nTmp;
     101             :     }
     102             : }
     103             : 
     104             : 
     105           0 : inline sal_Bool ScBigAddress::IsValid( const ScDocument* pDoc ) const
     106             : {   // min/max interval bounds define whole col/row/tab
     107             :     return
     108             :         ((0 <= nCol && nCol <= MAXCOL)
     109             :             || nCol == nInt32Min || nCol == nInt32Max) &&
     110             :         ((0 <= nRow && nRow <= MAXROW)
     111             :             || nRow == nInt32Min || nRow == nInt32Max) &&
     112           0 :         ((0 <= nTab && nTab < pDoc->GetTableCount())
     113           0 :             || nTab == nInt32Min || nTab == nInt32Max)
     114             :         ;
     115             : }
     116             : 
     117             : 
     118           0 : inline ScAddress ScBigAddress::MakeAddress() const
     119             : {
     120             :     SCCOL nColA;
     121             :     SCROW nRowA;
     122             :     SCTAB nTabA;
     123             : 
     124           0 :     if ( nCol < 0 )
     125           0 :         nColA = 0;
     126           0 :     else if ( nCol > MAXCOL )
     127           0 :         nColA = MAXCOL;
     128             :     else
     129           0 :         nColA = (SCCOL) nCol;
     130             : 
     131           0 :     if ( nRow < 0 )
     132           0 :         nRowA = 0;
     133           0 :     else if ( nRow > MAXROW )
     134           0 :         nRowA = MAXROW;
     135             :     else
     136           0 :         nRowA = (SCROW) nRow;
     137             : 
     138           0 :     if ( nTab < 0 )
     139           0 :         nTabA = 0;
     140           0 :     else if ( nTab > MAXTAB )
     141           0 :         nTabA = MAXTAB;
     142             :     else
     143           0 :         nTabA = (SCTAB) nTab;
     144             : 
     145           0 :     return ScAddress( nColA, nRowA, nTabA );
     146             : }
     147             : 
     148             : 
     149             : inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr )
     150             : {
     151             :     rStream << rAdr.nCol << rAdr.nRow << rAdr.nTab;
     152             :     return rStream;
     153             : }
     154             : 
     155             : 
     156             : inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr )
     157             : {
     158             :     rStream >> rAdr.nCol >> rAdr.nRow >> rAdr.nTab;
     159             :     return rStream;
     160             : }
     161             : 
     162             : 
     163             : class ScBigRange
     164             : {
     165             : public:
     166             : 
     167             :     ScBigAddress    aStart;
     168             :     ScBigAddress    aEnd;
     169             : 
     170           0 :                     ScBigRange() : aStart(), aEnd() {}
     171             :                     ScBigRange( const ScBigAddress& s, const ScBigAddress& e )
     172             :                         : aStart( s ), aEnd( e ) { aStart.PutInOrder( aEnd ); }
     173           0 :                     ScBigRange( const ScBigRange& r )
     174           0 :                         : aStart( r.aStart ), aEnd( r.aEnd ) {}
     175           0 :                     ScBigRange( const ScRange& r )
     176           0 :                         : aStart( r.aStart ), aEnd( r.aEnd ) {}
     177             :                     ScBigRange( const ScBigAddress& r )
     178             :                         : aStart( r ), aEnd( r ) {}
     179             :                     ScBigRange( const ScAddress& r )
     180             :                         : aStart( r ), aEnd( r ) {}
     181             :                     ScBigRange( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nTab )
     182             :                         : aStart( nCol, nRow, nTab ), aEnd( aStart ) {}
     183             :                     ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
     184             :                             sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
     185             :                         : aStart( nCol1, nRow1, nTab1 ),
     186             :                         aEnd( nCol2, nRow2, nTab2 ) {}
     187             : 
     188           0 :     void    Set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
     189             :                      sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
     190           0 :                 { aStart.Set( nCol1, nRow1, nTab1 );
     191           0 :                     aEnd.Set( nCol2, nRow2, nTab2 ); }
     192             : 
     193           0 :     void    GetVars( sal_Int32& nCol1, sal_Int32& nRow1, sal_Int32& nTab1,
     194             :                      sal_Int32& nCol2, sal_Int32& nRow2, sal_Int32& nTab2 ) const
     195           0 :                 { aStart.GetVars( nCol1, nRow1, nTab1 );
     196           0 :                     aEnd.GetVars( nCol2, nRow2, nTab2 ); }
     197             : 
     198           0 :     sal_Bool    IsValid( const ScDocument* pDoc ) const
     199           0 :                 { return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
     200           0 :     inline ScRange  MakeRange() const
     201             :                     { return ScRange( aStart.MakeAddress(),
     202           0 :                         aEnd.MakeAddress() ); }
     203             : 
     204             :     inline sal_Bool In( const ScBigAddress& ) const;    // is Address& in range?
     205             :     inline sal_Bool In( const ScBigRange& ) const;      // is Range& in range?
     206             :     inline sal_Bool Intersects( const ScBigRange& ) const;  // do two ranges overlap?
     207             : 
     208           0 :     ScBigRange&     operator=( const ScBigRange& r )
     209           0 :                         { aStart = r.aStart; aEnd = r.aEnd; return *this; }
     210           0 :     int             operator==( const ScBigRange& r ) const
     211           0 :                         { return (aStart == r.aStart) && (aEnd == r.aEnd); }
     212           0 :     int             operator!=( const ScBigRange& r ) const
     213           0 :                         { return !operator==( r ); }
     214             : 
     215             :     friend inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange );
     216             :     friend inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange );
     217             : };
     218             : 
     219             : 
     220           0 : inline sal_Bool ScBigRange::In( const ScBigAddress& rAddr ) const
     221             : {
     222             :     return
     223           0 :         aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
     224           0 :         aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
     225           0 :         aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
     226             : }
     227             : 
     228             : 
     229           0 : inline sal_Bool ScBigRange::In( const ScBigRange& r ) const
     230             : {
     231             :     return
     232           0 :         aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
     233           0 :         aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
     234           0 :         aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
     235             : }
     236             : 
     237             : 
     238           0 : inline sal_Bool ScBigRange::Intersects( const ScBigRange& r ) const
     239             : {
     240             :     return !(
     241           0 :         Min( aEnd.Col(), r.aEnd.Col() ) < Max( aStart.Col(), r.aStart.Col() )
     242           0 :      || Min( aEnd.Row(), r.aEnd.Row() ) < Max( aStart.Row(), r.aStart.Row() )
     243           0 :      || Min( aEnd.Tab(), r.aEnd.Tab() ) < Max( aStart.Tab(), r.aStart.Tab() )
     244           0 :         );
     245             : }
     246             : 
     247             : 
     248             : inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange )
     249             : {
     250             :     rStream << rRange.aStart;
     251             :     rStream << rRange.aEnd;
     252             :     return rStream;
     253             : }
     254             : 
     255             : 
     256             : inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange )
     257             : {
     258             :     rStream >> rRange.aStart;
     259             :     rStream >> rRange.aEnd;
     260             :     return rStream;
     261             : }
     262             : 
     263             : 
     264             : 
     265             : #endif
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10