LCOV - code coverage report
Current view: top level - sc/source/core/tool - queryparam.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 149 208 71.6 %
Date: 2014-04-11 Functions: 34 44 77.3 %
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             : #include "queryparam.hxx"
      21             : #include "queryentry.hxx"
      22             : #include "scmatrix.hxx"
      23             : 
      24             : #include "svl/sharedstringpool.hxx"
      25             : 
      26             : namespace {
      27             : 
      28             : const size_t MAXQUERY = 8;
      29             : 
      30             : class FindByField : public std::unary_function<ScQueryEntry, bool>
      31             : {
      32             :     SCCOLROW mnField;
      33             : public:
      34           3 :     FindByField(SCCOLROW nField) : mnField(nField) {}
      35          17 :     bool operator() (const ScQueryEntry& rEntry) const
      36             :     {
      37          17 :         return rEntry.bDoQuery && rEntry.nField == mnField;
      38             :     }
      39             : };
      40             : 
      41             : struct FindUnused : public std::unary_function<ScQueryEntry, bool>
      42             : {
      43          10 :     bool operator() (const ScQueryEntry& rEntry) const
      44             :     {
      45          10 :         return !rEntry.bDoQuery;
      46             :     }
      47             : };
      48             : 
      49             : }
      50             : 
      51         840 : ScQueryParamBase::const_iterator ScQueryParamBase::begin() const
      52             : {
      53         840 :     return maEntries.begin();
      54             : }
      55             : 
      56         840 : ScQueryParamBase::const_iterator ScQueryParamBase::end() const
      57             : {
      58         840 :     return maEntries.end();
      59             : }
      60             : 
      61         498 : ScQueryParamBase::ScQueryParamBase() :
      62             :     bHasHeader(true),
      63             :     bByRow(true),
      64             :     bInplace(true),
      65             :     bCaseSens(false),
      66             :     bRegExp(false),
      67             :     bDuplicate(false),
      68         498 :     mbRangeLookup(false)
      69             : {
      70        4482 :     for (size_t i = 0; i < MAXQUERY; ++i)
      71        3984 :         maEntries.push_back(new ScQueryEntry);
      72         498 : }
      73             : 
      74        1247 : ScQueryParamBase::ScQueryParamBase(const ScQueryParamBase& r) :
      75             :     bHasHeader(r.bHasHeader), bByRow(r.bByRow), bInplace(r.bInplace), bCaseSens(r.bCaseSens),
      76             :     bRegExp(r.bRegExp), bDuplicate(r.bDuplicate), mbRangeLookup(r.mbRangeLookup),
      77        1247 :     maEntries(r.maEntries)
      78             : {
      79        1247 : }
      80             : 
      81        1716 : ScQueryParamBase::~ScQueryParamBase()
      82             : {
      83        1716 : }
      84             : 
      85           0 : bool ScQueryParamBase::IsValidFieldIndex() const
      86             : {
      87           0 :     return true;
      88             : }
      89             : 
      90        2918 : SCSIZE ScQueryParamBase::GetEntryCount() const
      91             : {
      92        2918 :     return maEntries.size();
      93             : }
      94             : 
      95        2526 : const ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n) const
      96             : {
      97        2526 :     return maEntries[n];
      98             : }
      99             : 
     100        6471 : ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n)
     101             : {
     102        6471 :     return maEntries[n];
     103             : }
     104             : 
     105           9 : ScQueryEntry& ScQueryParamBase::AppendEntry()
     106             : {
     107             :     // Find the first unused entry.
     108             :     EntriesType::iterator itr = std::find_if(
     109           9 :         maEntries.begin(), maEntries.end(), FindUnused());
     110             : 
     111           9 :     if (itr != maEntries.end())
     112             :         // Found!
     113           9 :         return *itr;
     114             : 
     115             :     // Add a new entry to the end.
     116           0 :     maEntries.push_back(new ScQueryEntry);
     117           0 :     return maEntries.back();
     118             : }
     119             : 
     120           0 : ScQueryEntry* ScQueryParamBase::FindEntryByField(SCCOLROW nField, bool bNew)
     121             : {
     122             :     EntriesType::iterator itr = std::find_if(
     123           0 :         maEntries.begin(), maEntries.end(), FindByField(nField));
     124             : 
     125           0 :     if (itr != maEntries.end())
     126             :     {
     127             :         // existing entry found!
     128           0 :         return &(*itr);
     129             :     }
     130             : 
     131           0 :     if (!bNew)
     132             :         // no existing entry found, and we are not creating a new one.
     133           0 :         return NULL;
     134             : 
     135           0 :     return &AppendEntry();
     136             : }
     137             : 
     138           3 : void ScQueryParamBase::RemoveEntryByField(SCCOLROW nField)
     139             : {
     140             :     EntriesType::iterator itr = std::find_if(
     141           3 :         maEntries.begin(), maEntries.end(), FindByField(nField));
     142             : 
     143           3 :     if (itr != maEntries.end())
     144             :     {
     145           1 :         maEntries.erase(itr);
     146           1 :         if (maEntries.size() < MAXQUERY)
     147             :             // Make sure that we have at least MAXQUERY number of entries at
     148             :             // all times.
     149           1 :             maEntries.push_back(new ScQueryEntry);
     150             :     }
     151           3 : }
     152             : 
     153          53 : void ScQueryParamBase::Resize(size_t nNew)
     154             : {
     155          53 :     if (nNew < MAXQUERY)
     156          38 :         nNew = MAXQUERY;                // never less than MAXQUERY
     157             : 
     158          53 :     if (nNew < maEntries.size())
     159             :     {
     160           9 :         size_t n = maEntries.size() - nNew;
     161          27 :         for (size_t i = 0; i < n; ++i)
     162          18 :             maEntries.pop_back();
     163             :     }
     164          44 :     else if (nNew > maEntries.size())
     165             :     {
     166          14 :         size_t n = nNew - maEntries.size();
     167          58 :         for (size_t i = 0; i < n; ++i)
     168          44 :             maEntries.push_back(new ScQueryEntry);
     169             :     }
     170          53 : }
     171             : 
     172          47 : void ScQueryParamBase::FillInExcelSyntax(
     173             :     svl::SharedStringPool& rPool, const OUString& rStr, SCSIZE nIndex)
     174             : {
     175          47 :     const OUString aCellStr = rStr;
     176          47 :     if (!aCellStr.isEmpty())
     177             :     {
     178          47 :         if ( nIndex >= maEntries.size() )
     179           0 :             Resize( nIndex+1 );
     180             : 
     181          47 :         ScQueryEntry& rEntry = GetEntry(nIndex);
     182          47 :         ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
     183             : 
     184          47 :         rEntry.bDoQuery = true;
     185             :         // Operatoren herausfiltern
     186          47 :         if (aCellStr[0] == '<')
     187             :         {
     188           2 :             if (aCellStr[1] == '>')
     189             :             {
     190           0 :                 rItem.maString = rPool.intern(aCellStr.copy(2));
     191           0 :                 rEntry.eOp   = SC_NOT_EQUAL;
     192             :             }
     193           2 :             else if (aCellStr[1] == '=')
     194             :             {
     195           0 :                 rItem.maString = rPool.intern(aCellStr.copy(2));
     196           0 :                 rEntry.eOp   = SC_LESS_EQUAL;
     197             :             }
     198             :             else
     199             :             {
     200           2 :                 rItem.maString = rPool.intern(aCellStr.copy(1));
     201           2 :                 rEntry.eOp   = SC_LESS;
     202             :             }
     203             :         }
     204          45 :         else if (aCellStr[0]== '>')
     205             :         {
     206          18 :             if (aCellStr[1] == '=')
     207             :             {
     208           9 :                 rItem.maString = rPool.intern(aCellStr.copy(2));
     209           9 :                 rEntry.eOp   = SC_GREATER_EQUAL;
     210             :             }
     211             :             else
     212             :             {
     213           9 :                 rItem.maString = rPool.intern(aCellStr.copy(1));
     214           9 :                 rEntry.eOp   = SC_GREATER;
     215             :             }
     216             :         }
     217             :         else
     218             :         {
     219          27 :             if (aCellStr[0] == '=')
     220           0 :                 rItem.maString = rPool.intern(aCellStr.copy(1));
     221             :             else
     222          27 :                 rItem.maString = rPool.intern(aCellStr);
     223          27 :             rEntry.eOp = SC_EQUAL;
     224             :         }
     225          47 :     }
     226          47 : }
     227             : 
     228         498 : ScQueryParamTable::ScQueryParamTable()
     229             : {
     230         498 : }
     231             : 
     232        1247 : ScQueryParamTable::ScQueryParamTable(const ScQueryParamTable& r) :
     233        1247 :     nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nTab(r.nTab)
     234             : {
     235        1247 : }
     236             : 
     237        1716 : ScQueryParamTable::~ScQueryParamTable()
     238             : {
     239        1716 : }
     240             : 
     241         478 : ScQueryParam::ScQueryParam() :
     242             :     ScQueryParamBase(),
     243             :     ScQueryParamTable(),
     244             :     bDestPers(true),
     245             :     nDestTab(0),
     246             :     nDestCol(0),
     247         478 :     nDestRow(0)
     248             : {
     249         478 :     Clear();
     250         478 : }
     251             : 
     252        1119 : ScQueryParam::ScQueryParam( const ScQueryParam& r ) :
     253             :     ScQueryParamBase(r),
     254             :     ScQueryParamTable(r),
     255        1119 :     bDestPers(r.bDestPers), nDestTab(r.nDestTab), nDestCol(r.nDestCol), nDestRow(r.nDestRow)
     256             : {
     257        1119 : }
     258             : 
     259         128 : ScQueryParam::ScQueryParam( const ScDBQueryParamInternal& r ) :
     260             :     ScQueryParamBase(r),
     261             :     ScQueryParamTable(r),
     262             :     bDestPers(true),
     263             :     nDestTab(0),
     264             :     nDestCol(0),
     265         128 :     nDestRow(0)
     266             : {
     267         128 : }
     268             : 
     269        2418 : ScQueryParam::~ScQueryParam()
     270             : {
     271        2418 : }
     272             : 
     273         478 : void ScQueryParam::Clear()
     274             : {
     275         478 :     nCol1=nCol2 = 0;
     276         478 :     nRow1=nRow2 = 0;
     277         478 :     nTab = SCTAB_MAX;
     278         478 :     bHasHeader = bCaseSens = bRegExp = false;
     279         478 :     bInplace = bByRow = bDuplicate = true;
     280             : 
     281         478 :     boost::ptr_vector<ScQueryEntry>::iterator itr = maEntries.begin(), itrEnd = maEntries.end();
     282        4302 :     for (; itr != itrEnd; ++itr)
     283        3824 :         itr->Clear();
     284             : 
     285         478 :     ClearDestParams();
     286         478 : }
     287             : 
     288         478 : void ScQueryParam::ClearDestParams()
     289             : {
     290         478 :     bDestPers = true;
     291         478 :     nDestTab = 0;
     292         478 :     nDestCol = 0;
     293         478 :     nDestRow = 0;
     294         478 : }
     295             : 
     296         370 : ScQueryParam& ScQueryParam::operator=( const ScQueryParam& r )
     297             : {
     298         370 :     nCol1       = r.nCol1;
     299         370 :     nRow1       = r.nRow1;
     300         370 :     nCol2       = r.nCol2;
     301         370 :     nRow2       = r.nRow2;
     302         370 :     nTab        = r.nTab;
     303         370 :     nDestTab    = r.nDestTab;
     304         370 :     nDestCol    = r.nDestCol;
     305         370 :     nDestRow    = r.nDestRow;
     306         370 :     bHasHeader  = r.bHasHeader;
     307         370 :     bInplace    = r.bInplace;
     308         370 :     bCaseSens   = r.bCaseSens;
     309         370 :     bRegExp     = r.bRegExp;
     310         370 :     bDuplicate  = r.bDuplicate;
     311         370 :     bByRow      = r.bByRow;
     312         370 :     bDestPers   = r.bDestPers;
     313             : 
     314         370 :     maEntries = r.maEntries.clone();
     315             : 
     316         370 :     return *this;
     317             : }
     318             : 
     319           2 : bool ScQueryParam::operator==( const ScQueryParam& rOther ) const
     320             : {
     321           2 :     bool bEqual = false;
     322             : 
     323             :     // Anzahl der Queries gleich?
     324           2 :     SCSIZE nUsed      = 0;
     325           2 :     SCSIZE nOtherUsed = 0;
     326           2 :     SCSIZE nEntryCount = GetEntryCount();
     327           2 :     SCSIZE nOtherEntryCount = rOther.GetEntryCount();
     328             : 
     329           2 :     while ( nUsed<nEntryCount && maEntries[nUsed].bDoQuery ) ++nUsed;
     330           4 :     while ( nOtherUsed<nOtherEntryCount && rOther.maEntries[nOtherUsed].bDoQuery )
     331           0 :         ++nOtherUsed;
     332             : 
     333           2 :     if (   (nUsed       == nOtherUsed)
     334           0 :         && (nCol1       == rOther.nCol1)
     335           0 :         && (nRow1       == rOther.nRow1)
     336           0 :         && (nCol2       == rOther.nCol2)
     337           0 :         && (nRow2       == rOther.nRow2)
     338           0 :         && (nTab        == rOther.nTab)
     339           0 :         && (bHasHeader  == rOther.bHasHeader)
     340           0 :         && (bByRow      == rOther.bByRow)
     341           0 :         && (bInplace    == rOther.bInplace)
     342           0 :         && (bCaseSens   == rOther.bCaseSens)
     343           0 :         && (bRegExp     == rOther.bRegExp)
     344           0 :         && (bDuplicate  == rOther.bDuplicate)
     345           0 :         && (bDestPers   == rOther.bDestPers)
     346           0 :         && (nDestTab    == rOther.nDestTab)
     347           0 :         && (nDestCol    == rOther.nDestCol)
     348           0 :         && (nDestRow    == rOther.nDestRow) )
     349             :     {
     350           0 :         bEqual = true;
     351           0 :         for ( SCSIZE i=0; i<nUsed && bEqual; i++ )
     352           0 :             bEqual = maEntries[i] == rOther.maEntries[i];
     353             :     }
     354           2 :     return bEqual;
     355             : }
     356             : 
     357           0 : void ScQueryParam::MoveToDest()
     358             : {
     359           0 :     if (!bInplace)
     360             :     {
     361           0 :         SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
     362           0 :         SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
     363           0 :         SCsTAB nDifZ = ((SCsTAB) nDestTab) - ((SCsTAB) nTab);
     364             : 
     365           0 :         nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
     366           0 :         nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
     367           0 :         nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
     368           0 :         nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
     369           0 :         nTab  = sal::static_int_cast<SCTAB>( nTab  + nDifZ );
     370           0 :         size_t n = maEntries.size();
     371           0 :         for (size_t i=0; i<n; i++)
     372           0 :             maEntries[i].nField += nDifX;
     373             : 
     374           0 :         bInplace = true;
     375             :     }
     376             :     else
     377             :     {
     378             :         OSL_FAIL("MoveToDest, bInplace == TRUE");
     379             :     }
     380           0 : }
     381             : 
     382          20 : ScDBQueryParamBase::ScDBQueryParamBase(DataType eType) :
     383             :     ScQueryParamBase(),
     384             :     mnField(-1),
     385             :     mbSkipString(true),
     386          20 :     meType(eType)
     387             : {
     388          20 : }
     389             : 
     390          20 : ScDBQueryParamBase::~ScDBQueryParamBase()
     391             : {
     392          20 : }
     393             : 
     394          20 : ScDBQueryParamBase::DataType ScDBQueryParamBase::GetType() const
     395             : {
     396          20 :     return meType;
     397             : }
     398             : 
     399          20 : ScDBQueryParamInternal::ScDBQueryParamInternal() :
     400             :     ScDBQueryParamBase(ScDBQueryParamBase::INTERNAL),
     401          20 :     ScQueryParamTable()
     402             : {
     403          20 : }
     404             : 
     405          40 : ScDBQueryParamInternal::~ScDBQueryParamInternal()
     406             : {
     407          40 : }
     408             : 
     409          14 : bool ScDBQueryParamInternal::IsValidFieldIndex() const
     410             : {
     411          14 :     return nCol1 <= mnField && mnField <= nCol2;
     412             : }
     413             : 
     414           0 : ScDBQueryParamMatrix::ScDBQueryParamMatrix() :
     415           0 :     ScDBQueryParamBase(ScDBQueryParamBase::MATRIX)
     416             : {
     417           0 : }
     418             : 
     419           0 : bool ScDBQueryParamMatrix::IsValidFieldIndex() const
     420             : {
     421             :     SCSIZE nC, nR;
     422           0 :     mpMatrix->GetDimensions(nC, nR);
     423           0 :     return 0 <= mnField && mnField <= static_cast<SCCOL>(nC);
     424             : }
     425             : 
     426           0 : ScDBQueryParamMatrix::~ScDBQueryParamMatrix()
     427             : {
     428           0 : }
     429             : 
     430             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10