LCOV - code coverage report
Current view: top level - sc/source/core/tool - lookupcache.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 52 54 96.3 %
Date: 2015-06-13 12:38:46 Functions: 11 11 100.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             : #include "lookupcache.hxx"
      21             : #include "document.hxx"
      22             : #include "queryentry.hxx"
      23             : #include <brdcst.hxx>
      24             : 
      25          77 : ScLookupCache::QueryCriteria::QueryCriteria( const ScQueryEntry& rEntry ) :
      26          77 :     mfVal(0.0), mbAlloc(false), mbString(false)
      27             : {
      28          77 :     switch (rEntry.eOp)
      29             :     {
      30             :         case SC_EQUAL :
      31          11 :             meOp = EQUAL;
      32          11 :             break;
      33             :         case SC_LESS_EQUAL :
      34          49 :             meOp = LESS_EQUAL;
      35          49 :             break;
      36             :         case SC_GREATER_EQUAL :
      37          17 :             meOp = GREATER_EQUAL;
      38          17 :             break;
      39             :         default:
      40           0 :             meOp = UNKNOWN;
      41             :             SAL_WARN( "sc.core", "ScLookupCache::QueryCriteria not prepared for this ScQueryOp");
      42             :     }
      43             : 
      44          77 :     const ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
      45          77 :     if (rItem.meType == ScQueryEntry::ByString)
      46          38 :         setString(rItem.maString.getString());
      47             :     else
      48          39 :         setDouble(rItem.mfVal);
      49          77 : }
      50             : 
      51         216 : ScLookupCache::QueryCriteria::QueryCriteria( const ScLookupCache::QueryCriteria & r ) :
      52             :     mfVal( r.mfVal),
      53             :     mbAlloc( false),
      54             :     mbString( false),
      55         216 :     meOp( r.meOp)
      56             : {
      57         216 :     if (r.mbString && r.mpStr)
      58             :     {
      59          99 :         mpStr = new OUString( *r.mpStr);
      60          99 :         mbAlloc = mbString = true;
      61             :     }
      62         216 : }
      63             : 
      64         285 : ScLookupCache::QueryCriteria::~QueryCriteria()
      65             : {
      66         285 :     deleteString();
      67         285 : }
      68             : 
      69          18 : ScLookupCache::ScLookupCache( ScDocument * pDoc, const ScRange & rRange ) :
      70             :     maRange( rRange),
      71          18 :     mpDoc( pDoc)
      72             : {
      73          18 : }
      74             : 
      75          24 : ScLookupCache::~ScLookupCache()
      76             : {
      77          24 : }
      78             : 
      79          77 : ScLookupCache::Result ScLookupCache::lookup( ScAddress & o_rResultAddress,
      80             :         const QueryCriteria & rCriteria, const ScAddress & rQueryAddress ) const
      81             : {
      82             :     QueryMap::const_iterator it( maQueryMap.find( QueryKey( rQueryAddress,
      83          77 :                     rCriteria.getQueryOp())));
      84          77 :     if (it == maQueryMap.end())
      85          72 :         return NOT_CACHED;
      86           5 :     const QueryCriteriaAndResult& rResult = (*it).second;
      87           5 :     if (!(rResult.maCriteria == rCriteria))
      88           2 :         return CRITERIA_DIFFERENT;
      89           3 :     if (rResult.maAddress.Row() < 0 )
      90           0 :         return NOT_AVAILABLE;
      91           3 :     o_rResultAddress = rResult.maAddress;
      92           3 :     return FOUND;
      93             : }
      94             : 
      95          72 : bool ScLookupCache::insert( const ScAddress & rResultAddress,
      96             :         const QueryCriteria & rCriteria, const ScAddress & rQueryAddress,
      97             :         const bool bAvailable )
      98             : {
      99          72 :     QueryKey aKey( rQueryAddress, rCriteria.getQueryOp());
     100          72 :     QueryCriteriaAndResult aResult( rCriteria, rResultAddress);
     101          72 :     if (!bAvailable)
     102           8 :         aResult.maAddress.SetRow(-1);
     103             :     bool bInserted = maQueryMap.insert( ::std::pair< const QueryKey,
     104          72 :             QueryCriteriaAndResult>( aKey, aResult)).second;
     105             : 
     106          72 :     return bInserted;
     107             : }
     108             : 
     109           4 : void ScLookupCache::Notify( const SfxHint& rHint )
     110             : {
     111           4 :     if (!mpDoc->IsInDtorClear())
     112             :     {
     113           4 :         const ScHint* p = dynamic_cast<const ScHint*>(&rHint);
     114           4 :         if (p && (p->GetId() & SC_HINT_DATACHANGED))
     115             :         {
     116           4 :             mpDoc->RemoveLookupCache( *this);
     117           4 :             delete this;
     118             :         }
     119             :     }
     120         160 : }
     121             : 
     122             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11