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

Generated by: LCOV version 1.10