pyuno: call target only with internal python
[LibreOffice.git] / sc / source / core / tool / lookupcache.cxx
blobd4c19a3c7e0779c7c24844c73c1ee1658421930e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <lookupcache.hxx>
21 #include <document.hxx>
22 #include <queryentry.hxx>
23 #include <brdcst.hxx>
25 #include <sal/log.hxx>
27 ScLookupCache::QueryCriteria::QueryCriteria( const ScQueryEntry& rEntry, sal_Int8 nSearchMode ) :
28 mfVal(0.0), mbAlloc(false), mbString(false), meSearchMode(static_cast<SearchMode>(nSearchMode))
30 switch (rEntry.eOp)
32 case SC_EQUAL :
33 meOp = EQUAL;
34 break;
35 case SC_LESS_EQUAL :
36 meOp = LESS_EQUAL;
37 break;
38 case SC_GREATER_EQUAL :
39 meOp = GREATER_EQUAL;
40 break;
41 default:
42 meOp = UNKNOWN;
43 SAL_WARN( "sc.core", "ScLookupCache::QueryCriteria not prepared for this ScQueryOp");
46 const ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
47 if (rItem.meType == ScQueryEntry::ByString)
48 setString(rItem.maString.getString());
49 else
50 setDouble(rItem.mfVal);
53 ScLookupCache::QueryCriteria::QueryCriteria( const ScLookupCache::QueryCriteria & r ) :
54 mfVal( r.mfVal),
55 mbAlloc( false),
56 mbString( false),
57 meOp( r.meOp),
58 meSearchMode( r.meSearchMode)
60 if (r.mbString && r.mpStr)
62 mpStr = new OUString( *r.mpStr);
63 mbAlloc = mbString = true;
67 ScLookupCache::QueryCriteria::~QueryCriteria()
69 deleteString();
72 ScLookupCache::Result ScLookupCache::lookup( ScAddress & o_rResultAddress,
73 const QueryCriteria & rCriteria, const ScAddress & rQueryAddress ) const
75 auto it( maQueryMap.find( QueryKey( rQueryAddress,
76 rCriteria.getQueryOp(), rCriteria.getSearchMode())));
77 if (it == maQueryMap.end())
78 return NOT_CACHED;
79 const QueryCriteriaAndResult& rResult = (*it).second;
80 if (!(rResult.maCriteria == rCriteria))
81 return CRITERIA_DIFFERENT;
82 if (rResult.maAddress.Row() < 0 )
83 return NOT_AVAILABLE;
84 o_rResultAddress = rResult.maAddress;
85 return FOUND;
88 SCROW ScLookupCache::lookup( const QueryCriteria & rCriteria ) const
90 // try to find the row index for which we have already performed lookup
91 auto it = std::find_if(maQueryMap.begin(), maQueryMap.end(),
92 [&rCriteria](const std::pair<QueryKey, QueryCriteriaAndResult>& rEntry) {
93 return rEntry.second.maCriteria == rCriteria;
94 });
95 if (it != maQueryMap.end())
96 return it->first.mnRow;
98 // not found
99 return -1;
102 bool ScLookupCache::insert( const ScAddress & rResultAddress,
103 const QueryCriteria & rCriteria, const ScAddress & rQueryAddress,
104 const bool bAvailable )
106 QueryKey aKey( rQueryAddress, rCriteria.getQueryOp(), rCriteria.getSearchMode() );
107 QueryCriteriaAndResult aResult( rCriteria, rResultAddress);
108 if (!bAvailable)
109 aResult.maAddress.SetRow(-1);
110 bool bInserted = maQueryMap.insert( ::std::pair< const QueryKey,
111 QueryCriteriaAndResult>( aKey, aResult)).second;
113 return bInserted;
116 void ScLookupCache::Notify( const SfxHint& rHint )
118 if (!mpDoc->IsInDtorClear())
120 if (rHint.GetId() == SfxHintId::ScDataChanged || rHint.GetId() == SfxHintId::ScAreaChanged)
122 mpDoc->RemoveLookupCache( *this);
123 // this ScLookupCache is deleted by RemoveLookupCache
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */