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

Generated by: LCOV version 1.10