LCOV - code coverage report
Current view: top level - sc/inc - bigrange.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 51 77 66.2 %
Date: 2014-11-03 Functions: 20 32 62.5 %
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 INCLUDED_SC_INC_BIGRANGE_HXX
      21             : #define INCLUDED_SC_INC_BIGRANGE_HXX
      22             : 
      23             : #include "global.hxx"
      24             : 
      25             : static const sal_Int32 nInt32Min = 0x80000000;
      26             : static const sal_Int32 nInt32Max = 0x7fffffff;
      27             : 
      28             : class ScDocument;
      29             : 
      30             : class ScBigAddress
      31             : {
      32             :     sal_Int32   nRow;
      33             :     sal_Int32   nCol;
      34             :     sal_Int32   nTab;
      35             : 
      36             : public:
      37           0 :             ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
      38         208 :             ScBigAddress( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
      39         208 :                 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
      40        1304 :             ScBigAddress( const ScBigAddress& r )
      41        1304 :                 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
      42         216 :             ScBigAddress( const ScAddress& r )
      43         216 :                 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
      44             : 
      45         768 :     sal_Int32   Col() const { return nCol; }
      46        1340 :     sal_Int32   Row() const { return nRow; }
      47         192 :     sal_Int32   Tab() const { return nTab; }
      48             : 
      49           0 :     void    Set( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
      50           0 :                 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
      51         288 :     void    SetCol( sal_Int32 nColP ) { nCol = nColP; }
      52         624 :     void    SetRow( sal_Int32 nRowP ) { nRow = nRowP; }
      53           0 :     void    SetTab( sal_Int32 nTabP ) { nTab = nTabP; }
      54           0 :     void    IncCol( sal_Int32 n = 1 ) { nCol += n; }
      55           0 :     void    IncRow( sal_Int32 n = 1 ) { nRow += n; }
      56           0 :     void    IncTab( sal_Int32 n = 1 ) { nTab += n; }
      57             : 
      58        1152 :     void    GetVars( sal_Int32& nColP, sal_Int32& nRowP, sal_Int32& nTabP ) const
      59        1152 :                 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
      60             : 
      61             :     inline void     PutInOrder( ScBigAddress& r );
      62             :     bool IsValid( const ScDocument* pDoc ) const;
      63             :     inline ScAddress    MakeAddress() const;
      64             : 
      65           0 :     ScBigAddress&   operator=( const ScBigAddress& r )
      66           0 :                     { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
      67             :     ScBigAddress&   operator=( const ScAddress& r )
      68             :                     { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
      69         980 :     bool            operator==( const ScBigAddress& r ) const
      70         980 :                     { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
      71             :     bool            operator!=( const ScBigAddress& r ) const
      72             :                     { return !operator==( r ); }
      73             : 
      74             :     friend inline SvStream& WriteScBigAddress( SvStream& rStream, const ScBigAddress& rAdr );
      75             :     friend inline SvStream& ReadScBigAddress( SvStream& rStream, ScBigAddress& rAdr );
      76             : };
      77             : 
      78             : inline void ScBigAddress::PutInOrder( ScBigAddress& r )
      79             : {
      80             :     sal_Int32 nTmp;
      81             :     if ( r.nCol < nCol )
      82             :     {
      83             :         nTmp = r.nCol;
      84             :         r.nCol = nCol;
      85             :         nCol = nTmp;
      86             :     }
      87             :     if ( r.nRow < nRow )
      88             :     {
      89             :         nTmp = r.nRow;
      90             :         r.nRow = nRow;
      91             :         nRow = nTmp;
      92             :     }
      93             :     if ( r.nTab < nTab )
      94             :     {
      95             :         nTmp = r.nTab;
      96             :         r.nTab = nTab;
      97             :         nTab = nTmp;
      98             :     }
      99             : }
     100             : 
     101         154 : inline ScAddress ScBigAddress::MakeAddress() const
     102             : {
     103             :     SCCOL nColA;
     104             :     SCROW nRowA;
     105             :     SCTAB nTabA;
     106             : 
     107         154 :     if ( nCol < 0 )
     108          32 :         nColA = 0;
     109         122 :     else if ( nCol > MAXCOL )
     110          32 :         nColA = MAXCOL;
     111             :     else
     112          90 :         nColA = (SCCOL) nCol;
     113             : 
     114         154 :     if ( nRow < 0 )
     115           0 :         nRowA = 0;
     116         154 :     else if ( nRow > MAXROW )
     117           8 :         nRowA = MAXROW;
     118             :     else
     119         146 :         nRowA = (SCROW) nRow;
     120             : 
     121         154 :     if ( nTab < 0 )
     122           0 :         nTabA = 0;
     123         154 :     else if ( nTab > MAXTAB )
     124           0 :         nTabA = MAXTAB;
     125             :     else
     126         154 :         nTabA = (SCTAB) nTab;
     127             : 
     128         154 :     return ScAddress( nColA, nRowA, nTabA );
     129             : }
     130             : 
     131             : inline SvStream& WriteScBigAddress( SvStream& rStream, const ScBigAddress& rAdr )
     132             : {
     133             :     rStream.WriteInt32( rAdr.nCol ).WriteInt32( rAdr.nRow ).WriteInt32( rAdr.nTab );
     134             :     return rStream;
     135             : }
     136             : 
     137             : inline SvStream& ReadScBigAddress( SvStream& rStream, ScBigAddress& rAdr )
     138             : {
     139             :     rStream.ReadInt32( rAdr.nCol ).ReadInt32( rAdr.nRow ).ReadInt32( rAdr.nTab );
     140             :     return rStream;
     141             : }
     142             : 
     143             : class ScBigRange
     144             : {
     145             : public:
     146             : 
     147             :     ScBigAddress    aStart;
     148             :     ScBigAddress    aEnd;
     149             : 
     150           0 :                     ScBigRange() : aStart(), aEnd() {}
     151             :                     ScBigRange( const ScBigAddress& s, const ScBigAddress& e )
     152             :                         : aStart( s ), aEnd( e ) { aStart.PutInOrder( aEnd ); }
     153         652 :                     ScBigRange( const ScBigRange& r )
     154         652 :                         : aStart( r.aStart ), aEnd( r.aEnd ) {}
     155         108 :                     ScBigRange( const ScRange& r )
     156         108 :                         : aStart( r.aStart ), aEnd( r.aEnd ) {}
     157             :                     ScBigRange( const ScBigAddress& r )
     158             :                         : aStart( r ), aEnd( r ) {}
     159             :                     ScBigRange( const ScAddress& r )
     160             :                         : aStart( r ), aEnd( r ) {}
     161             :                     ScBigRange( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nTab )
     162             :                         : aStart( nCol, nRow, nTab ), aEnd( aStart ) {}
     163         104 :                     ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
     164             :                             sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
     165             :                         : aStart( nCol1, nRow1, nTab1 ),
     166         104 :                         aEnd( nCol2, nRow2, nTab2 ) {}
     167             : 
     168           0 :     void    Set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
     169             :                      sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
     170           0 :                 { aStart.Set( nCol1, nRow1, nTab1 );
     171           0 :                     aEnd.Set( nCol2, nRow2, nTab2 ); }
     172             : 
     173         576 :     void    GetVars( sal_Int32& nCol1, sal_Int32& nRow1, sal_Int32& nTab1,
     174             :                      sal_Int32& nCol2, sal_Int32& nRow2, sal_Int32& nTab2 ) const
     175         576 :                 { aStart.GetVars( nCol1, nRow1, nTab1 );
     176         576 :                     aEnd.GetVars( nCol2, nRow2, nTab2 ); }
     177             : 
     178           2 :     bool    IsValid( const ScDocument* pDoc ) const
     179           2 :                 { return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
     180          60 :     inline ScRange  MakeRange() const
     181             :                     { return ScRange( aStart.MakeAddress(),
     182          60 :                         aEnd.MakeAddress() ); }
     183             : 
     184             :     inline bool In( const ScBigAddress& ) const;    ///< is Address& in range?
     185             :     inline bool In( const ScBigRange& ) const;      ///< is Range& in range?
     186             :     inline bool Intersects( const ScBigRange& ) const;  ///< do two ranges overlap?
     187             : 
     188           0 :     ScBigRange&     operator=( const ScBigRange& r )
     189           0 :                         { aStart = r.aStart; aEnd = r.aEnd; return *this; }
     190         392 :     bool            operator==( const ScBigRange& r ) const
     191         392 :                         { return (aStart == r.aStart) && (aEnd == r.aEnd); }
     192         288 :     bool            operator!=( const ScBigRange& r ) const
     193         288 :                         { return !operator==( r ); }
     194             : 
     195             :     friend inline SvStream& WriteScBigRange( SvStream& rStream, const ScBigRange& rRange );
     196             :     friend inline SvStream& ReadScBigRange( SvStream& rStream, ScBigRange& rRange );
     197             : };
     198             : 
     199           0 : inline bool ScBigRange::In( const ScBigAddress& rAddr ) const
     200             : {
     201             :     return
     202           0 :         aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
     203           0 :         aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
     204           0 :         aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
     205             : }
     206             : 
     207           0 : inline bool ScBigRange::In( const ScBigRange& r ) const
     208             : {
     209             :     return
     210           0 :         aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
     211           0 :         aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
     212           0 :         aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
     213             : }
     214             : 
     215         192 : inline bool ScBigRange::Intersects( const ScBigRange& r ) const
     216             : {
     217             :     return !(
     218        1344 :         std::min( aEnd.Col(), r.aEnd.Col() ) < std::max( aStart.Col(), r.aStart.Col() )
     219         384 :      || std::min( aEnd.Row(), r.aEnd.Row() ) < std::max( aStart.Row(), r.aStart.Row() )
     220         432 :      || std::min( aEnd.Tab(), r.aEnd.Tab() ) < std::max( aStart.Tab(), r.aStart.Tab() )
     221        1584 :         );
     222             : }
     223             : 
     224             : inline SvStream& WriteScBigRange ( SvStream& rStream, const ScBigRange& rRange )
     225             : {
     226             :     WriteScBigAddress( rStream, rRange.aStart );
     227             :     WriteScBigAddress( rStream, rRange.aEnd );
     228             :     return rStream;
     229             : }
     230             : 
     231             : inline SvStream& ReadScBigRange( SvStream& rStream, ScBigRange& rRange )
     232             : {
     233             :     ReadScBigAddress( rStream, rRange.aStart );
     234             :     ReadScBigAddress( rStream, rRange.aEnd );
     235             :     return rStream;
     236             : }
     237             : 
     238             : #endif
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10