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

Generated by: LCOV version 1.10