1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "lookupcache.hxx"
22 #include "document.hxx"
23 #include "queryentry.hxx"
25 ScLookupCache::QueryCriteria::QueryCriteria( const ScQueryEntry
& rEntry
) :
26 mfVal(0.0), mbAlloc(false), mbString(false)
36 case SC_GREATER_EQUAL
:
41 SAL_WARN( "sc.core", "ScLookupCache::QueryCriteria not prepared for this ScQueryOp");
44 const ScQueryEntry::Item
& rItem
= rEntry
.GetQueryItem();
45 if (rItem
.meType
== ScQueryEntry::ByString
)
46 setString(rItem
.maString
.getString());
48 setDouble(rItem
.mfVal
);
51 ScLookupCache::QueryCriteria::QueryCriteria( const ScLookupCache::QueryCriteria
& r
) :
57 if (r
.mbString
&& r
.mpStr
)
59 mpStr
= new OUString( *r
.mpStr
);
60 mbAlloc
= mbString
= true;
64 ScLookupCache::QueryCriteria::~QueryCriteria()
69 ScLookupCache::ScLookupCache( ScDocument
* pDoc
, const ScRange
& rRange
) :
76 ScLookupCache::~ScLookupCache()
81 ScLookupCache::Result
ScLookupCache::lookup( ScAddress
& o_rResultAddress
,
82 const QueryCriteria
& rCriteria
, const ScAddress
& rQueryAddress
) const
84 QueryMap::const_iterator
it( maQueryMap
.find( QueryKey( rQueryAddress
,
85 rCriteria
.getQueryOp())));
86 if (it
== maQueryMap
.end())
88 const QueryCriteriaAndResult
& rResult
= (*it
).second
;
89 if (!(rResult
.maCriteria
== rCriteria
))
90 return CRITERIA_DIFFERENT
;
91 if (rResult
.maAddress
.Row() < 0 )
93 o_rResultAddress
= rResult
.maAddress
;
98 bool ScLookupCache::insert( const ScAddress
& rResultAddress
,
99 const QueryCriteria
& rCriteria
, const ScAddress
& rQueryAddress
,
100 const bool bAvailable
)
102 QueryKey
aKey( rQueryAddress
, rCriteria
.getQueryOp());
103 QueryCriteriaAndResult
aResult( rCriteria
, rResultAddress
);
105 aResult
.maAddress
.SetRow(-1);
106 bool bInserted
= maQueryMap
.insert( ::std::pair
< const QueryKey
,
107 QueryCriteriaAndResult
>( aKey
, aResult
)).second
;
113 void ScLookupCache::Notify( SvtBroadcaster
& /* rBC */ , const SfxHint
& rHint
)
115 if (!mpDoc
->IsInDtorClear())
117 const ScHint
* p
= PTR_CAST( ScHint
, &rHint
);
118 if (p
&& (p
->GetId() & SC_HINT_DATACHANGED
))
120 mpDoc
->RemoveLookupCache( *this);
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */